mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 09:15:33 +00:00
Bilder & Vorschau / Tabellen für die Satrtseite
This commit is contained in:
@@ -2,12 +2,16 @@ package seed
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/xmlmodels"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/tools/filesystem"
|
||||
)
|
||||
|
||||
const NO_TITLE = "[No Title]"
|
||||
@@ -20,6 +24,8 @@ func RecordsFromInhalte(app core.App, inhalte xmlmodels.Inhalte) ([]*dbmodels.Co
|
||||
return records, err
|
||||
}
|
||||
|
||||
images := getImages(xmlmodels.IMG_PATH)
|
||||
|
||||
for i := 0; i < len(inhalte.Inhalte); i++ {
|
||||
record := dbmodels.NewContent(core.NewRecord(collection))
|
||||
inhalt := inhalte.Inhalte[i]
|
||||
@@ -28,6 +34,7 @@ func RecordsFromInhalte(app core.App, inhalte xmlmodels.Inhalte) ([]*dbmodels.Co
|
||||
app.Logger().Error("Error finding band record for inhalt", "error", err, "inhalt", inhalt)
|
||||
continue
|
||||
}
|
||||
|
||||
record.SetEntry(band.Id)
|
||||
record.SetAnnotation(NormalizeString(inhalt.Anmerkungen))
|
||||
record.SetMusenalmID(inhalt.ID)
|
||||
@@ -48,6 +55,21 @@ func RecordsFromInhalte(app core.App, inhalte xmlmodels.Inhalte) ([]*dbmodels.Co
|
||||
}
|
||||
record.SetNumbering(no)
|
||||
|
||||
images, ok := images[inhalt.ID]
|
||||
if ok {
|
||||
files := []*filesystem.File{}
|
||||
for _, image := range images {
|
||||
file, err := filesystem.NewFileFromPath(image)
|
||||
if err != nil {
|
||||
app.Logger().Error("Error creating file from path", "error", err, "path", image)
|
||||
continue
|
||||
}
|
||||
files = append(files, file)
|
||||
}
|
||||
|
||||
record.SetScans(files)
|
||||
}
|
||||
|
||||
handlePreferredTitle(inhalt, record)
|
||||
n := record.PreferredTitle()
|
||||
if n == "" || n == NO_TITLE {
|
||||
@@ -104,3 +126,36 @@ func commatizeArray(array []string) string {
|
||||
}
|
||||
return array[0]
|
||||
}
|
||||
|
||||
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
|
||||
ret := make(map[string][]string)
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
return ret
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := filepath.Walk(path, e); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user