mirror of
https://github.com/keven1024/015.git
synced 2026-06-10 06:14:34 +00:00
refactor(backend): update file info retrieval to use models package and improve file slice creation logic
This commit is contained in:
@@ -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不存在该文件信息")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user