fix/feat: primary photo auto set and auto-set primary photo (#651)

* fix error when item doesn't have photo attachment

* automatically detect image types and set primary photo if first

* remove charts.js from libs

Former-commit-id: 321a83b6344461233979e4f45e60f3121b1ffcef
This commit is contained in:
Hayden 2023-12-01 11:57:29 -06:00 committed by GitHub
parent bd1a241be1
commit 81e76d9dd4
13 changed files with 41 additions and 424 deletions

View file

@ -3,6 +3,7 @@ package v1
import (
"errors"
"net/http"
"path/filepath"
"github.com/hay-kot/homebox/backend/internal/core/services"
"github.com/hay-kot/homebox/backend/internal/data/ent/attachment"
@ -67,7 +68,15 @@ func (ctrl *V1Controller) HandleItemAttachmentCreate() errchain.HandlerFunc {
attachmentType := r.FormValue("type")
if attachmentType == "" {
attachmentType = attachment.TypeAttachment.String()
// Attempt to auto-detect the type of the file
ext := filepath.Ext(attachmentName)
switch ext {
case ".jpg", ".jpeg", ".png", ".webp", ".gif", ".bmp", ".tiff":
attachmentType = attachment.TypePhoto.String()
default:
attachmentType = attachment.TypeAttachment.String()
}
}
id, err := ctrl.routeID(r)