contented: new option to cap the filesize for thumbnailing (default 20MiB)
This commit is contained in:
parent
77a4061cdd
commit
caf521c318
@ -22,6 +22,7 @@ var SERVER_HEADER string = `contented/0.0.0-dev`
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
DEFAULT_MAX_CONCURRENT_THUMBS = 16
|
DEFAULT_MAX_CONCURRENT_THUMBS = 16
|
||||||
|
DEFAULT_MAX_THUMBSIZE = 20 * 1024 * 1024 // 20 MiB
|
||||||
|
|
||||||
ALBUM_MIMETYPE = `contented/album`
|
ALBUM_MIMETYPE = `contented/album`
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ type ServerOptions struct {
|
|||||||
EnableHomepage bool
|
EnableHomepage bool
|
||||||
EnableUpload bool
|
EnableUpload bool
|
||||||
MaxConcurrentThumbs int
|
MaxConcurrentThumbs int
|
||||||
|
MaxThumbSizeBytes int64
|
||||||
ServerPublicProperties
|
ServerPublicProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,6 +76,11 @@ func NewServer(opts *ServerOptions) (*Server, error) {
|
|||||||
log.Printf("Allowing %d concurrent thumbnails", s.opts.MaxConcurrentThumbs)
|
log.Printf("Allowing %d concurrent thumbnails", s.opts.MaxConcurrentThumbs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.opts.MaxThumbSizeBytes <= 0 {
|
||||||
|
s.opts.MaxThumbSizeBytes = DEFAULT_MAX_THUMBSIZE
|
||||||
|
log.Printf("Allowing thumbnails for files up to %d byte(s)", s.opts.MaxThumbSizeBytes)
|
||||||
|
}
|
||||||
|
|
||||||
s.staticDir, _ = fs.Sub(staticAssets, `static`) // can't fail
|
s.staticDir, _ = fs.Sub(staticAssets, `static`) // can't fail
|
||||||
|
|
||||||
// "fill" the thumbnailer semaphore
|
// "fill" the thumbnailer semaphore
|
||||||
|
4
thumb.go
4
thumb.go
@ -94,6 +94,10 @@ func (this *Server) handleThumbInternal(ctx context.Context, w http.ResponseWrit
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m.FileSize > this.opts.MaxThumbSizeBytes {
|
||||||
|
return errors.New("Don't want to thumbnail very large files, sorry")
|
||||||
|
}
|
||||||
|
|
||||||
filePath := filepath.Join(this.opts.DataDirectory, m.FileHash)
|
filePath := filepath.Join(this.opts.DataDirectory, m.FileHash)
|
||||||
thumb, err := t.RenderFileAs(filePath, m.MimeType)
|
thumb, err := t.RenderFileAs(filePath, m.MimeType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user