diff --git a/.gitignore b/.gitignore index a10ea14..813ce63 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ go.work.sum .env **/build/** +!cmd/openem-ingestor-app/build/appicon.png dist/** diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 84d8b9b..881013e 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -22,7 +22,7 @@ before: builds: # The app build is invoked via wails and binary copied manually to the expected output folder - - id: "openem-ingestor-app" + - id: openem-ingestor-app-linux hooks: pre: - cmd: mkdir {{dir .Path}} @@ -38,6 +38,27 @@ builds: dir: ./cmd/openem-ingestor-app goos: - linux + goarch: + - amd64 + main: . + binary: openem-ingestor-app + gobinary: echo + + - id: openem-ingestor-app-win + hooks: + pre: + - cmd: mkdir {{dir .Path}} + post: + - dir: cmd/openem-ingestor-app + cmd: wails build -platform {{ .Os }} -clean -windowsconsole -ldflags "-s -w -X 'main.version={{.Version}}'" -trimpath -o {{base .Path}} + output: true + - dir: cmd/openem-ingestor-app + cmd: cp build/bin/{{base .Path}} {{dir .Path}}/ + output: true + env: + - CGO_ENABLED=0 + dir: ./cmd/openem-ingestor-app + goos: - windows goarch: - amd64 @@ -45,7 +66,6 @@ builds: binary: openem-ingestor-app gobinary: echo - - id: "openem-ingestor-service" flags: - -trimpath @@ -63,7 +83,8 @@ builds: archives: - id: "openem-ingestor-app" builds: - - openem-ingestor-app + - openem-ingestor-app-linux + - openem-ingestor-app-win format: tar.gz wrap_in_directory: true @@ -104,6 +125,7 @@ archives: dst: ./ - src: configs/schemas/*.json dst: schemas + changelog: sort: asc filters: diff --git a/cmd/openem-ingestor-app/app.go b/cmd/openem-ingestor-app/app.go index ffca88c..d740ad4 100644 --- a/cmd/openem-ingestor-app/app.go +++ b/cmd/openem-ingestor-app/app.go @@ -2,10 +2,13 @@ package main import ( "context" + "fmt" "log" + "log/slog" core "github.com/SwissOpenEM/Ingestor/internal/core" - "github.com/SwissOpenEM/Ingestor/internal/task" + metadataextractor "github.com/SwissOpenEM/Ingestor/internal/metadataextractor" + task "github.com/SwissOpenEM/Ingestor/internal/task" webserver "github.com/SwissOpenEM/Ingestor/internal/webserver" "github.com/google/uuid" @@ -48,10 +51,11 @@ func (w *WailsNotifier) OnTaskProgress(id uuid.UUID, current_file int, total_fil // App struct type App struct { - ctx context.Context - taskqueue core.TaskQueue - config core.Config - version string + ctx context.Context + taskqueue core.TaskQueue + config core.Config + extractorHandler *metadataextractor.ExtractorHandler + version string } // NewApp creates a new App application struct @@ -77,6 +81,9 @@ func (b *App) beforeClose(ctx context.Context) (prevent bool) { // so we can call the runtime methods func (a *App) startup(ctx context.Context) { a.ctx = ctx + + a.extractorHandler = metadataextractor.NewExtractorHandler(a.config.MetadataExtractors) + a.taskqueue = core.TaskQueue{Config: a.config, AppContext: a.ctx, Notifier: &WailsNotifier{AppContext: a.ctx}, @@ -88,11 +95,12 @@ func (a *App) startup(ctx context.Context) { s := webserver.NewIngesterServer(ingestor, port) log.Fatal(s.ListenAndServe()) }(a.config.Misc.Port) + } func (a *App) SelectFolder() { folder, err := task.SelectFolder(a.ctx) - if err != nil { + if err != nil || folder.FolderPath == "" { return } @@ -102,6 +110,58 @@ func (a *App) SelectFolder() { } } +func (a *App) ExtractMetadata(extractor_name string, id uuid.UUID) string { + + folder := a.taskqueue.GetTaskFolder(id) + if folder == "" { + return "" + } + + log_message := func(id uuid.UUID, msg string) { + slog.Info("Extractor output: ", "message", msg) + runtime.EventsEmit(a.ctx, "log-update", id, msg) + } + + log_error := func(id uuid.UUID, msg string) { + slog.Info("Extractor error: ", "message", msg) + runtime.EventsEmit(a.ctx, "log-update", id, msg) + } + + outputfile := metadataextractor.MetadataFilePath(folder) + + metadata, err := a.extractorHandler.ExtractMetadata(a.ctx, extractor_name, folder, outputfile, func(message string) { log_message(id, message) }, func(message string) { log_error(id, message) }) + + if err != nil { + slog.Error("Metadata extraction failed", "error", err.Error()) + return fmt.Sprintf("{\"status\":\"%s\"}", err.Error()) + } + return metadata +} + +type ExtractionMethod struct { + Name string + Schema string +} + +func (e *ExtractionMethod) GetName() string { + return e.Name +} + +func (e *ExtractionMethod) GetSchema() string { + return e.Schema +} + +func (a *App) AvailableMethods() []ExtractionMethod { + e := []ExtractionMethod{} + for _, ex := range a.extractorHandler.AvailableMethods() { + e = append(e, ExtractionMethod{ + Name: ex.Name, + Schema: ex.Schema, + }) + } + return e +} + func (a *App) CancelTask(id uuid.UUID) { a.taskqueue.CancelTask(id) } diff --git a/cmd/openem-ingestor-app/build/appicon.png b/cmd/openem-ingestor-app/build/appicon.png new file mode 100644 index 0000000..eb9ffea Binary files /dev/null and b/cmd/openem-ingestor-app/build/appicon.png differ diff --git a/cmd/openem-ingestor-app/frontend/src/App.svelte b/cmd/openem-ingestor-app/frontend/src/App.svelte index 89460d6..336b8af 100644 --- a/cmd/openem-ingestor-app/frontend/src/App.svelte +++ b/cmd/openem-ingestor-app/frontend/src/App.svelte @@ -1,15 +1,22 @@
- + + +
+

Metadata Extractors

+ + +
+
+