Manage display of book covers
This commit is contained in:
@@ -4,21 +4,33 @@ import (
|
||||
"net/http"
|
||||
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/appcontext"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/fileutils"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/model"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/myvalidator"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type fileInfoPost struct {
|
||||
FileID uint `json:"fileId"`
|
||||
FilePath string `json:"filepath"`
|
||||
}
|
||||
|
||||
func PostUploadBookCoverHandler(ac appcontext.AppContext) {
|
||||
file, err := ac.C.FormFile("file")
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
filepath := file.Filename
|
||||
err = ac.C.SaveUploadedFile(file, ac.Config.ImageFolderPath+"/"+filepath)
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
staticFile, saveErr := fileutils.SaveStaticFile(&ac, file)
|
||||
if saveErr != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, saveErr)
|
||||
return
|
||||
}
|
||||
ac.C.JSON(http.StatusOK, gin.H{"filepath": "/bookcover/" + filepath})
|
||||
ac.C.JSON(http.StatusOK, staticFileDbToWs(&staticFile))
|
||||
}
|
||||
|
||||
func staticFileDbToWs(f *model.StaticFile) fileInfoPost {
|
||||
return fileInfoPost{
|
||||
FileID: f.ID,
|
||||
FilePath: fileutils.GetWsLinkPrefix() + f.Path,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user