Initial open-source release (MIT): image2api AI gateway

Full Go backend + Vue 3 frontend, OpenAI-compatible API, multi-provider
account pools, billing/admin, Docker one-command deploy with auto HTTPS.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-25 22:59:04 +08:00
co-authored by Claude Opus 4.8
commit 606caaf047
142 changed files with 33648 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
package repo
import (
"context"
"encoding/json"
"time"
"backend/internal/model"
"gorm.io/datatypes"
"gorm.io/gorm"
)
type ModelRepository struct {
db *gorm.DB
}
func NewModelRepository(db *gorm.DB) *ModelRepository {
return &ModelRepository{db: db}
}
func (r *ModelRepository) List(ctx context.Context) ([]model.ModelConfig, error) {
var items []model.ModelConfig
// Higher weight floats to the top of the dropdown / admin list; ties fall
// back to newest-first so order stays stable for equal-weight models.
if err := r.db.WithContext(ctx).Order("weight desc, created_at desc").Find(&items).Error; err != nil {
return nil, err
}
return items, nil
}
func (r *ModelRepository) Get(ctx context.Context, modelID string) (*model.ModelConfig, error) {
var item model.ModelConfig
if err := r.db.WithContext(ctx).First(&item, "id = ?", modelID).Error; err != nil {
return nil, err
}
return &item, nil
}
func JSONStrings(v datatypes.JSON) []string {
if len(v) == 0 {
return []string{}
}
var out []string
if err := json.Unmarshal([]byte(v), &out); err == nil {
return out
}
return []string{}
}
func (r *ModelRepository) Create(ctx context.Context, item *model.ModelConfig) error {
return r.db.WithContext(ctx).Create(item).Error
}
func (r *ModelRepository) Update(ctx context.Context, modelID string, patch map[string]any) (*model.ModelConfig, error) {
patch["updated_at"] = time.Now()
if err := r.db.WithContext(ctx).Model(&model.ModelConfig{}).Where("id = ?", modelID).Updates(patch).Error; err != nil {
return nil, err
}
var item model.ModelConfig
if err := r.db.WithContext(ctx).First(&item, "id = ?", modelID).Error; err != nil {
return nil, err
}
return &item, nil
}
func (r *ModelRepository) Delete(ctx context.Context, modelID string) (int64, error) {
res := r.db.WithContext(ctx).Delete(&model.ModelConfig{}, "id = ?", modelID)
return res.RowsAffected, res.Error
}