Attachments

This commit is contained in:
2024-03-10 18:38:42 +08:00
parent 192d0c40bb
commit 38ba4d9c75
17 changed files with 328 additions and 60 deletions

View File

@ -1,11 +1,13 @@
package services
import (
"mime/multipart"
"net/http"
"strings"
"code.smartsheep.studio/hydrogen/interactive/pkg/database"
"code.smartsheep.studio/hydrogen/interactive/pkg/models"
"github.com/google/uuid"
"mime/multipart"
"net/http"
)
func NewAttachment(user models.Account, header *multipart.FileHeader) (models.Attachment, error) {
@ -33,6 +35,17 @@ func NewAttachment(user models.Account, header *multipart.FileHeader) (models.At
}
attachment.Mimetype = http.DetectContentType(fileHeader)
switch strings.Split(attachment.Mimetype, "/")[0] {
case "image":
attachment.Type = models.AttachmentPhoto
case "video":
attachment.Type = models.AttachmentVideo
case "audio":
attachment.Type = models.AttachmentAudio
default:
attachment.Type = models.AttachmentOthers
}
// Save into database
err = database.C.Save(&attachment).Error