Skip to content

Commit

Permalink
implemented download disable / enable functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirari04 committed Nov 26, 2024
1 parent bb10dee commit 6f5bac6
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 1 deletion.
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ type Config struct {
PluginPgsServer string

StatsDriveName string `validate:"required,min=1,max=255"`

DownloadEnabled *bool
}

type PublicConfig struct {
Expand All @@ -90,6 +92,8 @@ type PublicConfig struct {
CaptchaType string
Captcha_Recaptcha_PublicKey string
Captcha_Hcaptcha_PublicKey string

DownloadEnabled bool
}

func (c Config) PublicConfig() PublicConfig {
Expand All @@ -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,
}
}

Expand Down
2 changes: 2 additions & 0 deletions configdb/configdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions controllers/DownloadVideoController.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions controllers/PlayerController.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -160,5 +166,6 @@ func PlayerController(c echo.Context) error {
"JWT": tkn,
"AppName": config.ENV.AppName,
"BaseUrl": config.ENV.BaseUrl,
"DownloadEnabled": downloadsEnabled,
})
}
1 change: 1 addition & 0 deletions controllers/UpdateSettingsController.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions models/Setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
11 changes: 10 additions & 1 deletion views/player.html
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
const HEIGHT = parseInt("{{ .Height }}");
const WIDTH = parseFloat("{{ .Width }}");
const RATIO = WIDTH / HEIGHT;
const DOWNLOAD_ENABLED = "{{ .DownloadEnabled }}";
</script>
<script>
Subtitles = Subtitles.filter((e) =>
Expand Down Expand Up @@ -317,13 +318,21 @@
{
name: "Download",
checkable: false,
items: [
items: DOWNLOAD_ENABLED === 'true' ? [
...Qualitys.map((Quality, i) => ({
name: `${Quality.label} - ${Quality.width}x${Quality.height}`,
click: () => {
downloadFile(Quality.url);
},
})),
] : [
{
name: "Downloads are disabled",
active: false,
click: () => {

},
},
],
},
];
Expand Down

0 comments on commit 6f5bac6

Please sign in to comment.