refactor(backend): update file info retrieval to use models package and improve file slice creation logic

This commit is contained in:
keven1024
2025-04-28 20:17:53 +08:00
parent e32388f70a
commit ea998b7d34
3 changed files with 25 additions and 30 deletions

View File

@@ -1,5 +1,11 @@
package models
import (
"backend/internal/utils"
"encoding/json"
"errors"
)
type FileInfo struct {
FileSize int64 `json:"size"`
MimeType string `json:"mime_type"`
@@ -26,3 +32,17 @@ type RedisShareInfo struct {
FileId string `json:"fileId"`
CreatedAt int64 `json:"created_at"`
}
func GetRedisFileInfo(fileId string) (RedisFileInfo, error) {
rdb, ctx := utils.GetRedisClient()
fileInfoUnmarshalData, _ := rdb.HGet(ctx, "015:fileInfoMap", fileId).Result()
if fileInfoUnmarshalData != "" {
var fileInfoData RedisFileInfo
if err := json.Unmarshal([]byte(fileInfoUnmarshalData), &fileInfoData); err != nil {
return RedisFileInfo{}, err
}
return fileInfoData, nil
}
return RedisFileInfo{}, errors.New("db不存在该文件信息")
}