diff --git a/internal/handlers/localfiles.go b/internal/handlers/localfiles.go index c8311622..a55abb57 100644 --- a/internal/handlers/localfiles.go +++ b/internal/handlers/localfiles.go @@ -19,6 +19,46 @@ func HandleGetLocalFiles(c *RouteCtx) error { //---------------------------------------------------------------------------------------------------------------------- +func HandleLocalFileBulkAction(c *RouteCtx) error { + + type body struct { + Action string `json:"action"` + } + + b := new(body) + if err := c.Fiber.BodyParser(b); err != nil { + return c.RespondWithError(err) + } + + // Get all the local files + lfs, dbId, err := getLocalFilesAndIdFromDB(c.App.Database) + if err != nil { + return c.RespondWithError(err) + } + + switch b.Action { + case "lock": + for _, lf := range lfs { + lf.Locked = true + } + case "unlock": + for _, lf := range lfs { + lf.Locked = false + } + } + + // Save the local files + retLfs, err := saveLocalFilesInDB(c.App.Database, dbId, lfs) + if err != nil { + return c.RespondWithError(err) + } + + return c.RespondWithData(retLfs) + +} + +//---------------------------------------------------------------------------------------------------------------------- + // HandleUpdateLocalFileData // POST func HandleUpdateLocalFileData(c *RouteCtx) error { diff --git a/internal/handlers/routes.go b/internal/handlers/routes.go index 010b5c01..30103e90 100644 --- a/internal/handlers/routes.go +++ b/internal/handlers/routes.go @@ -86,6 +86,9 @@ func InitRoutes(app *core.App, fiberApp *fiber.App) { // GET /v1/library/local-files v1Library.Get("/local-files", makeHandler(app, HandleGetLocalFiles)) + // POST /v1/library/local-files + v1Library.Post("/local-files", makeHandler(app, HandleLocalFileBulkAction)) + // Get the library collection // GET /v1/library/collection v1Library.Get("/collection", makeHandler(app, HandleGetLibraryCollection)) diff --git a/test/test_helper/test_helper.go b/test/test_helper/test_helper.go deleted file mode 100644 index 777ba594..00000000 --- a/test/test_helper/test_helper.go +++ /dev/null @@ -1,116 +0,0 @@ -package test_helper - -import ( - "github.com/goccy/go-json" - "github.com/seanime-app/seanime-server/internal/anilist" - "github.com/seanime-app/seanime-server/internal/entities" - "io" - "os" -) - -func MockGetTestLocalFiles() ([]*entities.LocalFile, bool) { - - // Open the JSON file - file, err := os.Open("../../test/sample/localfiles.json") - if err != nil { - println("Error opening file:", err.Error()) - return nil, false - } - defer file.Close() - - jsonData, err := io.ReadAll(file) - if err != nil { - println("Error reading file:", err.Error()) - return nil, false - } - - var data []*entities.LocalFile - if err := json.Unmarshal(jsonData, &data); err != nil { - println("Error unmarshaling JSON:", err.Error()) - return nil, false - } - - return data, true - -} -func MockGetSelectTestLocalFiles() ([]*entities.LocalFile, bool) { - - // Open the JSON file - file, err := os.Open("../../test/sample/localfiles_selected.json") - if err != nil { - println("Error opening file:", err.Error()) - return nil, false - } - defer file.Close() - - jsonData, err := io.ReadAll(file) - if err != nil { - println("Error reading file:", err.Error()) - return nil, false - } - - var data []*entities.LocalFile - if err := json.Unmarshal(jsonData, &data); err != nil { - println("Error unmarshaling JSON:", err.Error()) - return nil, false - } - - return data, true - -} - -type JWT struct { - JWT string `json:"jwt"` -} - -func MockGetAnilistClient() *anilist.Client { - - // Open the JSON file - file, err := os.Open("../../test/sample/jwt.json") - if err != nil { - println("Error opening file:", err.Error()) - return nil - } - defer file.Close() - - jsonData, err := io.ReadAll(file) - if err != nil { - println("Error reading file:", err.Error()) - return nil - } - - var data *JWT - if err := json.Unmarshal(jsonData, &data); err != nil { - println("Error unmarshaling JSON:", err.Error()) - return nil - } - - anilistClient := anilist.NewAuthedClient(data.JWT) - - return anilistClient -} - -func MockAllMedia() *[]*anilist.BaseMedia { - - // Open the JSON file - file, err := os.Open("../../test/sample/media.json") - if err != nil { - println("Error opening file:", err.Error()) - return nil - } - defer file.Close() - - jsonData, err := io.ReadAll(file) - if err != nil { - println("Error reading file:", err.Error()) - return nil - } - - var data []*anilist.BaseMedia - if err := json.Unmarshal(jsonData, &data); err != nil { - println("Error unmarshaling JSON:", err.Error()) - return nil - } - - return &data -}