33 lines
874 B
Go
33 lines
874 B
Go
package routes
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.artlef.fr/PersonalLibraryManager/internal/appcontext"
|
|
"git.artlef.fr/PersonalLibraryManager/internal/dto"
|
|
"git.artlef.fr/PersonalLibraryManager/internal/fileutils"
|
|
"git.artlef.fr/PersonalLibraryManager/internal/model"
|
|
"git.artlef.fr/PersonalLibraryManager/internal/myvalidator"
|
|
)
|
|
|
|
func PostUploadBookCoverHandler(ac appcontext.AppContext) {
|
|
file, err := ac.C.FormFile("file")
|
|
if err != nil {
|
|
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
|
return
|
|
}
|
|
staticFile, saveErr := fileutils.SaveStaticFile(&ac, file)
|
|
if saveErr != nil {
|
|
myvalidator.ReturnErrorsAsJsonResponse(&ac, saveErr)
|
|
return
|
|
}
|
|
ac.C.JSON(http.StatusOK, staticFileDbToWs(&staticFile))
|
|
}
|
|
|
|
func staticFileDbToWs(f *model.StaticFile) dto.FileInfoPost {
|
|
return dto.FileInfoPost{
|
|
FileID: f.ID,
|
|
FilePath: fileutils.GetWsLinkPrefix() + f.Path,
|
|
}
|
|
}
|