Make it more implementable

This commit is contained in:
2024-08-20 19:17:43 +08:00
parent 73b39a4fb5
commit 37c47f9839
6 changed files with 21 additions and 24 deletions

View File

@ -25,7 +25,6 @@ type Attachment struct {
Alternative string `json:"alt"`
MimeType string `json:"mimetype"`
HashCode string `json:"hash"`
UserHash *string `json:"user_hash"`
Destination AttachmentDst `json:"destination"`
RefCount int `json:"ref_count"`

View File

@ -19,7 +19,6 @@ func createAttachmentMultipartPlaceholder(c *fiber.Ctx) error {
var data struct {
Pool string `json:"pool" validate:"required"`
Size int64 `json:"size" validate:"required"`
Hash string `json:"hash" validate:"required"`
Alternative string `json:"alt"`
MimeType string `json:"mimetype"`
Metadata map[string]any `json:"metadata"`
@ -43,7 +42,6 @@ func createAttachmentMultipartPlaceholder(c *fiber.Ctx) error {
}
metadata, err := services.NewAttachmentPlaceholder(database.C, user, models.Attachment{
UserHash: &data.Hash,
Alternative: data.Alternative,
MimeType: data.MimeType,
Metadata: data.Metadata,
@ -57,7 +55,10 @@ func createAttachmentMultipartPlaceholder(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
}
return c.JSON(metadata)
return c.JSON(fiber.Map{
"chunk_size": viper.GetInt64("performance.file_chunk_size"),
"meta": metadata,
})
}
func uploadAttachmentMultipart(c *fiber.Ctx) error {

View File

@ -99,6 +99,14 @@ func AnalyzeAttachment(file models.Attachment) error {
var start time.Time
if len(file.HashCode) == 0 {
if hash, err := HashAttachment(file); err != nil {
return err
} else {
file.HashCode = hash
}
}
// Do analyze jobs
if !file.IsAnalyzed || len(file.HashCode) == 0 {
destMap := viper.GetStringMap("destinations.temporary")
@ -158,12 +166,6 @@ func AnalyzeAttachment(file models.Attachment) error {
"color_space": stream.ColorSpace,
}
}
if hash, err := HashAttachment(file); err != nil {
return err
} else {
file.HashCode = hash
}
}
tx := database.C.Begin()

View File

@ -44,5 +44,7 @@ func MergeFileChunks(meta models.Attachment, arrange []string) (models.Attachmen
meta.IsUploaded = true
database.C.Save(&meta)
PublishAnalyzeTask(meta)
return meta, nil
}