add SHA-1 hash calculation for file uploads and update related API and model structures

This commit is contained in:
nyne
2025-05-16 15:16:01 +08:00
parent a827b67c41
commit 5431328515
8 changed files with 174 additions and 20 deletions

View File

@@ -2,9 +2,10 @@ package model
import (
"context"
"reflect"
"gorm.io/gorm"
"gorm.io/gorm/schema"
"reflect"
)
type UploadingFile struct {
@@ -20,6 +21,7 @@ type UploadingFile struct {
TempPath string
Resource Resource `gorm:"foreignKey:TargetResourceID"`
Storage Storage `gorm:"foreignKey:TargetStorageID"`
Sha1 string
}
func (uf *UploadingFile) BlocksCount() int {
@@ -84,6 +86,7 @@ type UploadingFileView struct {
BlocksCount int `json:"blocksCount"`
StorageID uint `json:"storageId"`
ResourceID uint `json:"resourceId"`
Sha1 string `json:"sha1"`
}
func (uf *UploadingFile) ToView() *UploadingFileView {
@@ -96,5 +99,6 @@ func (uf *UploadingFile) ToView() *UploadingFileView {
BlocksCount: uf.BlocksCount(),
StorageID: uf.TargetStorageID,
ResourceID: uf.TargetResourceID,
Sha1: uf.Sha1,
}
}