Skip to content

Commit

Permalink
Ads and statistic integration support
Browse files Browse the repository at this point in the history
  • Loading branch information
vintikzzz committed Apr 23, 2024
1 parent 9af7d47 commit 5e7f13e
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ node_modules

assets/dist/*

.env
.env

templates/partials/extend.html
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Some features to mention:
- [x] Authentication
- [x] Passwordless authentication
- [x] Patreon account linking
- [ ] Ads integration
- [x] Ads and statistic integration support
- [ ] Feedback form
- [ ] Chrome extension integration
- [ ] Embed support
- [ ] 🚀Switch webtor.io to web-ui-v2

Expand Down
7 changes: 7 additions & 0 deletions services/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var SHA1R = regexp.MustCompile("(?i)[0-9a-f]{5,40}")

var (
DomainFlag = "domain"
DemoMagnetFlag = "demo-magnet"
SMTPHostFlag = "smtp-host"
SMTPUserFlag = "smtp-user"
SMTPPassFlag = "smtp-pass"
Expand All @@ -28,6 +29,12 @@ func RegisterFlags(f []cli.Flag) []cli.Flag {
Value: "http://localhost:8080",
EnvVar: "DOMAIN",
},
cli.StringFlag{
Name: DemoMagnetFlag,
Usage: "demo magnet",
Value: "magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.fastcast.nz&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F",
EnvVar: "DEMO_MAGNET",
},
cli.StringFlag{
Name: SMTPHostFlag,
Usage: "smtp host",
Expand Down
8 changes: 8 additions & 0 deletions services/web/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,17 @@ func (s *Helper) GetFuncs() template.FuncMap {
"useAuth": s.UseAuth,
"domain": s.Domain,
"has": Has,
"hasAds": HasAds,
}
}

func HasAds(c *claims.Data) bool {
if c == nil {
return false
}
return !c.Claims.Site.NoAds
}

func (s *Helper) UseAuth() bool {
return s.useAuth
}
Expand Down
11 changes: 9 additions & 2 deletions services/web/index/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,31 @@ import (

"github.com/gin-gonic/gin"
"github.com/urfave/cli"
"github.com/webtor-io/web-ui-v2/services"
"github.com/webtor-io/web-ui-v2/services/template"
)

type IndexData struct{}
type IndexData struct {
DemoMagnet string
}

type Handler struct {
tm *template.Manager
dm string
}

func RegisterHandler(c *cli.Context, r *gin.Engine, tm *template.Manager) {
h := &Handler{
tm: tm,
dm: c.String(services.DemoMagnetFlag),
}
r.GET("/", h.index)

h.tm.RegisterViews("*")
}

func (s *Handler) index(c *gin.Context) {
s.tm.MakeTemplate("index").HTML(http.StatusOK, c, &IndexData{})
s.tm.MakeTemplate("index").HTML(http.StatusOK, c, &IndexData{
DemoMagnet: s.dm,
})
}
4 changes: 4 additions & 0 deletions services/web/resource/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resource
import (
"github.com/gin-gonic/gin"
"github.com/urfave/cli"
"github.com/webtor-io/web-ui-v2/services"
"github.com/webtor-io/web-ui-v2/services/api"
"github.com/webtor-io/web-ui-v2/services/template"
j "github.com/webtor-io/web-ui-v2/services/web/job"
Expand All @@ -12,13 +13,15 @@ type Handler struct {
api *api.Api
jobs *j.Handler
tm *template.Manager
dm string
}

func RegisterHandler(c *cli.Context, r *gin.Engine, tm *template.Manager, api *api.Api, jobs *j.Handler) {
h := &Handler{
api: api,
jobs: jobs,
tm: tm,
dm: c.String(services.DemoMagnetFlag),
}
r.POST("/", h.post)
r.GET("/:resource_id", h.get)
Expand All @@ -33,5 +36,6 @@ func RegisterHandler(c *cli.Context, r *gin.Engine, tm *template.Manager, api *a
"makeImage": MakeImage,
"makeAudio": MakeAudio,
"makeVideo": MakeVideo,
"isDemoMagnet": h.IsDemoMagnet,
})
}
4 changes: 4 additions & 0 deletions services/web/resource/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,7 @@ func MakePagination(lr *ra.ListResponse, page uint, pageSize uint) []Pagination
})
return res
}

func (s *Handler) IsDemoMagnet(m string) bool {
return s.dm == m
}
2 changes: 1 addition & 1 deletion templates/layouts/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<script>window._sessionExpired = {{ .User.Expired }};</script>
<script async src="{{ "auth.js" | asset }}"></script>
{{- end }}
{{- template "head" . }}
{{- template "head_extra" . }}
</head>
<body style="background-color: rgb(15, 23, 42);">
<script>document.body.style.display = 'none';</script>
Expand Down
2 changes: 0 additions & 2 deletions templates/partials/extend.html

This file was deleted.

4 changes: 4 additions & 0 deletions templates/partials/extend_base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ define "head_extra" }}
{{ end }}
{{ define "get_extra" }}
{{ end }}
2 changes: 1 addition & 1 deletion templates/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</form>
<div class="divider h-12">OR</div>
<form class="flex flex-col justify-center items-center" action="/" method="post" enctype="multipart/form-data" async-target="main">
<input type="hidden" name="resource" value="magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.fastcast.nz&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F" />
<input type="hidden" name="resource" value="{{ .DemoMagnet }}" />
<button type="submit" class="btn btn-accent btn-outline">Try demo!</button>
</form>
{{ end }}
Expand Down
1 change: 1 addition & 0 deletions templates/views/resource/get.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
{{ end }}
<script async src="{{ "resource/get.js" | asset }}"></script>
{{ if dev }}<script async src="{{ "resource/get.js" | devAsset }}"></script>{{ end }}
{{ template "get_extra" . }}
{{ end }}

0 comments on commit 5e7f13e

Please sign in to comment.