Downloads: Configure file name schema #675

There is no UI for this setting yet.
This commit is contained in:
Michael Mayer
2020-12-16 11:59:16 +01:00
parent 373578b9a9
commit 717da1bd34
11 changed files with 96 additions and 23 deletions

View File

@@ -2,8 +2,11 @@ package api
import (
"fmt"
"github.com/photoprism/photoprism/internal/entity"
"net/http"
"github.com/photoprism/photoprism/internal/service"
"github.com/photoprism/photoprism/internal/photoprism"
"github.com/photoprism/photoprism/internal/query"
"github.com/photoprism/photoprism/pkg/fs"
@@ -48,9 +51,31 @@ func GetDownload(router *gin.RouterGroup) {
return
}
downloadFileName := f.ShareFileName()
name := entity.DownloadNameFile
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", downloadFileName))
switch c.Query("name") {
case "file":
name = entity.DownloadNameFile
case "share":
name = entity.DownloadNameShare
case "original":
name = entity.DownloadNameOriginal
default:
name = service.Config().Settings().Download.Name
}
var downloadName string
switch name {
case entity.DownloadNameFile:
downloadName = f.Base()
case entity.DownloadNameOriginal:
downloadName = f.OriginalBase()
default:
downloadName = f.ShareBase()
}
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", downloadName))
c.File(fileName)
})