args over envars, some music gateway fixes

This commit is contained in:
ari melody 2024-08-31 02:56:06 +01:00
parent ec3ccec73c
commit 99b6a21179
Signed by: ari
GPG key ID: CF99829C92678188
7 changed files with 63 additions and 41 deletions

View file

@ -3,8 +3,9 @@ package admin
import (
"fmt"
"math/rand"
"os"
"time"
"arimelody.me/arimelody.me/global"
)
type (
@ -19,19 +20,19 @@ 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.")
if global.Args["adminBypass"] == "true" {
fmt.Println("WARN: Admin login is currently BYPASSED. (-adminBypass)")
return true
}
return false
}()
var ADMIN_ID_DISCORD = func() string {
envvar := os.Getenv("DISCORD_ADMIN_ID")
if envvar == "" {
fmt.Printf("DISCORD_ADMIN_ID was not provided. Admin login will be unavailable.\n")
id := global.Args["discordAdmin"]
if id == "" {
fmt.Printf("WARN: Discord admin ID (-discordAdmin) was not provided. Admin login will be unavailable.\n")
}
return envvar
return id
}()
var sessions []*Session

View file

@ -6,45 +6,32 @@ import (
"fmt"
"net/http"
"net/url"
"os"
"strings"
"arimelody.me/arimelody.me/global"
)
const API_ENDPOINT = "https://discord.com/api/v10"
var CREDENTIALS_PROVIDED = true
var CLIENT_ID = func() string {
envvar := os.Getenv("DISCORD_CLIENT_ID")
if envvar == "" {
fmt.Printf("DISCORD_CLIENT_ID was not provided. Admin login will be unavailable.\n")
id := global.Args["discordClient"]
if id == "" {
fmt.Printf("WARN: Discord client ID (-discordClient) was not provided. Admin login will be unavailable.\n")
CREDENTIALS_PROVIDED = false
}
return envvar
return id
}()
var CLIENT_SECRET = func() string {
envvar := os.Getenv("DISCORD_CLIENT_SECRET")
if envvar == "" {
fmt.Printf("DISCORD_CLIENT_SECRET was not provided. Admin login will be unavailable.\n")
secret := global.Args["discordSecret"]
if secret== "" {
fmt.Printf("WARN: Discord secret (-discordSecret) was not provided. Admin login will be unavailable.\n")
CREDENTIALS_PROVIDED = false
}
return envvar
}()
var REDIRECT_URI = func() string {
envvar := os.Getenv("DISCORD_REDIRECT_URI")
if envvar == "" {
fmt.Printf("DISCORD_REDIRECT_URI was not provided. Admin login will be unavailable.\n")
CREDENTIALS_PROVIDED = false
}
return envvar
}()
var OAUTH_CALLBACK_URI = func() string {
envvar := os.Getenv("OAUTH_CALLBACK_URI")
if envvar == "" {
fmt.Printf("OAUTH_CALLBACK_URI was not provided. Admin login will be unavailable.\n")
CREDENTIALS_PROVIDED = false
}
return envvar
return secret
}()
var OAUTH_CALLBACK_URI = fmt.Sprintf("%s/admin/login", global.HTTP_DOMAIN)
var REDIRECT_URI = fmt.Sprintf("https://discord.com/oauth2/authorize?client_id=%s&response_type=code&redirect_uri=%s&scope=identify", CLIENT_ID, OAUTH_CALLBACK_URI)
type (
AccessTokenResponse struct {

View file

@ -1,19 +1,48 @@
package global
import (
"fmt"
"os"
"strings"
"arimelody.me/arimelody.me/music/model"
"github.com/jmoiron/sqlx"
)
var Args = func() map[string]string {
args := map[string]string{}
index := 0
for index < len(os.Args[1:]) {
arg := os.Args[index + 1]
if !strings.HasPrefix(arg, "-") {
fmt.Printf("FATAL: Parameters must follow an argument (%s).\n", arg)
os.Exit(1)
}
if index + 3 > len(os.Args) || strings.HasPrefix(os.Args[index + 2], "-") {
args[arg[1:]] = "true"
index += 1
continue
}
val := os.Args[index + 2]
args[arg[1:]] = val
// fmt.Printf("%s: %s\n", arg[1:], val)
index += 2
}
return args
}()
var HTTP_DOMAIN = func() string {
envvar := os.Getenv("HTTP_DOMAIN")
if envvar != "" {
return envvar
}
return "https://arimelody.me"
}
}()
var DB *sqlx.DB

View file

@ -70,4 +70,5 @@ function bind_share_btn() {
bind_share_btn();
bind_go_back_btn();
apply_funny_bob_to_upcoming_tags();
if (document.getElementById("extras"))
update_extras_buttons();

View file

@ -108,14 +108,20 @@
{{end}}
{{if .IsSingle}}
{{$Track := index .Tracks 0}}
{{if $Track.Lyrics}}
<div id="lyrics">
<h2>lyrics:</h2>
<p>{{$Track.Lyrics}}</p>
<p class="album-track-subheading">LYRICS</p>
{{if $Track.Lyrics}}
{{$Track.Lyrics}}
{{else}}
<span class="empty">No lyrics.</span>
{{end}}
</div>
{{end}}
{{else}}
{{else if .Tracks}}
<div id="tracks">
<h2>tracks:</h2>
{{range $i, $track := .Tracks}}
@ -154,7 +160,7 @@
{{if $Track.Lyrics}}
<li><a href="#lyrics">lyrics</a></li>
{{end}}
{{else}}
{{else if .Tracks}}
<li><a href="#tracks">tracks</a></li>
{{end}}
</ul>

View file

@ -93,7 +93,5 @@
&gt; <a href="mailto:ari@arimelody.me">ari@arimelody.me</a>
</p>
</div>
<a href="#" id="backtotop">back to top</a>
</main>
{{end}}

View file

@ -1,5 +1,5 @@
{{define "prideflag"}}
<a href="https://git.arimelody.me/ari/prideflag" target="_blank" id="prideflag">
<a href="https://github.com/arimelody/prideflag" target="_blank" id="prideflag">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="120" height="120" hx-preserve="true">
<path id="red" d="M120,80 L100,100 L120,120 Z" style="fill:#d20605"/>
<path id="orange" d="M120,80 V40 L80,80 L100,100 Z" style="fill:#ef9c00"/>