feat: improve file handling by generating default file names and adding mime type detection

This commit is contained in:
krau
2025-02-16 15:43:02 +08:00
parent db69688722
commit 2d17a731c4
7 changed files with 48 additions and 26 deletions

View File

@@ -2,6 +2,8 @@ package types
import (
"context"
"crypto/md5"
"encoding/hex"
"fmt"
"time"
@@ -56,3 +58,18 @@ type File struct {
FileSize int64
FileName string
}
func (f File) Hash() string {
locationBytes := []byte(f.Location.String())
fileSizeBytes := []byte(fmt.Sprintf("%d", f.FileSize))
fileNameBytes := []byte(f.FileName)
structBytes := append(locationBytes, fileSizeBytes...)
structBytes = append(structBytes, fileNameBytes...)
hash := md5.New()
hash.Write(structBytes)
hashBytes := hash.Sum(nil)
return hex.EncodeToString(hashBytes)
}