fix(platform): 公开既有账号文件容量上限 (#684)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d1dd25b666
commit
3750b8b39a
3 files changed
+58
No files matched your search
@@ -0,0 +1,55 @@
|
|||||||
|
package platform
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"infinite-canvas/backend/internal/model"
|
||||||
|
"infinite-canvas/backend/internal/repository"
|
||||||
|
|
||||||
|
"gorm.io/driver/sqlite"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPublicRuntimeLimitsStoredFileGB(t *testing.T) {
|
||||||
|
for _, configured := range []bool{false, true} {
|
||||||
|
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
sqlDB, err := db.DB()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Cleanup(func() { _ = sqlDB.Close() })
|
||||||
|
if err := db.AutoMigrate(&model.SystemSetting{}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
policy := DefaultRuntimePolicy()
|
||||||
|
if configured {
|
||||||
|
policy.Resource.StoredFileGB = 37
|
||||||
|
data, err := json.Marshal(policy)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := db.Create(&model.SystemSetting{Key: runtimePolicySettingKey, ValueJSON: string(data)}).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
limits, err := New(repository.New(db), nil, nil).PublicRuntimeLimits()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
data, err := json.Marshal(limits)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var fields map[string]any
|
||||||
|
if err := json.Unmarshal(data, &fields); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := fields["storedFileGB"]; got != float64(policy.Resource.StoredFileGB) {
|
||||||
|
t.Errorf("configured=%v: storedFileGB = %v, want %d; JSON=%s", configured, got, policy.Resource.StoredFileGB, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -137,6 +137,7 @@ type PublicRuntimePolicySetting struct {
|
|||||||
type PublicRuntimeLimits struct {
|
type PublicRuntimeLimits struct {
|
||||||
ActiveTaskLimit int `json:"activeTaskLimit"`
|
ActiveTaskLimit int `json:"activeTaskLimit"`
|
||||||
ResourceUploadMB int64 `json:"resourceUploadMB"`
|
ResourceUploadMB int64 `json:"resourceUploadMB"`
|
||||||
|
StoredFileGB int64 `json:"storedFileGB"`
|
||||||
RecycleBinRetentionDays int `json:"recycleBinRetentionDays"`
|
RecycleBinRetentionDays int `json:"recycleBinRetentionDays"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,6 +275,7 @@ func (s *Service) PublicRuntimeLimits() (*PublicRuntimeLimits, error) {
|
|||||||
}
|
}
|
||||||
return &PublicRuntimeLimits{
|
return &PublicRuntimeLimits{
|
||||||
ActiveTaskLimit: policy.Task.ActiveTaskLimit, ResourceUploadMB: policy.Resource.ResourceUploadMB,
|
ActiveTaskLimit: policy.Task.ActiveTaskLimit, ResourceUploadMB: policy.Resource.ResourceUploadMB,
|
||||||
|
StoredFileGB: policy.Resource.StoredFileGB,
|
||||||
RecycleBinRetentionDays: policy.Resource.RecycleBinRetentionDays,
|
RecycleBinRetentionDays: policy.Resource.RecycleBinRetentionDays,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ export type AuthSessionPayload = {
|
|||||||
export type RuntimeLimits = {
|
export type RuntimeLimits = {
|
||||||
activeTaskLimit: number;
|
activeTaskLimit: number;
|
||||||
resourceUploadMB: number;
|
resourceUploadMB: number;
|
||||||
|
storedFileGB: number;
|
||||||
recycleBinRetentionDays?: number;
|
recycleBinRetentionDays?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user