Disable import, upload and raw converter in read-only mode #56
This commit is contained in:
parent
b976c095f3
commit
bc65ad57d5
7 changed files with 43 additions and 1 deletions
11
internal/api/errors.go
Normal file
11
internal/api/errors.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/util"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrReadOnly = gin.H{"error": util.UcFirst(config.ErrReadOnly.Error())}
|
||||
)
|
|
@ -29,6 +29,11 @@ func initImporter(conf *config.Config) {
|
|||
// POST /api/v1/import
|
||||
func Import(router *gin.RouterGroup, conf *config.Config) {
|
||||
router.POST("/import/*path", func(c *gin.Context) {
|
||||
if conf.ReadOnly() {
|
||||
c.AbortWithStatusJSON(http.StatusForbidden, ErrReadOnly)
|
||||
return
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
path := conf.ImportPath()
|
||||
|
||||
|
|
|
@ -17,6 +17,11 @@ import (
|
|||
// POST /api/v1/upload/:path
|
||||
func Upload(router *gin.RouterGroup, conf *config.Config) {
|
||||
router.POST("/upload/:path", func(c *gin.Context) {
|
||||
if conf.ReadOnly() {
|
||||
c.AbortWithStatusJSON(http.StatusForbidden, ErrReadOnly)
|
||||
return
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
subPath := c.Param("path")
|
||||
|
||||
|
|
|
@ -20,6 +20,10 @@ func convertAction(ctx *cli.Context) error {
|
|||
|
||||
conf := config.NewConfig(ctx)
|
||||
|
||||
if conf.ReadOnly() {
|
||||
return config.ErrReadOnly
|
||||
}
|
||||
|
||||
if err := conf.CreateDirectories(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -21,6 +21,10 @@ func importAction(ctx *cli.Context) error {
|
|||
|
||||
conf := config.NewConfig(ctx)
|
||||
|
||||
if conf.ReadOnly() {
|
||||
return config.ErrReadOnly
|
||||
}
|
||||
|
||||
if err := conf.CreateDirectories(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
9
internal/config/errors.go
Normal file
9
internal/config/errors.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrReadOnly = errors.New("not available in read only mode")
|
||||
)
|
|
@ -75,7 +75,7 @@ func (c *Converter) ConvertCommand(image *MediaFile, jpegFilename string, xmpFil
|
|||
// ConvertToJpeg converts a single image the JPEG format.
|
||||
func (c *Converter) ConvertToJpeg(image *MediaFile) (*MediaFile, error) {
|
||||
if !image.Exists() {
|
||||
return nil, fmt.Errorf("can not convert, file does not exist: %s", image.Filename())
|
||||
return nil, fmt.Errorf("can not convert to jpeg, file does not exist: %s", image.Filename())
|
||||
}
|
||||
|
||||
if image.IsJpeg() {
|
||||
|
@ -92,6 +92,10 @@ func (c *Converter) ConvertToJpeg(image *MediaFile) (*MediaFile, error) {
|
|||
return mediaFile, nil
|
||||
}
|
||||
|
||||
if c.conf.ReadOnly() {
|
||||
return nil, fmt.Errorf("can not convert to jpeg in read only mode: %s", image.Filename())
|
||||
}
|
||||
|
||||
log.Infof("converting \"%s\" to \"%s\"", image.filename, jpegFilename)
|
||||
|
||||
xmpFilename := baseFilename + ".xmp"
|
||||
|
|
Loading…
Reference in a new issue