feat: add param to disable img resizing
parent
bc00165094
commit
aa78e3ab1f
|
@ -59,6 +59,8 @@ func addServerFlags(flags *pflag.FlagSet) {
|
|||
flags.String("socket", "", "socket to listen to (cannot be used with address, port, cert nor key flags)")
|
||||
flags.StringP("baseurl", "b", "", "base url")
|
||||
flags.Int("img-processors", 4, "image processors count")
|
||||
flags.Bool("disable-thumbnails", false, "disable image thumbnails")
|
||||
flags.Bool("disable-preview-resize", false, "disable resize of image previews")
|
||||
}
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
|
@ -216,6 +218,12 @@ func getRunParams(flags *pflag.FlagSet, st *storage.Storage) *settings.Server {
|
|||
server.Socket = ""
|
||||
}
|
||||
|
||||
_, disableThumbnails := getParamB(flags, "disable-thumbnails")
|
||||
server.EnableThumbnails = !disableThumbnails
|
||||
|
||||
_, disablePreviewResize := getParamB(flags, "disable-preview-resize")
|
||||
server.ResizePreview = !disablePreviewResize
|
||||
|
||||
return server
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
:aria-label="name"
|
||||
:aria-selected="isSelected">
|
||||
<div>
|
||||
<img v-if="type==='image'" v-lazy="thumbnailUrl">
|
||||
<img v-if="type==='image' && isThumbsEnabled" v-lazy="thumbnailUrl">
|
||||
<i v-else class="material-icons">{{ icon }}</i>
|
||||
</div>
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { baseURL } from '@/utils/constants'
|
||||
import { baseURL, enableThumbs } from '@/utils/constants'
|
||||
import { mapMutations, mapGetters, mapState } from 'vuex'
|
||||
import filesize from 'filesize'
|
||||
import moment from 'moment'
|
||||
|
@ -76,6 +76,9 @@ export default {
|
|||
thumbnailUrl () {
|
||||
const path = this.url.replace(/^\/files\//, '')
|
||||
return `${baseURL}/api/preview/thumb/${path}?auth=${this.jwt}&inline=true`
|
||||
},
|
||||
isThumbsEnabled () {
|
||||
return enableThumbs
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
|
@ -11,6 +11,7 @@ const noAuth = window.FileBrowser.NoAuth
|
|||
const authMethod = window.FileBrowser.AuthMethod
|
||||
const loginPage = window.FileBrowser.LoginPage
|
||||
const theme = window.FileBrowser.Theme
|
||||
const enableThumbs = window.FileBrowser.EnableThumbs
|
||||
|
||||
export {
|
||||
name,
|
||||
|
@ -24,5 +25,6 @@ export {
|
|||
noAuth,
|
||||
authMethod,
|
||||
loginPage,
|
||||
theme
|
||||
theme,
|
||||
enableThumbs
|
||||
}
|
||||
|
|
|
@ -59,7 +59,8 @@ func NewHandler(imgSvc ImgService, store *storage.Storage, server *settings.Serv
|
|||
api.Handle("/settings", monkey(settingsPutHandler, "")).Methods("PUT")
|
||||
|
||||
api.PathPrefix("/raw").Handler(monkey(rawHandler, "/api/raw")).Methods("GET")
|
||||
api.PathPrefix("/preview/{size}/{path:.*}").Handler(monkey(previewHandler(imgSvc), "/api/preview")).Methods("GET")
|
||||
api.PathPrefix("/preview/{size}/{path:.*}").
|
||||
Handler(monkey(previewHandler(imgSvc, server.EnableThumbnails, server.ResizePreview), "/api/preview")).Methods("GET")
|
||||
api.PathPrefix("/command").Handler(monkey(commandsHandler, "/api/command")).Methods("GET")
|
||||
api.PathPrefix("/search").Handler(monkey(searchHandler, "/api/search")).Methods("GET")
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ type ImgService interface {
|
|||
Resize(ctx context.Context, file afero.File, width, height int, out io.Writer, options ...img.Option) error
|
||||
}
|
||||
|
||||
func previewHandler(imgSvc ImgService) handleFunc {
|
||||
func previewHandler(imgSvc ImgService, enableThumbnails, resizePreview bool) handleFunc {
|
||||
return withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
||||
if !d.user.Perm.Download {
|
||||
return http.StatusAccepted, nil
|
||||
|
@ -50,14 +50,15 @@ func previewHandler(imgSvc ImgService) handleFunc {
|
|||
|
||||
switch file.Type {
|
||||
case "image":
|
||||
return handleImagePreview(imgSvc, w, r, file, size)
|
||||
return handleImagePreview(imgSvc, w, r, file, size, enableThumbnails, resizePreview)
|
||||
default:
|
||||
return http.StatusNotImplemented, fmt.Errorf("can't create preview for %s type", file.Type)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func handleImagePreview(imgSvc ImgService, w http.ResponseWriter, r *http.Request, file *files.FileInfo, size string) (int, error) {
|
||||
func handleImagePreview(imgSvc ImgService, w http.ResponseWriter, r *http.Request,
|
||||
file *files.FileInfo, size string, enableThumbnails, resizePreview bool) (int, error) {
|
||||
format, err := imgSvc.FormatFromExtension(file.Extension)
|
||||
if err != nil {
|
||||
// Unsupported extensions directly return the raw data
|
||||
|
@ -73,30 +74,26 @@ func handleImagePreview(imgSvc ImgService, w http.ResponseWriter, r *http.Reques
|
|||
}
|
||||
defer fd.Close()
|
||||
|
||||
if format == img.FormatGif && size == sizeBig {
|
||||
if _, err := rawFileHandler(w, r, file); err != nil {
|
||||
return errToStatus(err), err
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var (
|
||||
width int
|
||||
height int
|
||||
options []img.Option
|
||||
)
|
||||
|
||||
switch size {
|
||||
case sizeBig:
|
||||
switch {
|
||||
case size == sizeBig && resizePreview && format != img.FormatGif:
|
||||
width = 1080
|
||||
height = 1080
|
||||
options = append(options, img.WithHighPriority())
|
||||
case sizeThumb:
|
||||
options = append(options, img.WithMode(img.ResizeModeFit), img.WithQuality(img.QualityMedium))
|
||||
case size == sizeThumb && enableThumbnails:
|
||||
width = 128
|
||||
height = 128
|
||||
options = append(options, img.WithMode(img.ResizeModeFill), img.WithQuality(img.QualityLow))
|
||||
options = append(options, img.WithMode(img.ResizeModeFill), img.WithQuality(img.QualityLow), img.WithFormat(img.FormatJpeg))
|
||||
default:
|
||||
return http.StatusBadRequest, fmt.Errorf("unsupported preview size %s", size)
|
||||
if _, err := rawFileHandler(w, r, file); err != nil {
|
||||
return errToStatus(err), err
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if err := imgSvc.Resize(r.Context(), fd, width, height, w, options...); err != nil {
|
||||
|
|
|
@ -39,6 +39,7 @@ func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, box *
|
|||
"CSS": false,
|
||||
"ReCaptcha": false,
|
||||
"Theme": d.settings.Branding.Theme,
|
||||
"EnableThumbs": d.server.EnableThumbnails,
|
||||
}
|
||||
|
||||
if d.settings.Branding.Files != "" {
|
||||
|
|
|
@ -30,14 +30,16 @@ func (s *Settings) GetRules() []rules.Rule {
|
|||
|
||||
// Server specific settings.
|
||||
type Server struct {
|
||||
Root string `json:"root"`
|
||||
BaseURL string `json:"baseURL"`
|
||||
Socket string `json:"socket"`
|
||||
TLSKey string `json:"tlsKey"`
|
||||
TLSCert string `json:"tlsCert"`
|
||||
Port string `json:"port"`
|
||||
Address string `json:"address"`
|
||||
Log string `json:"log"`
|
||||
Root string `json:"root"`
|
||||
BaseURL string `json:"baseURL"`
|
||||
Socket string `json:"socket"`
|
||||
TLSKey string `json:"tlsKey"`
|
||||
TLSCert string `json:"tlsCert"`
|
||||
Port string `json:"port"`
|
||||
Address string `json:"address"`
|
||||
Log string `json:"log"`
|
||||
EnableThumbnails bool `json:"enableThumbnails"`
|
||||
ResizePreview bool `json:"resizePreview"`
|
||||
}
|
||||
|
||||
// Clean cleans any variables that might need cleaning.
|
||||
|
|
Loading…
Reference in New Issue