From b5ee4625a689cf67d91aa03201e66ffad1e99614 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Mon, 6 Apr 2020 22:50:04 +0200 Subject: [PATCH] Backend: Replace export with temp directory #276 Signed-off-by: Michael Mayer --- internal/api/album.go | 2 +- internal/api/zip.go | 4 ++-- internal/config/db.go | 8 ++++++++ internal/config/test.go | 5 +++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/internal/api/album.go b/internal/api/album.go index cad1893e5..0d22cdc95 100644 --- a/internal/api/album.go +++ b/internal/api/album.go @@ -352,7 +352,7 @@ func DownloadAlbum(router *gin.RouterGroup, conf *config.Config) { return } - zipPath := path.Join(conf.ExportPath(), "album") + zipPath := path.Join(conf.TempPath(), "album") zipToken := rnd.Token(3) zipBaseName := fmt.Sprintf("%s-%s.zip", strings.Title(a.AlbumSlug), zipToken) zipFileName := path.Join(zipPath, zipBaseName) diff --git a/internal/api/zip.go b/internal/api/zip.go index a9ec0880f..9a64afbb0 100644 --- a/internal/api/zip.go +++ b/internal/api/zip.go @@ -50,7 +50,7 @@ func CreateZip(router *gin.RouterGroup, conf *config.Config) { return } - zipPath := path.Join(conf.ExportPath(), "zip") + zipPath := path.Join(conf.TempPath(), "zip") zipToken := rnd.Token(3) zipYear := time.Now().Format("January-2006") zipBaseName := fmt.Sprintf("Photos-%s-%s.zip", zipYear, zipToken) @@ -105,7 +105,7 @@ func CreateZip(router *gin.RouterGroup, conf *config.Config) { func DownloadZip(router *gin.RouterGroup, conf *config.Config) { router.GET("/zip/:filename", func(c *gin.Context) { zipBaseName := filepath.Base(c.Param("filename")) - zipPath := path.Join(conf.ExportPath(), "zip") + zipPath := path.Join(conf.TempPath(), "zip") zipFileName := path.Join(zipPath, zipBaseName) c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", zipBaseName)) diff --git a/internal/config/db.go b/internal/config/db.go index ae4f32a30..ffbbacdd7 100644 --- a/internal/config/db.go +++ b/internal/config/db.go @@ -13,6 +13,7 @@ import ( "github.com/photoprism/photoprism/internal/entity" "github.com/photoprism/photoprism/internal/mutex" "github.com/photoprism/photoprism/internal/tidb" + "github.com/sirupsen/logrus" ) // DatabaseDriver returns the database driver name. @@ -156,10 +157,17 @@ func (c *Config) connectToDatabase(ctx context.Context) error { func (c *Config) DropTables() { db := c.Db() + log.SetLevel(logrus.FatalLevel) + db.SetLogger(log) + db.LogMode(false) + db.DropTableIfExists( &entity.Account{}, &entity.File{}, + &entity.FileShare{}, + &entity.FileSync{}, &entity.Photo{}, + &entity.Description{}, &entity.Event{}, &entity.Place{}, &entity.Location{}, diff --git a/internal/config/test.go b/internal/config/test.go index 0a5f89aa5..2f1477ed8 100644 --- a/internal/config/test.go +++ b/internal/config/test.go @@ -47,6 +47,7 @@ func NewTestParams() *Params { OriginalsPath: testDataPath + "/originals", ImportPath: testDataPath + "/import", ExportPath: testDataPath + "/export", + TempPath: testDataPath + "/temp", DatabaseDriver: "mysql", DatabaseDsn: "photoprism:photoprism@tcp(photoprism-db:4001)/photoprism?parseTime=true", } @@ -67,6 +68,7 @@ func NewTestParamsError() *Params { OriginalsPath: testDataPath + "/originals", ImportPath: testDataPath + "/import", ExportPath: testDataPath + "/export", + TempPath: testDataPath + "/temp", DatabaseDriver: "mysql", DatabaseDsn: "photoprism:photoprism@tcp(photoprism-db:4001)/photoprism?parseTime=true", } @@ -132,6 +134,7 @@ func CliTestContext() *cli.Context { globalSet.String("originals-path", config.OriginalsPath, "doc") globalSet.String("import-path", config.OriginalsPath, "doc") globalSet.String("export-path", config.OriginalsPath, "doc") + globalSet.String("temp-path", config.OriginalsPath, "doc") globalSet.String("cache-path", config.OriginalsPath, "doc") globalSet.String("darktable-cli", config.DarktableBin, "doc") globalSet.Bool("detect-nsfw", config.DetectNSFW, "doc") @@ -146,6 +149,7 @@ func CliTestContext() *cli.Context { c.Set("originals-path", config.OriginalsPath) c.Set("import-path", config.ImportPath) c.Set("export-path", config.ExportPath) + c.Set("temp-path", config.TempPath) c.Set("cache-path", config.CachePath) c.Set("darktable-cli", config.DarktableBin) c.Set("detect-nsfw", "true") @@ -157,6 +161,7 @@ func CliTestContext() *cli.Context { func (c *Config) RemoveTestData(t *testing.T) { os.RemoveAll(c.ImportPath()) os.RemoveAll(c.ExportPath()) + os.RemoveAll(c.TempPath()) os.RemoveAll(c.OriginalsPath()) os.RemoveAll(c.CachePath()) }