Skip to content

Commit

Permalink
Merge pull request #104 from vim-jp/embed-file-less-than-handred-thou…
Browse files Browse the repository at this point in the history
…sand

add maxEmbededFileSize
  • Loading branch information
koron authored May 10, 2020
2 parents 1c8e646 + 89cd32d commit c307107
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/slacklog/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ type HTMLGenerator struct {
baseURL string
}

// maxEmbeddedFileSize : 添付ファイルの埋め込みを行うファイルサイズ
// これ以下の場合、表示されるようになる
const maxEmbeddedFileSize = 102400

// NewHTMLGenerator : HTMLGeneratorを生成する。
func NewHTMLGenerator(templateDir string, filesDir string, s *LogStore) *HTMLGenerator {
users := s.GetDisplayNameMap()
Expand Down Expand Up @@ -291,6 +295,9 @@ func (g *HTMLGenerator) generateAttachmentText(attachment MessageAttachment) str
// generateFileHTML : 'text/plain' な添付ファイルをHTMLに埋め込む
// 存在しない場合、エラーを表示する
func (g *HTMLGenerator) generateFileHTML(file *MessageFile) string {
if file.Size > maxEmbeddedFileSize {
return `<span class="file-error">file size is too big to embed. please download from above link to see.</span>`
}
suffix := file.DownloadURLsAndSuffixes()[file.URLPrivate]
path := filepath.Join(g.filesDir, file.ID, file.DownloadFilename(file.URLPrivate, suffix))
src, err := ioutil.ReadFile(path)
Expand Down

0 comments on commit c307107

Please sign in to comment.