From ad91cbd4c6e9e1109de4036e9444f23a8a2e15ec Mon Sep 17 00:00:00 2001 From: Simon Martens Date: Tue, 11 Feb 2025 12:09:48 +0100 Subject: [PATCH] BUGFIX: Almanach-Bilder-Import mit Kommas --- .gitignore | 1 + ; | 36 ------------------------------------ migrations/seed/contents.go | 22 ++++++++++------------ 3 files changed, 11 insertions(+), 48 deletions(-) delete mode 100644 ; diff --git a/.gitignore b/.gitignore index df38dc3..ba97ceb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ tmp/ bin/ cache/ data_bilder/ +Almanach-Bilder/ config.json out.log *.log diff --git a/; b/; deleted file mode 100644 index f2e33eb..0000000 --- a/; +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "log" - - "github.com/Theodor-Springmann-Stiftung/musenalm/app" - "github.com/Theodor-Springmann-Stiftung/musenalm/cmd" - "github.com/Theodor-Springmann-Stiftung/musenalm/helpers" - _ "github.com/Theodor-Springmann-Stiftung/musenalm/migrations" - _ "github.com/Theodor-Springmann-Stiftung/musenalm/pages" - "github.com/pocketbase/pocketbase/plugins/migratecmd" -) - -const ( - DEV_CONFIG = "config.dev.json" - DEFAULT_CONFIG = "config.json" -) - -func main() { - cfg := app.NewConfigProvider([]string{DEFAULT_CONFIG}, []string{DEV_CONFIG}) - if err := cfg.Read(); err != nil { - helpers.Assert(err, "Error reading config") - } - - app := app.New(*cfg.Config) - app.PB.RootCmd.AddCommand(cmd.AddResetPagesCommand(app.PB, &app)) - - migratecmd.MustRegister(app.PB, app.PB.RootCmd, migratecmd.Config{ - Automigrate: false, - TemplateLang: migratecmd.TemplateLangGo, - }) - - if err := app.Serve(); err != nil { - log.Fatal(err) - } -} diff --git a/migrations/seed/contents.go b/migrations/seed/contents.go index 6631692..18b7851 100644 --- a/migrations/seed/contents.go +++ b/migrations/seed/contents.go @@ -128,7 +128,7 @@ func commatizeArray(array []string) string { } func getImages(path string) map[string][]string { - /// BUG: there is a bug somewhere, where files ending with numbers after a comma (",001") etc dont get added + /// FIXED: there is a bug somewhere, where files ending with numbers after a comma (",001") etc dont get added ret := make(map[string][]string) if _, err := os.Stat(path); os.IsNotExist(err) { return ret @@ -136,18 +136,16 @@ func getImages(path string) map[string][]string { e := func(path string, fileInfo os.FileInfo, inpErr error) (err error) { if !fileInfo.IsDir() { - basesplit := strings.Split(fileInfo.Name(), "-") - if len(basesplit) == 3 { - extensionsplit := strings.Split(basesplit[2], ".") - if len(extensionsplit) == 2 { - // BUG: prob here - commaseperatorsplit := strings.Split(extensionsplit[0], ",") - id := commaseperatorsplit[1] - if _, ok := ret[id]; !ok { - ret[id] = make([]string, 0) - } - ret[id] = append(ret[id], path) + ext := filepath.Ext(fileInfo.Name()) + filename := strings.TrimSuffix(fileInfo.Name(), ext) + basesplit := strings.Split(filename, "-") + if len(basesplit) >= 3 { + commaseperatorsplit := strings.Split(basesplit[2], ",") + id := commaseperatorsplit[0] + if _, ok := ret[id]; !ok { + ret[id] = make([]string, 0) } + ret[id] = append(ret[id], path) } } return nil