- Move from separate dirs for upload to a unified one (identify media/metadata files by file extension) - Prevent uploading when an import is already scheduled - Allow setting custom, parser-specific settings - Add CLI - Implement WebDAV upload - Implement checking of upload folders for uploadable contents Close #6, close #7, close #9, close #3, close #1, close #4
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package configloader
|
|
|
|
import _ "embed"
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"slices"
|
|
)
|
|
|
|
type ParserListItem struct {
|
|
Title string `json:"title"`
|
|
Comment string `json:"comment"`
|
|
Authors []string `json:"authors"`
|
|
Links []string `json:"links"`
|
|
}
|
|
|
|
// Load parser list from JSON retrieved from musdb's API
|
|
// See https://<subdomain>.museum-digital.org/musdb/api/meta/list_import_parsers
|
|
// The embed module requires the variable to not be bound to a function.
|
|
|
|
//go:embed parser_list.json
|
|
var rawParserList []byte
|
|
|
|
// Returns a list of the available parsers.
|
|
func ListParsers() []ParserListItem {
|
|
|
|
parserListFromApi := []ParserListItem{}
|
|
// parserListFromApi := new(ApiParserListFormat)
|
|
json.Unmarshal(rawParserList, &parserListFromApi)
|
|
|
|
return parserListFromApi
|
|
|
|
}
|
|
|
|
// Checks if inputParser is in the list of available parsers.
|
|
// Returns the parser name or an error.
|
|
func ValidateParser(inputParser string) (string, error) {
|
|
|
|
parserList := ListParsers()
|
|
parserTitles := []string{}
|
|
|
|
for _, p := range(parserList) {
|
|
parserTitles = append(parserTitles, p.Title)
|
|
}
|
|
|
|
if slices.Contains(parserTitles, inputParser) {
|
|
return inputParser, nil
|
|
}
|
|
|
|
// Accepted invalid modes to clean up:
|
|
// ParserLido > Lido
|
|
// lido > Lido
|
|
cleaned := inputParser[6:]
|
|
if slices.Contains(parserTitles, cleaned) {
|
|
return cleaned, nil
|
|
}
|
|
|
|
return "", errors.New("Invalid parser selected")
|
|
|
|
}
|