hide some information for visible but unreleased releases
Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
parent
10f19d46db
commit
7914fba52a
|
@ -18,6 +18,14 @@ type (
|
|||
const TOKEN_LENGTH = 64
|
||||
const TOKEN_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
var ADMIN_BYPASS = func() bool {
|
||||
if os.Getenv("ARIMELODY_ADMIN_BYPASS") == "true" {
|
||||
fmt.Println("WARNING: Admin login is currently BYPASSED by ARIMELODY_ADMIN_BYPASS.")
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}()
|
||||
|
||||
var ADMIN_ID_DISCORD = func() string {
|
||||
envvar := os.Getenv("DISCORD_ADMIN_ID")
|
||||
if envvar == "" {
|
||||
|
|
|
@ -85,9 +85,9 @@ func MustAuthorise(next http.Handler) http.Handler {
|
|||
}
|
||||
|
||||
func GetSession(r *http.Request) *Session {
|
||||
if os.Getenv("ARIMELODY_ADMIN_BYPASS") == "true" {
|
||||
return &Session{}
|
||||
}
|
||||
// if ADMIN_BYPASS {
|
||||
// return &Session{}
|
||||
// }
|
||||
|
||||
var token = ""
|
||||
// is the session token in context?
|
||||
|
|
|
@ -24,10 +24,11 @@ type (
|
|||
)
|
||||
|
||||
const (
|
||||
Single ReleaseType = "Single"
|
||||
Album ReleaseType = "Album"
|
||||
Single ReleaseType = "single"
|
||||
Album ReleaseType = "album"
|
||||
EP ReleaseType = "EP"
|
||||
Compilation ReleaseType = "Compilation"
|
||||
Compilation ReleaseType = "compilation"
|
||||
Upcoming ReleaseType = "upcoming"
|
||||
)
|
||||
|
||||
// GETTERS
|
||||
|
|
|
@ -3,7 +3,6 @@ package view
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"arimelody.me/arimelody.me/admin"
|
||||
"arimelody.me/arimelody.me/global"
|
||||
"arimelody.me/arimelody.me/music/model"
|
||||
)
|
||||
|
@ -26,13 +25,15 @@ func Handler() http.Handler {
|
|||
|
||||
func ServeCatalog() http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
releases := []*model.Release{}
|
||||
authorised := admin.GetSession(r) != nil
|
||||
for _, release := range global.Releases {
|
||||
if !release.IsReleased() && !authorised {
|
||||
continue
|
||||
releases := []model.Release{}
|
||||
for _, r := range global.Releases {
|
||||
if r.Visible {
|
||||
release := *r
|
||||
if !release.IsReleased() {
|
||||
release.ReleaseType = model.Upcoming
|
||||
}
|
||||
releases = append(releases, release)
|
||||
}
|
||||
releases = append(releases, release)
|
||||
}
|
||||
|
||||
global.ServeTemplate("music.html", releases).ServeHTTP(w, r)
|
||||
|
|
|
@ -21,7 +21,8 @@ type (
|
|||
|
||||
gatewayRelease struct {
|
||||
*model.Release
|
||||
Tracks []gatewayTrack
|
||||
Tracks []gatewayTrack
|
||||
Authorised bool
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -35,18 +36,23 @@ func ServeRelease() http.Handler {
|
|||
}
|
||||
|
||||
releaseID := r.URL.Path[1:]
|
||||
var release = global.GetRelease(releaseID)
|
||||
if release == nil {
|
||||
var releaseRef = global.GetRelease(releaseID)
|
||||
if releaseRef == nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
var release = *releaseRef
|
||||
|
||||
// only allow authorised users to view unreleased releases
|
||||
authorised := admin.GetSession(r) != nil
|
||||
if !release.IsReleased() && !authorised {
|
||||
admin.MustAuthorise(ServeRelease()).ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
// only allow authorised users to view hidden releases
|
||||
authorised := admin.GetSession(r) != nil
|
||||
if !authorised && !release.Visible {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if !authorised && !release.IsReleased() {
|
||||
release.Tracks = nil
|
||||
release.Credits = nil
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
err := json.NewEncoder(w).Encode(release)
|
||||
|
@ -71,6 +77,13 @@ func ServeGateway() http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
// only allow authorised users to view hidden releases
|
||||
authorised := admin.GetSession(r) != nil
|
||||
if !release.Visible && !authorised {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
tracks := []gatewayTrack{}
|
||||
for i, track := range release.Tracks {
|
||||
tracks = append([]gatewayTrack{{
|
||||
|
@ -80,16 +93,9 @@ func ServeGateway() http.Handler {
|
|||
}}, tracks...)
|
||||
}
|
||||
|
||||
// only allow authorised users to view unreleased releases
|
||||
authorised := admin.GetSession(r) != nil
|
||||
if !release.IsReleased() && !authorised {
|
||||
admin.MustAuthorise(ServeGateway()).ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
lrw := global.LoggingResponseWriter{ResponseWriter: w, Code: http.StatusOK}
|
||||
|
||||
global.ServeTemplate("music-gateway.html", gatewayRelease{release, tracks}).ServeHTTP(&lrw, r)
|
||||
global.ServeTemplate("music-gateway.html", gatewayRelease{release, tracks, authorised}).ServeHTTP(&lrw, r)
|
||||
|
||||
if lrw.Code != http.StatusOK {
|
||||
fmt.Printf("Error rendering music gateway for %s\n", id)
|
||||
|
|
|
@ -57,7 +57,11 @@
|
|||
<span id="year" title="{{.PrintReleaseDate}}">{{.GetReleaseYear}}</span>
|
||||
</div>
|
||||
<p id="artist">{{.PrintArtists true true}}</p>
|
||||
{{if .IsReleased}}
|
||||
<p id="type" class="{{.ReleaseType}}">{{.ReleaseType}}</p>
|
||||
{{else}}
|
||||
<p id="type" class="upcoming">upcoming</p>
|
||||
{{end}}
|
||||
|
||||
<ul id="links">
|
||||
{{if .Buylink}}
|
||||
|
@ -82,6 +86,8 @@
|
|||
<button id="share">share</button>
|
||||
</div>
|
||||
|
||||
{{if .IsReleased}}
|
||||
|
||||
{{if .Credits}}
|
||||
<div id="credits">
|
||||
<h2>credits:</h2>
|
||||
|
@ -121,12 +127,14 @@
|
|||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
{{if .IsReleased}}
|
||||
<div id="extras">
|
||||
<ul>
|
||||
<li><a href="#overview">overview</a></li>
|
||||
|
||||
{{if .Credits}}
|
||||
<li><a href="#credits">credits</a></li>
|
||||
{{end}}
|
||||
|
@ -141,30 +149,7 @@
|
|||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
<!-- <div id="tracks"> -->
|
||||
<!-- <% var file = `/audio/preview/${data.id}.webm` %> -->
|
||||
<!-- <% if (data.tracks && typeof(data.tracks) == typeof([])) { %> -->
|
||||
<!-- <% for( let i = 0; i < data.tracks.length; i++ ) { %> -->
|
||||
<!-- <% -->
|
||||
<!-- songid = data.tracks[i].title.toLowerCase().replace(/[^a-z0-9]/g, ""); -->
|
||||
<!-- file = `/audio/preview/${data.id}-${songid}.webm`; -->
|
||||
<!-- %> -->
|
||||
<!---->
|
||||
<!-- <div class="track-preview" id="preview-<%= songid %>"> -->
|
||||
<!-- <i class="fa-solid fa-play play"></i> -->
|
||||
<!-- <p><%= data.tracks[i].title %></p> -->
|
||||
<!-- <audio src="<%= file %>"></audio> -->
|
||||
<!-- </div> -->
|
||||
<!---->
|
||||
<!-- <% } %> -->
|
||||
<!-- <% } else { %> -->
|
||||
<!-- <div class="track-preview" id="preview-<%= data.id %>"> -->
|
||||
<!-- <i class="fa-solid fa-play play"></i> -->
|
||||
<!-- <p>{{.Title}}</p> -->
|
||||
<!-- <audio src="<%= file %>"></audio> -->
|
||||
<!-- </div> -->
|
||||
<!-- <% } %> -->
|
||||
<!-- </div> -->
|
||||
{{end}}
|
||||
</div>
|
||||
</main>
|
||||
{{end}}
|
||||
|
|
Loading…
Reference in a new issue