mirror of
https://github.com/teest114514/chatlog_alpha.git
synced 2026-03-29 22:57:06 +08:00
Improved image file access by supporting files in Rec subdirectories using the extra_buffer field, and enhanced decryption logic to handle files without extensions as .dat files, with fallback to serving as-is if decryption fails. Updated MediaV4 model and datasource to extract and use extra_buffer, and revised README to document these changes.
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package model
|
|
|
|
import (
|
|
"path/filepath"
|
|
"regexp"
|
|
)
|
|
|
|
type MediaV4 struct {
|
|
Type string `json:"type"`
|
|
Key string `json:"key"`
|
|
Dir1 string `json:"dir1"`
|
|
Dir2 string `json:"dir2"`
|
|
ExtraBuffer string `json:"extraBuffer"` // Extra buffer for Rec subdirectory
|
|
Name string `json:"name"`
|
|
Size int64 `json:"size"`
|
|
ModifyTime int64 `json:"modifyTime"`
|
|
}
|
|
|
|
func (m *MediaV4) Wrap() *Media {
|
|
|
|
var path string
|
|
switch m.Type {
|
|
case "image":
|
|
// Clean extra_buffer: extract only alphanumeric characters
|
|
extraBuffer := m.cleanExtraBuffer(m.ExtraBuffer)
|
|
if extraBuffer != "" {
|
|
// Path with Rec/{extra_buffer}: msg/attach/{Dir1}/{Dir2}/Rec/{extraBuffer}/Img/{Name}
|
|
path = filepath.Join("msg", "attach", m.Dir1, m.Dir2, "Rec", extraBuffer, "Img", m.Name)
|
|
} else {
|
|
// Fallback to old path format: msg/attach/{Dir1}/{Dir2}/Img/{Name}
|
|
path = filepath.Join("msg", "attach", m.Dir1, m.Dir2, "Img", m.Name)
|
|
}
|
|
case "video":
|
|
path = filepath.Join("msg", "video", m.Dir1, m.Name)
|
|
case "file":
|
|
path = filepath.Join("msg", "file", m.Dir1, m.Name)
|
|
}
|
|
|
|
return &Media{
|
|
Type: m.Type,
|
|
Key: m.Key,
|
|
Path: path,
|
|
Name: m.Name,
|
|
Size: m.Size,
|
|
ModifyTime: m.ModifyTime,
|
|
}
|
|
}
|
|
|
|
// cleanExtraBuffer extracts only alphanumeric characters from extra_buffer
|
|
func (m *MediaV4) cleanExtraBuffer(extraBuffer string) string {
|
|
if extraBuffer == "" {
|
|
return ""
|
|
}
|
|
|
|
// Remove all non-alphanumeric characters
|
|
re := regexp.MustCompile(`[^a-zA-Z0-9]`)
|
|
cleaned := re.ReplaceAllString(extraBuffer, "")
|
|
|
|
// Only return if we have meaningful content
|
|
if cleaned != "" {
|
|
return cleaned
|
|
}
|
|
|
|
return ""
|
|
}
|