From 6f5bac62b33a344198824c562ee4b96dc6000a30 Mon Sep 17 00:00:00 2001 From: kirari04 Date: Tue, 26 Nov 2024 09:46:35 +0100 Subject: [PATCH] implemented download disable / enable functionality --- config/config.go | 6 ++++++ configdb/configdb.go | 2 ++ controllers/DownloadVideoController.go | 4 ++++ controllers/PlayerController.go | 7 +++++++ controllers/UpdateSettingsController.go | 1 + models/Setting.go | 2 ++ views/player.html | 11 ++++++++++- 7 files changed, 32 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 41e61c3..a26ad3e 100755 --- a/config/config.go +++ b/config/config.go @@ -71,6 +71,8 @@ type Config struct { PluginPgsServer string StatsDriveName string `validate:"required,min=1,max=255"` + + DownloadEnabled *bool } type PublicConfig struct { @@ -90,6 +92,8 @@ type PublicConfig struct { CaptchaType string Captcha_Recaptcha_PublicKey string Captcha_Hcaptcha_PublicKey string + + DownloadEnabled bool } func (c Config) PublicConfig() PublicConfig { @@ -110,6 +114,8 @@ func (c Config) PublicConfig() PublicConfig { CaptchaType: c.CaptchaType, Captcha_Recaptcha_PublicKey: c.Captcha_Recaptcha_PublicKey, Captcha_Hcaptcha_PublicKey: c.Captcha_Hcaptcha_PublicKey, + + DownloadEnabled: *c.DownloadEnabled, } } diff --git a/configdb/configdb.go b/configdb/configdb.go index 7976169..610affd 100644 --- a/configdb/configdb.go +++ b/configdb/configdb.go @@ -74,6 +74,8 @@ func Setup() { config.ENV.PluginPgsServer = getEnvDb(&setting.PluginPgsServer, "http://127.0.0.1:5000") + config.ENV.DownloadEnabled = getEnvDb_bool(&setting.DownloadEnabled, boolPtr(true)) + // validate config before saving validate := validator.New(validator.WithRequiredStructEnabled()) err := validate.Struct(&setting) diff --git a/controllers/DownloadVideoController.go b/controllers/DownloadVideoController.go index 4df4f9d..061a64d 100644 --- a/controllers/DownloadVideoController.go +++ b/controllers/DownloadVideoController.go @@ -36,6 +36,10 @@ func DownloadVideoController(c echo.Context) error { return c.String(http.StatusBadRequest, "bad quality format") } + if config.ENV.DownloadEnabled == nil || !*config.ENV.DownloadEnabled { + return c.String(http.StatusBadRequest, "download disabled") + } + //translate link id to file id var dbLink models.Link if dbRes := inits.DB. diff --git a/controllers/PlayerController.go b/controllers/PlayerController.go index 927c6b1..6cf3d46 100755 --- a/controllers/PlayerController.go +++ b/controllers/PlayerController.go @@ -139,6 +139,12 @@ func PlayerController(c echo.Context) error { // Domain: config.ENV.CookieDomain, // HTTPOnly: true, // }) + + var downloadsEnabled bool + if config.ENV.DownloadEnabled != nil { + downloadsEnabled = *config.ENV.DownloadEnabled + } + return c.Render(http.StatusOK, "player.html", echo.Map{ "Title": fmt.Sprintf("%s - %s", config.ENV.AppName, dbLink.Name), "Description": fmt.Sprintf("Watch %s on %s", dbLink.Name, config.ENV.AppName), @@ -160,5 +166,6 @@ func PlayerController(c echo.Context) error { "JWT": tkn, "AppName": config.ENV.AppName, "BaseUrl": config.ENV.BaseUrl, + "DownloadEnabled": downloadsEnabled, }) } diff --git a/controllers/UpdateSettingsController.go b/controllers/UpdateSettingsController.go index c9bdc9b..7a9d00c 100755 --- a/controllers/UpdateSettingsController.go +++ b/controllers/UpdateSettingsController.go @@ -70,6 +70,7 @@ func UpdateSettings(c echo.Context) error { setting.FFmpegVp9Crf = validation.FFmpegVp9Crf setting.FFmpegH264Crf = validation.FFmpegH264Crf setting.PluginPgsServer = validation.PluginPgsServer + setting.DownloadEnabled = validation.DownloadEnabled if res := inits.DB.Save(&setting); res.Error != nil { log.Fatalln("Failed to save settings", res.Error) return c.NoContent(http.StatusInternalServerError) diff --git a/models/Setting.go b/models/Setting.go index 3549407..52bbe39 100644 --- a/models/Setting.go +++ b/models/Setting.go @@ -63,4 +63,6 @@ type Setting struct { FFmpegH264Crf string `validate:"required,number,min=1,max=50"` PluginPgsServer string `validate:"required"` + + DownloadEnabled string `validate:"required,boolean"` } diff --git a/views/player.html b/views/player.html index fc9b713..c6e163a 100755 --- a/views/player.html +++ b/views/player.html @@ -242,6 +242,7 @@ const HEIGHT = parseInt("{{ .Height }}"); const WIDTH = parseFloat("{{ .Width }}"); const RATIO = WIDTH / HEIGHT; + const DOWNLOAD_ENABLED = "{{ .DownloadEnabled }}";