Skip to content

Commit

Permalink
add donation block to download
Browse files Browse the repository at this point in the history
  • Loading branch information
vintikzzz committed Nov 28, 2024
1 parent 27be5d9 commit 3d42df1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 45 deletions.
87 changes: 43 additions & 44 deletions serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ func serve(c *cli.Context) error {
return err
}

// Setting template renderer
re := multitemplate.NewRenderer()

// Setting Helper
helper := w.NewHelper(c)

// Setting Helper
umamiHelper := umami.NewHelper(c)

// Setting TemplateManager
tm := template.NewManager(re).
WithHelper(helper).
WithHelper(umamiHelper).
WithContextWrapper(w.NewContext)

var servers []cs.Servable
// Setting Probe
probe := cs.NewProbe(c)
Expand All @@ -91,10 +106,6 @@ func serve(c *cli.Context) error {
servers = append(servers, pprof)
defer pprof.Close()
}

// Setting template renderer
re := multitemplate.NewRenderer()

// Setting Gin
r := gin.Default()
r.HTMLRender = re
Expand All @@ -112,31 +123,45 @@ func serve(c *cli.Context) error {
return err
}

err = sta.RegisterHandler(c, r)
if err != nil {
return err
// Setting Auth
a := auth.New(c)

if a != nil {
err := a.Init()
if err != nil {
return err
}
a.RegisterHandler(r)
wau.RegisterHandler(r, tm)
}

// Setting Migration from v1 to v2
wm.RegisterHandler(r)
// Setting Claims Client
cpCl := claims.NewClient(c)
defer cpCl.Close()

// Setting UserClaims
uc := claims.New(c, cpCl)
if uc != nil {
// Setting UserClaimsHandler
uc.RegisterHandler(r)
}

// Setting HTTP Client
cl := http.DefaultClient

// Setting Api
sapi := api.New(c, cl)

// Setting Helper
helper := w.NewHelper(c)
// Setting ApiClaimsHandler
sapi.RegisterHandler(r)

// Setting Helper
umamiHelper := umami.NewHelper(c)
err = sta.RegisterHandler(c, r)
if err != nil {
return err
}

// Setting TemplateManager
tm := template.NewManager(re).
WithHelper(helper).
WithHelper(umamiHelper).
WithContextWrapper(w.NewContext)
// Setting Migration from v1 to v2
wm.RegisterHandler(r)

// Setting Redis
redis := cs.NewRedisClient(c)
Expand All @@ -150,18 +175,6 @@ func serve(c *cli.Context) error {

jobs.RegisterHandler(r)

// Setting Auth
a := auth.New(c)

if a != nil {
err := a.Init()
if err != nil {
return err
}
a.RegisterHandler(r)
wau.RegisterHandler(r, tm)
}

// Setting AbuseStore
asc := as.New(c)

Expand All @@ -174,23 +187,9 @@ func serve(c *cli.Context) error {
legal.RegisterHandler(r, tm)
}

// Setting Claims Client
cpCl := claims.NewClient(c)
defer cpCl.Close()

// Setting UserClaims
uc := claims.New(c, cpCl)
if uc != nil {
// Setting UserClaimsHandler
uc.RegisterHandler(r)
}

// Setting DomainSettings
ds := embed.NewDomainSettings(pg, uc)

// Setting ApiClaimsHandler
sapi.RegisterHandler(r)

// Setting ResourceHandler
wr.RegisterHandler(r, tm, sapi, jobs)

Expand Down
13 changes: 12 additions & 1 deletion templates/views/action/download_file.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@
var file = new URL(url).pathname.split('/').pop();
var wgetCmd = `wget -c -O "${file}" -t 20 "${url}"`;
</script>
<div class="pt-3 sm:text-right ml-3">
{{- if .Claims | hasAds }}
<pre class="warn-summary"><span>Your current download speed will be limited to {{ .Claims.Claims.Connection.Rate }}Mbps, <a href="/donate" class="link" target="_blank">donate</a> to increase your speed and remove ads!</span></pre>
{{- end }}
<div class="pt-3 ml-3 flex flex-wrap justify-end">
{{- if .Claims | hasAds }}
<a class="btn btn-sm btn-accent btn-outline m-2 uppercase flex-grow" href="/donate" target="_blank">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"></path>
</svg>
donate
</a>
{{- end }}
<a class="btn btn-sm btn-accent m-2 closeable-close" onclick="navigator.clipboard.writeText(wgetCmd)">copy wget cmd</a>
<a class="btn btn-sm btn-accent m-2 closeable-close" onclick="navigator.clipboard.writeText(url)">copy url</a>
<a class="btn btn-sm btn-accent m-2 closeable-close" download href="{{ .Data.URL }}">start download</a>
Expand Down

0 comments on commit 3d42df1

Please sign in to comment.