Files
chatlog/internal/model/media.go
2025-03-28 16:48:49 +08:00

45 lines
1010 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package model
import (
"path/filepath"
)
type Media struct {
Type string `json:"type"` // 媒体类型image, video, voice, file
Key string `json:"key"` // MD5
Path string `json:"path"`
Name string `json:"name"`
Size int64 `json:"size"`
ModifyTime int64 `json:"modifyTime"`
}
type MediaV3 struct {
Type string `json:"type"`
Key string `json:"key"`
Dir1 string `json:"dir1"`
Dir2 string `json:"dir2"`
Name string `json:"name"`
ModifyTime int64 `json:"modifyTime"`
}
func (m *MediaV3) Wrap() *Media {
var path string
switch m.Type {
case "image":
path = filepath.Join("FileStorage", "MsgAttach", m.Dir1, "Image", m.Dir2, m.Name)
case "video":
path = filepath.Join("FileStorage", "Video", m.Dir2, m.Name)
case "file":
path = filepath.Join("FileStorage", "File", m.Dir2, m.Name)
}
return &Media{
Type: m.Type,
Key: m.Key,
ModifyTime: m.ModifyTime,
Path: path,
Name: m.Name,
}
}