From 92c42fe250412ee3ed0c5dfd0ac44099f140d601 Mon Sep 17 00:00:00 2001 From: Marc Ole Bulling Date: Sat, 19 Apr 2025 22:06:20 +0200 Subject: [PATCH] Make GOKAPI_LENGTH_ID non-permanent, add GOKAPI_LENGTH_HOTLINK_ID to change hotlink ID length #251 --- custom/custom.css | 1 + docs/advanced.rst | 4 +++- internal/configuration/Configuration.go | 2 ++ internal/environment/Environment.go | 4 ++++ internal/models/Configuration.go | 3 ++- internal/storage/FileServing.go | 2 +- 6 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 custom/custom.css diff --git a/custom/custom.css b/custom/custom.css new file mode 100644 index 0000000..62c2bba --- /dev/null +++ b/custom/custom.css @@ -0,0 +1 @@ +hellooooo! diff --git a/docs/advanced.rst b/docs/advanced.rst index a3c8115..d6457e6 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -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) | +-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+ diff --git a/internal/configuration/Configuration.go b/internal/configuration/Configuration.go index 4abfacf..c2219ff 100644 --- a/internal/configuration/Configuration.go +++ b/internal/configuration/Configuration.go @@ -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) diff --git a/internal/environment/Environment.go b/internal/environment/Environment.go index 1f23422..47f110b 100644 --- a/internal/environment/Environment.go +++ b/internal/environment/Environment.go @@ -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 } diff --git a/internal/models/Configuration.go b/internal/models/Configuration.go index fafb20e..4cc618e 100644 --- a/internal/models/Configuration.go +++ b/internal/models/Configuration.go @@ -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"` diff --git a/internal/storage/FileServing.go b/internal/storage/FileServing.go index f1bbb0d..f5bb5b1 100644 --- a/internal/storage/FileServing.go +++ b/internal/storage/FileServing.go @@ -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) }