Documentation
¶
Index ¶
- Variables
- func CloseMongoDB() error
- func GetClient() *mongo.Client
- func GetCollection(collectionName string) *mongo.Collection
- func GetDB() *mongo.Database
- func NewBucket() error
- func NewImageStore(imageMetaCollection *mongo.Collection) error
- func NewMongo(opts *MongoOptions) error
- type ImageMeta
- type ImageStore
- func (is *ImageStore) CleanupOrphanedFiles(ctx context.Context) (int, error)
- func (is *ImageStore) DeleteImage(ctx context.Context, imageID string) error
- func (is *ImageStore) DownloadImageToFile(ctx context.Context, imageID, outputPath string) error
- func (is *ImageStore) GetImageByChecksum(ctx context.Context, checksum string) (*ImageMeta, error)
- func (is *ImageStore) GetImageData(ctx context.Context, imageID string) (io.ReadCloser, *ImageMeta, error)
- func (is *ImageStore) GetImageMeta(ctx context.Context, imageID string) (*ImageMeta, error)
- func (is *ImageStore) GetImageStats(ctx context.Context) (map[string]any, error)
- func (is *ImageStore) ListImages(ctx context.Context, tags []string, limit, offset int64) ([]*ImageMeta, error)
- func (is *ImageStore) StoreImageFromFile(ctx context.Context, imagePath string, tags []string, metadata map[string]any) (string, error)
- func (is *ImageStore) StoreImageFromReader(ctx context.Context, reader io.Reader, filename string, tags []string, ...) (string, error)
- func (is *ImageStore) UpdateImageMetadata(ctx context.Context, imageID string, metadata map[string]any) error
- func (is *ImageStore) UpdateImageTags(ctx context.Context, imageID string, tags []string) error
- type MongoOptions
- type MongoStorage
- func (s *MongoStorage) BindThreadIDToUserTaskID(ctx context.Context, taskID, threadID string) error
- func (s *MongoStorage) DeleteModel(ctx context.Context, id string) error
- func (s *MongoStorage) DeleteThreadIDFromUserTask(ctx context.Context, taskID, threadID string) error
- func (s *MongoStorage) DeleteUserTask(ctx context.Context, taskID string) error
- func (s *MongoStorage) GetModel(ctx context.Context, id string) (*op.ModelConfig, error)
- func (s *MongoStorage) GetUserSettings(ctx context.Context, uid string) (*op.UserSettings, error)
- func (s *MongoStorage) GetUserTask(ctx context.Context, taskID string) (*op.UserTask, error)
- func (s *MongoStorage) ListModelIDs(ctx context.Context) ([]string, error)
- func (s *MongoStorage) ListModels(ctx context.Context) ([]*op.ModelConfig, error)
- func (s *MongoStorage) ListUIDs(ctx context.Context) ([]string, error)
- func (s *MongoStorage) ListUserTasks(ctx context.Context, uid string) ([]*op.UserTask, error)
- func (s *MongoStorage) UpsertModel(ctx context.Context, model *op.ModelConfig) error
- func (s *MongoStorage) UpsertUserSettings(ctx context.Context, settings *op.UserSettings) error
- func (s *MongoStorage) UpsertUserTask(ctx context.Context, task *op.UserTask) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrImageNotFound = errors.New("image not found") ErrInvalidImageType = errors.New("invalid image type") ErrImageAlreadyExists = errors.New("image already exists") )
Error definitions
Functions ¶
func GetCollection ¶
func GetCollection(collectionName string) *mongo.Collection
GetCollection returns a collection from the database
func NewBucket ¶
func NewBucket() error
InitMongoDB initializes MongoDB connection, if image is true, it will initialize the GridFS bucket
func NewImageStore ¶
func NewImageStore(imageMetaCollection *mongo.Collection) error
NewImageStore creates a new image store manager
func NewMongo ¶
func NewMongo(opts *MongoOptions) error
Types ¶
type ImageMeta ¶
type ImageMeta struct {
ImageID string `bson:"imageID" json:"imageID"` // Image ID
GridFSID primitive.ObjectID `bson:"gridfsID" json:"gridfsID"` // Internal GridFS ID
OriginalName string `bson:"originalName" json:"originalName"` // Original filename
ContentType string `bson:"contentType" json:"contentType"` // MIME type
Size int64 `bson:"size" json:"size"` // File size in bytes
Checksum string `bson:"checksum" json:"checksum"` // SHA256 checksum
Tags []string `bson:"tags,omitempty" json:"tags,omitempty"` // Tags
Metadata map[string]any `bson:"metadata,omitempty" json:"metadata,omitempty"` // Custom metadata
CreatedAt time.Time `bson:"createdAt" json:"createdAt"` // Creation time
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` // Update time
}
ImageMeta represents image metadata structure
func GetImageData ¶
type ImageStore ¶
type ImageStore struct {
// contains filtered or unexported fields
}
ImageStore manages image storage operations
func (*ImageStore) CleanupOrphanedFiles ¶
func (is *ImageStore) CleanupOrphanedFiles(ctx context.Context) (int, error)
CleanupOrphanedFiles cleans up orphaned files (files in GridFS but not in metadata)
func (*ImageStore) DeleteImage ¶
func (is *ImageStore) DeleteImage(ctx context.Context, imageID string) error
DeleteImage deletes image and its metadata
func (*ImageStore) DownloadImageToFile ¶
func (is *ImageStore) DownloadImageToFile(ctx context.Context, imageID, outputPath string) error
DownloadImageToFile downloads image to a file
func (*ImageStore) GetImageByChecksum ¶
GetImageByChecksum retrieves image metadata by checksum
func (*ImageStore) GetImageData ¶
func (is *ImageStore) GetImageData(ctx context.Context, imageID string) (io.ReadCloser, *ImageMeta, error)
GetImageData retrieves image data stream by ID
func (*ImageStore) GetImageMeta ¶
GetImageMeta retrieves image metadata by ID
func (*ImageStore) GetImageStats ¶
GetImageStats 获取图片存储统计信息
func (*ImageStore) ListImages ¶
func (is *ImageStore) ListImages(ctx context.Context, tags []string, limit, offset int64) ([]*ImageMeta, error)
ListImages lists images with pagination and filtering support
func (*ImageStore) StoreImageFromFile ¶
func (is *ImageStore) StoreImageFromFile(ctx context.Context, imagePath string, tags []string, metadata map[string]any) (string, error)
StoreImageFromFile stores an image from a file path
func (*ImageStore) StoreImageFromReader ¶
func (is *ImageStore) StoreImageFromReader(ctx context.Context, reader io.Reader, filename string, tags []string, metadata map[string]any) (string, error)
StoreImageFromReader stores an image from an io.Reader
func (*ImageStore) UpdateImageMetadata ¶
func (is *ImageStore) UpdateImageMetadata(ctx context.Context, imageID string, metadata map[string]any) error
UpdateImageMetadata updates image custom metadata
func (*ImageStore) UpdateImageTags ¶
UpdateImageTags updates image tags
type MongoOptions ¶
type MongoStorage ¶
type MongoStorage struct{}
MongoStorage 实现 Storage 接口的 MongoDB 版本
func (*MongoStorage) BindThreadIDToUserTaskID ¶
func (s *MongoStorage) BindThreadIDToUserTaskID(ctx context.Context, taskID, threadID string) error
BindThreadIDToTaskID 将 threadID 绑定到 taskID
func (*MongoStorage) DeleteModel ¶
func (s *MongoStorage) DeleteModel(ctx context.Context, id string) error
func (*MongoStorage) DeleteThreadIDFromUserTask ¶
func (s *MongoStorage) DeleteThreadIDFromUserTask(ctx context.Context, taskID, threadID string) error
func (*MongoStorage) DeleteUserTask ¶
func (s *MongoStorage) DeleteUserTask(ctx context.Context, taskID string) error
func (*MongoStorage) GetModel ¶
func (s *MongoStorage) GetModel(ctx context.Context, id string) (*op.ModelConfig, error)
func (*MongoStorage) GetUserSettings ¶
func (s *MongoStorage) GetUserSettings(ctx context.Context, uid string) (*op.UserSettings, error)
func (*MongoStorage) GetUserTask ¶
-------------------------------- user task --------------------------------
func (*MongoStorage) ListModelIDs ¶
func (s *MongoStorage) ListModelIDs(ctx context.Context) ([]string, error)
ListModelIDs returns a list of distinct model IDs, represented as ModelConfig objects with only ID populated.
func (*MongoStorage) ListModels ¶
func (s *MongoStorage) ListModels(ctx context.Context) ([]*op.ModelConfig, error)
-------------------------------- models --------------------------------
func (*MongoStorage) ListUIDs ¶
func (s *MongoStorage) ListUIDs(ctx context.Context) ([]string, error)
func (*MongoStorage) ListUserTasks ¶
func (*MongoStorage) UpsertModel ¶
func (s *MongoStorage) UpsertModel(ctx context.Context, model *op.ModelConfig) error
func (*MongoStorage) UpsertUserSettings ¶
func (s *MongoStorage) UpsertUserSettings(ctx context.Context, settings *op.UserSettings) error
-------------------------------- user settings --------------------------------