支持 S3 兼容对象存储 (#336)
* feat(storage): 支持 S3 对象存储 * fix(storage): 补齐 S3 对象文件后缀
This commit is contained in:
25 files changed
+1374
-88
No files matched your search
@@ -840,6 +840,61 @@ func (r *Repository) CreateUserOSSSetting(setting *model.UserOSSSetting) error {
|
||||
return r.db.Create(setting).Error
|
||||
}
|
||||
|
||||
func (r *Repository) StorageLocation(id string) (*model.StorageLocation, error) {
|
||||
var location model.StorageLocation
|
||||
if err := r.db.First(&location, "id = ?", id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &location, nil
|
||||
}
|
||||
|
||||
func (r *Repository) StorageLocationByDigest(scope string, ownerID string, provider string, digest string) (*model.StorageLocation, error) {
|
||||
var location model.StorageLocation
|
||||
if err := r.db.First(&location, "scope = ? AND owner_id = ? AND provider = ? AND location_digest = ?", scope, ownerID, provider, digest).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &location, nil
|
||||
}
|
||||
|
||||
func (r *Repository) StorageLocationHistoryCount(scope string, ownerID string) (int64, error) {
|
||||
var count int64
|
||||
err := r.db.Model(&model.StorageLocation{}).Where("scope = ? AND owner_id = ?", scope, ownerID).Count(&count).Error
|
||||
return count, err
|
||||
}
|
||||
|
||||
func (r *Repository) StorageLocationResourceCount(id string) (int64, error) {
|
||||
var count int64
|
||||
err := r.db.Model(&model.Resource{}).Where("storage_setting_id = ?", id).Count(&count).Error
|
||||
return count, err
|
||||
}
|
||||
|
||||
func (r *Repository) CreateStorageLocation(location *model.StorageLocation) error {
|
||||
return r.db.Create(location).Error
|
||||
}
|
||||
|
||||
func (r *Repository) SaveStorageLocation(location *model.StorageLocation) error {
|
||||
return r.db.Save(location).Error
|
||||
}
|
||||
|
||||
func (r *Repository) ActivateStorageLocation(scope string, ownerID string, id string, active bool) error {
|
||||
return r.db.Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Model(&model.StorageLocation{}).Where("scope = ? AND owner_id = ? AND active = ?", scope, ownerID, true).Update("active", false).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if !active {
|
||||
return nil
|
||||
}
|
||||
result := tx.Model(&model.StorageLocation{}).Where("id = ? AND scope = ? AND owner_id = ?", id, scope, ownerID).Update("active", true)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
if result.RowsAffected != 1 {
|
||||
return gorm.ErrRecordNotFound
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (r *Repository) ReserveDailyUpload(userID string, day string, size int64, limit int64) error {
|
||||
usage := model.UserDailyUploadUsage{ID: userID + ":" + day, UserID: userID, Day: day}
|
||||
return r.db.Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
Reference in new issue
Block a user