Make GOKAPI_LENGTH_ID non-permanent, add GOKAPI_LENGTH_HOTLINK_ID to change hotlink ID length #251

This commit is contained in:
Marc Ole Bulling
2025-04-19 22:06:20 +02:00
parent d82303f96f
commit 92c42fe250
6 changed files with 13 additions and 3 deletions

1
custom/custom.css Normal file
View File

@@ -0,0 +1 @@
hellooooo!

View File

@@ -70,7 +70,9 @@ Available environment variables
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_DATABASE_URL | Sets the type and location of the database. See :ref:`Databases` | Yes | sqlite://[data folder]/gokapi.sqlite |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_LENGTH_ID | Sets the length of the download IDs. Value needs to be 5 or more | Yes | 15 |
| GOKAPI_LENGTH_ID | Sets the length of the download IDs. Value needs to be 5 or more | No | 15 |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_LENGTH_HOTLINK_ID | Sets the length of the hotlink IDs. Value needs to be 8 or more | No | 40 |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_MAX_FILESIZE | Sets the maximum allowed file size in MB | Yes | 102400 (100GB) |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+

View File

@@ -91,6 +91,8 @@ func Load() {
if serverSettings.ChunkSize == 0 {
serverSettings.ChunkSize = 45
}
serverSettings.LengthId = Environment.LengthId
serverSettings.LengthHotlinkId = Environment.LengthHotlinkId
helper.CreateDir(serverSettings.DataDir)
filesystem.Init(serverSettings.DataDir)
logging.Init(Environment.DataDir)

View File

@@ -22,6 +22,7 @@ type Environment struct {
DataDir string `env:"DATA_DIR" envDefault:"data"`
DatabaseUrl string `env:"DATABASE_URL" envDefault:"sqlite://[data]/gokapi.sqlite"`
LengthId int `env:"LENGTH_ID" envDefault:"15"`
LengthHotlinkId int `env:"LENGTH_HOTLINK_ID" envDefault:"40"`
MaxFileSize int `env:"MAX_FILESIZE" envDefault:"102400"` // 102400==100GB
MaxMemory int `env:"MAX_MEMORY_UPLOAD" envDefault:"50"`
MaxParallelUploads int `env:"MAX_PARALLEL_UPLOADS" envDefault:"4"`
@@ -74,6 +75,9 @@ func New() Environment {
if result.LengthId < 5 {
result.LengthId = 5
}
if result.LengthHotlinkId < 8 {
result.LengthHotlinkId = 8
}
if result.MaxMemory < 5 {
result.MaxMemory = 5
}

View File

@@ -15,11 +15,12 @@ type Configuration struct {
DataDir string `json:"DataDir"`
DatabaseUrl string `json:"DatabaseUrl"`
ConfigVersion int `json:"ConfigVersion"`
LengthId int `json:"LengthId"`
MaxFileSizeMB int `json:"MaxFileSizeMB"`
MaxMemory int `json:"MaxMemory"`
ChunkSize int `json:"ChunkSize"`
MaxParallelUploads int `json:"MaxParallelUploads"`
LengthId int `json:"-"`
LengthHotlinkId int `json:"-"`
Encryption Encryption `json:"Encryption"`
UseSsl bool `json:"UseSsl"`
PicturesAlwaysLocal bool `json:"PicturesAlwaysLocal"`

View File

@@ -519,7 +519,7 @@ func AddHotlink(file *models.File) {
if !IsAbleHotlink(*file) {
return
}
link := helper.GenerateRandomString(40) + getFileExtension(file.Name)
link := helper.GenerateRandomString(configuration.Get().LengthHotlinkId) + getFileExtension(file.Name)
file.HotlinkId = link
database.SaveHotlink(*file)
}