fix(sub): randomize fresh panel subscription paths (#6375)

* fix(sub): randomize fresh panel subscription paths

Seed distinct cryptographically random paths for base64, JSON, and Clash subscriptions when a panel database is first created. Persist them so restarts keep published URLs stable while upgrades preserve existing settings.

Generated-by: OpenCode:gpt-5.6-sol

* fix(sub): regenerate paths on settings reset

Keep subscription paths unpredictable after a factory reset, close the test database on failure, and update the builder, OpenAPI, and localized docs to describe panel-specific paths instead of obsolete fixed defaults.

Generated-by: OpenCode:gpt-5.6-sol
This commit is contained in:
ilyusha
2026-09-03 17:34:37 +03:00
committed by GitHub
parent ded2aa150c
commit f9898e0b24
20 changed files with 285 additions and 158 deletions
+11 -6
View File
@@ -309,12 +309,17 @@ func getEnv(key, fallback string) string {
func (s *SettingService) ResetSettings() error {
db := database.GetDB()
err := db.Where("1 = 1").Delete(model.Setting{}).Error
if err != nil {
return err
}
return db.Model(model.User{}).
Where("1 = 1").Error
return db.Transaction(func(tx *gorm.DB) error {
if err := tx.Where("1 = 1").Delete(model.Setting{}).Error; err != nil {
return err
}
paths := []model.Setting{
{Key: "subPath", Value: "/" + random.NumLower(16) + "/"},
{Key: "subJsonPath", Value: "/" + random.NumLower(16) + "/"},
{Key: "subClashPath", Value: "/" + random.NumLower(16) + "/"},
}
return tx.Create(&paths).Error
})
}
func (s *SettingService) getSetting(key string) (*model.Setting, error) {