Files
Atlas/internal/store/files.go
T
renjue 4009214cbc
CI / docker (push) Successful in 7m4s
实现 Atlas AI 平台一期能力并完成品牌化改造。
引入用户端对话/生图与管理端 Provider 配置,统一 invoke 编排、Gateway、请求日志与模型管理;前端按设计规范拆分布局,Go module 更名为 github.com/rose_cat707/Atlas;生图长任务 SSE 推送;管理端登录防爆破;协议与服务类型联动;Replicate 模型同步修复;用户端创作台 UI 重构;管理端创作历史替代请求日志。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 21:08:57 +08:00

45 lines
1.5 KiB
Go

package store
import "context"
type FileRecord struct {
ID int64 `json:"id"`
SessionID string `json:"session_id"`
Kind string `json:"kind"`
Mime string `json:"mime"`
StoragePath string `json:"storage_path"`
SizeBytes int64 `json:"size_bytes"`
SHA256 string `json:"sha256"`
ExpiresAt *string `json:"expires_at"`
CreatedAt string `json:"created_at"`
}
func (s *Store) InsertFile(ctx context.Context, f *FileRecord) (int64, error) {
res, err := s.db.ExecContext(ctx,
`INSERT INTO files (session_id, kind, mime, storage_path, size_bytes, sha256, expires_at) VALUES (?, ?, ?, ?, ?, ?, ?)`,
f.SessionID, f.Kind, f.Mime, f.StoragePath, f.SizeBytes, f.SHA256, f.ExpiresAt,
)
if err != nil {
return 0, err
}
return res.LastInsertId()
}
func (s *Store) GetFile(ctx context.Context, sessionID string, id int64) (*FileRecord, error) {
var f FileRecord
err := s.db.QueryRowContext(ctx,
`SELECT id, session_id, kind, mime, storage_path, size_bytes, sha256, expires_at, created_at FROM files WHERE id = ? AND session_id = ?`, id, sessionID,
).Scan(&f.ID, &f.SessionID, &f.Kind, &f.Mime, &f.StoragePath, &f.SizeBytes, &f.SHA256, &f.ExpiresAt, &f.CreatedAt)
if err != nil {
return nil, err
}
return &f, nil
}
func (s *Store) CountFiles(ctx context.Context) (int, int64, error) {
var count int
var total int64
err := s.db.QueryRowContext(ctx, `SELECT COUNT(*), COALESCE(SUM(size_bytes),0) FROM files`).Scan(&count, &total)
return count, total, err
}