mongo

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrImageNotFound      = errors.New("image not found")
	ErrInvalidImageType   = errors.New("invalid image type")
	ErrImageAlreadyExists = errors.New("image already exists")
)

Error definitions

Functions

func CloseMongoDB

func CloseMongoDB() error

CloseMongoDB closes the MongoDB connection

func GetClient

func GetClient() *mongo.Client

func GetCollection

func GetCollection(collectionName string) *mongo.Collection

GetCollection returns a collection from the database

func GetDB

func GetDB() *mongo.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

func GetImageData(ctx context.Context, imageID string) (io.ReadCloser, *ImageMeta, error)

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

func (is *ImageStore) GetImageByChecksum(ctx context.Context, checksum string) (*ImageMeta, error)

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

func (is *ImageStore) GetImageMeta(ctx context.Context, imageID string) (*ImageMeta, error)

GetImageMeta retrieves image metadata by ID

func (*ImageStore) GetImageStats

func (is *ImageStore) GetImageStats(ctx context.Context) (map[string]any, error)

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

func (is *ImageStore) UpdateImageTags(ctx context.Context, imageID string, tags []string) error

UpdateImageTags updates image tags

type MongoOptions

type MongoOptions struct {
	URI    string
	DBName string
	// if true, will only initialize the client, not the database, default is false
	ClientOnly bool
}

type MongoStorage

type MongoStorage struct{}

MongoStorage 实现 Storage 接口的 MongoDB 版本

func NewMongoStorage

func NewMongoStorage() *MongoStorage

NewMongoStorage 创建 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

func (s *MongoStorage) GetUserTask(ctx context.Context, taskID string) (*op.UserTask, error)

-------------------------------- 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 (s *MongoStorage) ListUserTasks(ctx context.Context, uid string) ([]*op.UserTask, error)

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 --------------------------------

func (*MongoStorage) UpsertUserTask

func (s *MongoStorage) UpsertUserTask(ctx context.Context, task *op.UserTask) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL