2026-04-30 11:05:56 +03:00
package config
var Definitions = [ ] SettingDefinition {
{ Key : SettingDataDir , EnvName : "WARPBOX_DATA_DIR" , Label : "Data directory" , Type : SettingTypeText , Editable : false , HardLimit : true } ,
{ Key : SettingGuestUploadsEnabled , EnvName : "WARPBOX_GUEST_UPLOADS_ENABLED" , Label : "Guest uploads enabled" , Type : SettingTypeBool , Editable : true } ,
{ Key : SettingAPIEnabled , EnvName : "WARPBOX_API_ENABLED" , Label : "API enabled" , Type : SettingTypeBool , Editable : true } ,
{ Key : SettingZipDownloadsEnabled , EnvName : "WARPBOX_ZIP_DOWNLOADS_ENABLED" , Label : "ZIP downloads enabled" , Type : SettingTypeBool , Editable : true } ,
{ Key : SettingOneTimeDownloadsEnabled , EnvName : "WARPBOX_ONE_TIME_DOWNLOADS_ENABLED" , Label : "One-time downloads enabled" , Type : SettingTypeBool , Editable : true } ,
{ Key : SettingOneTimeDownloadExpirySecs , EnvName : "WARPBOX_ONE_TIME_DOWNLOAD_EXPIRY_SECONDS" , Label : "One-time download expiry seconds" , Type : SettingTypeInt64 , Editable : true , Minimum : 0 } ,
{ Key : SettingOneTimeDownloadRetryFail , EnvName : "WARPBOX_ONE_TIME_DOWNLOAD_RETRY_ON_FAILURE" , Label : "One-time download retry on failure" , Type : SettingTypeBool , Editable : false } ,
{ Key : SettingRenewOnAccessEnabled , EnvName : "WARPBOX_RENEW_ON_ACCESS_ENABLED" , Label : "Renew on access enabled" , Type : SettingTypeBool , Editable : true } ,
{ Key : SettingRenewOnDownloadEnabled , EnvName : "WARPBOX_RENEW_ON_DOWNLOAD_ENABLED" , Label : "Renew on download enabled" , Type : SettingTypeBool , Editable : true } ,
{ Key : SettingDefaultGuestExpirySecs , EnvName : "WARPBOX_DEFAULT_GUEST_EXPIRY_SECONDS" , Label : "Default guest expiry seconds" , Type : SettingTypeInt64 , Editable : true , Minimum : 0 } ,
{ Key : SettingMaxGuestExpirySecs , EnvName : "WARPBOX_MAX_GUEST_EXPIRY_SECONDS" , Label : "Max guest expiry seconds" , Type : SettingTypeInt64 , Editable : true , Minimum : 0 } ,
2026-05-01 02:14:05 +03:00
{ Key : SettingGlobalMaxFileSizeBytes , EnvName : "WARPBOX_GLOBAL_MAX_FILE_SIZE_GB" , Label : "Global max file size GB" , Type : SettingTypeSizeGB , Editable : true , Minimum : 0 } ,
{ Key : SettingGlobalMaxBoxSizeBytes , EnvName : "WARPBOX_GLOBAL_MAX_BOX_SIZE_GB" , Label : "Global max box size GB" , Type : SettingTypeSizeGB , Editable : true , Minimum : 0 } ,
{ Key : SettingDefaultUserMaxFileBytes , EnvName : "WARPBOX_DEFAULT_USER_MAX_FILE_SIZE_GB" , Label : "Default user max file size GB" , Type : SettingTypeSizeGB , Editable : true , Minimum : 0 } ,
{ Key : SettingDefaultUserMaxBoxBytes , EnvName : "WARPBOX_DEFAULT_USER_MAX_BOX_SIZE_GB" , Label : "Default user max box size GB" , Type : SettingTypeSizeGB , Editable : true , Minimum : 0 } ,
2026-04-30 11:05:56 +03:00
{ Key : SettingSessionTTLSeconds , EnvName : "WARPBOX_SESSION_TTL_SECONDS" , Label : "Session TTL seconds" , Type : SettingTypeInt64 , Editable : true , Minimum : 60 } ,
{ Key : SettingBoxPollIntervalMS , EnvName : "WARPBOX_BOX_POLL_INTERVAL_MS" , Label : "Box poll interval milliseconds" , Type : SettingTypeInt , Editable : true , Minimum : 1000 } ,
{ Key : SettingThumbnailBatchSize , EnvName : "WARPBOX_THUMBNAIL_BATCH_SIZE" , Label : "Thumbnail batch size" , Type : SettingTypeInt , Editable : true , Minimum : 1 } ,
{ Key : SettingThumbnailIntervalSeconds , EnvName : "WARPBOX_THUMBNAIL_INTERVAL_SECONDS" , Label : "Thumbnail interval seconds" , Type : SettingTypeInt , Editable : true , Minimum : 1 } ,
}
func ( cfg * Config ) SettingRows ( ) [ ] SettingRow {
rows := make ( [ ] SettingRow , 0 , len ( Definitions ) )
for _ , def := range Definitions {
rows = append ( rows , SettingRow {
Definition : def ,
Value : cfg . values [ def . Key ] ,
Source : cfg . sourceFor ( def . Key ) ,
} )
}
return rows
}
func ( cfg * Config ) Source ( key string ) Source {
return cfg . sourceFor ( key )
}
func ( cfg * Config ) AdminLoginEnabled ( hasAdminUser bool ) bool {
switch cfg . AdminEnabled {
case AdminEnabledFalse :
return false
case AdminEnabledTrue :
return hasAdminUser
default :
return hasAdminUser
}
}
func Definition ( key string ) ( SettingDefinition , bool ) {
2026-05-01 02:14:05 +03:00
key = NormalizeLegacySettingKey ( key )
2026-04-30 11:05:56 +03:00
for _ , def := range Definitions {
if def . Key == key {
return def , true
}
}
return SettingDefinition { } , false
}
2026-05-01 02:14:05 +03:00
func NormalizeLegacySettingKey ( key string ) string {
switch key {
case "global_max_file_size_bytes" :
return SettingGlobalMaxFileSizeBytes
case "global_max_box_size_bytes" :
return SettingGlobalMaxBoxSizeBytes
case "default_user_max_file_size_bytes" :
return SettingDefaultUserMaxFileBytes
case "default_user_max_box_size_bytes" :
return SettingDefaultUserMaxBoxBytes
default :
return key
}
}
func NormalizeOverrideInput ( key string , value string ) ( string , string , error ) {
normalizedKey := NormalizeLegacySettingKey ( key )
switch key {
case "global_max_file_size_bytes" , "global_max_box_size_bytes" , "default_user_max_file_size_bytes" , "default_user_max_box_size_bytes" :
parsed , err := parseInt64 ( value , 0 )
if err != nil {
return normalizedKey , "" , err
}
return normalizedKey , formatGigabytesFromBytes ( parsed ) , nil
default :
return normalizedKey , value , nil
}
}
2026-04-30 11:05:56 +03:00
func EditableDefinitions ( ) [ ] SettingDefinition {
defs := make ( [ ] SettingDefinition , 0 , len ( Definitions ) )
for _ , def := range Definitions {
if def . Editable && ! def . HardLimit {
defs = append ( defs , def )
}
}
return defs
}