file-system/internal/domain/repository/file_repository.go
root d861be0d6e feat: 新增文件文本内容接口,修复Markdown预览
- 新增 GET /files/content 接口,后端直接读取S3文件文本内容返回
- Repository 新增 GetFileContent 方法
- CQRS: 新增 GetFileContentQuery / GetFileContentHandler
- 前端 Markdown 预览改为调用后端接口获取内容,用 marked.js 渲染
- 解决 presigned URL CORS 和下载头导致 MD 文件无法预览的问题
- config.go: AuthAPIKey 默认值恢复为 xn001624.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-06 18:08:42 +08:00

46 lines
1.7 KiB
Go

package repository
import (
"context"
"file-system/internal/common"
"io"
"time"
)
type FileInfo struct {
Key string
Size int64
LastModified time.Time
ETag string
}
type ListFilesResult struct {
Files []FileInfo
NextContinuationToken *string
}
type FileRepository interface {
UploadFile(ctx context.Context, bucketName string, objectKey string, data io.Reader) error
DownloadFile(ctx context.Context, bucketName string, objectKey string) (io.ReadCloser, error)
ListBuckets(ctx context.Context) ([]string, error)
CreateBucket(ctx context.Context, bucketName string) error
DeleteBucket(ctx context.Context, bucketName string) error
ListObjects(ctx context.Context, bucketName string) ([]string, error)
// 新增功能
ListObjectsV2(ctx context.Context, bucketName string, prefix string, maxKeys int32, continuationToken *string) (*ListFilesResult, error)
GeneratePresignedURL(ctx context.Context, bucketName string, objectKey string, expiry time.Duration) (string, error)
// 获取文件文本内容(用于文本文件预览)
GetFileContent(ctx context.Context, bucketName string, objectKey string) (string, error)
// 删除文件
DeleteFile(ctx context.Context, bucketName string, objectKey string) error
// 分片上传
CreateMultipartUpload(ctx context.Context, bucketName string, objectKey string) (string, error)
UploadPart(ctx context.Context, bucketName string, objectKey string, uploadId string, partNumber int32, data io.Reader) (string, error)
CompleteMultipartUpload(ctx context.Context, bucketName string, objectKey string, uploadId string, parts []common.Part) (string, error)
AbortMultipartUpload(ctx context.Context, bucketName string, objectKey string, uploadId string) error
}