args over envars, some music gateway fixes
This commit is contained in:
parent
ec3ccec73c
commit
99b6a21179
|
@ -3,8 +3,9 @@ package admin
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"arimelody.me/arimelody.me/global"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -19,19 +20,19 @@ const TOKEN_LENGTH = 64
|
||||||
const TOKEN_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
const TOKEN_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||||
|
|
||||||
var ADMIN_BYPASS = func() bool {
|
var ADMIN_BYPASS = func() bool {
|
||||||
if os.Getenv("ARIMELODY_ADMIN_BYPASS") == "true" {
|
if global.Args["adminBypass"] == "true" {
|
||||||
fmt.Println("WARNING: Admin login is currently BYPASSED by ARIMELODY_ADMIN_BYPASS.")
|
fmt.Println("WARN: Admin login is currently BYPASSED. (-adminBypass)")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var ADMIN_ID_DISCORD = func() string {
|
var ADMIN_ID_DISCORD = func() string {
|
||||||
envvar := os.Getenv("DISCORD_ADMIN_ID")
|
id := global.Args["discordAdmin"]
|
||||||
if envvar == "" {
|
if id == "" {
|
||||||
fmt.Printf("DISCORD_ADMIN_ID was not provided. Admin login will be unavailable.\n")
|
fmt.Printf("WARN: Discord admin ID (-discordAdmin) was not provided. Admin login will be unavailable.\n")
|
||||||
}
|
}
|
||||||
return envvar
|
return id
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var sessions []*Session
|
var sessions []*Session
|
||||||
|
|
|
@ -6,45 +6,32 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"arimelody.me/arimelody.me/global"
|
||||||
)
|
)
|
||||||
|
|
||||||
const API_ENDPOINT = "https://discord.com/api/v10"
|
const API_ENDPOINT = "https://discord.com/api/v10"
|
||||||
|
|
||||||
var CREDENTIALS_PROVIDED = true
|
var CREDENTIALS_PROVIDED = true
|
||||||
var CLIENT_ID = func() string {
|
var CLIENT_ID = func() string {
|
||||||
envvar := os.Getenv("DISCORD_CLIENT_ID")
|
id := global.Args["discordClient"]
|
||||||
if envvar == "" {
|
if id == "" {
|
||||||
fmt.Printf("DISCORD_CLIENT_ID was not provided. Admin login will be unavailable.\n")
|
fmt.Printf("WARN: Discord client ID (-discordClient) was not provided. Admin login will be unavailable.\n")
|
||||||
CREDENTIALS_PROVIDED = false
|
CREDENTIALS_PROVIDED = false
|
||||||
}
|
}
|
||||||
return envvar
|
return id
|
||||||
}()
|
}()
|
||||||
var CLIENT_SECRET = func() string {
|
var CLIENT_SECRET = func() string {
|
||||||
envvar := os.Getenv("DISCORD_CLIENT_SECRET")
|
secret := global.Args["discordSecret"]
|
||||||
if envvar == "" {
|
if secret== "" {
|
||||||
fmt.Printf("DISCORD_CLIENT_SECRET was not provided. Admin login will be unavailable.\n")
|
fmt.Printf("WARN: Discord secret (-discordSecret) was not provided. Admin login will be unavailable.\n")
|
||||||
CREDENTIALS_PROVIDED = false
|
CREDENTIALS_PROVIDED = false
|
||||||
}
|
}
|
||||||
return envvar
|
return secret
|
||||||
}()
|
|
||||||
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
|
|
||||||
}()
|
}()
|
||||||
|
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 (
|
type (
|
||||||
AccessTokenResponse struct {
|
AccessTokenResponse struct {
|
||||||
|
|
|
@ -1,19 +1,48 @@
|
||||||
package global
|
package global
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"arimelody.me/arimelody.me/music/model"
|
"arimelody.me/arimelody.me/music/model"
|
||||||
"github.com/jmoiron/sqlx"
|
"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 {
|
var HTTP_DOMAIN = func() string {
|
||||||
envvar := os.Getenv("HTTP_DOMAIN")
|
envvar := os.Getenv("HTTP_DOMAIN")
|
||||||
if envvar != "" {
|
if envvar != "" {
|
||||||
return envvar
|
return envvar
|
||||||
}
|
}
|
||||||
return "https://arimelody.me"
|
return "https://arimelody.me"
|
||||||
}
|
}()
|
||||||
|
|
||||||
var DB *sqlx.DB
|
var DB *sqlx.DB
|
||||||
|
|
||||||
|
|
|
@ -70,4 +70,5 @@ function bind_share_btn() {
|
||||||
bind_share_btn();
|
bind_share_btn();
|
||||||
bind_go_back_btn();
|
bind_go_back_btn();
|
||||||
apply_funny_bob_to_upcoming_tags();
|
apply_funny_bob_to_upcoming_tags();
|
||||||
|
if (document.getElementById("extras"))
|
||||||
update_extras_buttons();
|
update_extras_buttons();
|
||||||
|
|
|
@ -108,14 +108,20 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{if .IsSingle}}
|
{{if .IsSingle}}
|
||||||
|
|
||||||
{{$Track := index .Tracks 0}}
|
{{$Track := index .Tracks 0}}
|
||||||
{{if $Track.Lyrics}}
|
{{if $Track.Lyrics}}
|
||||||
<div id="lyrics">
|
<div id="lyrics">
|
||||||
<h2>lyrics:</h2>
|
<p class="album-track-subheading">LYRICS</p>
|
||||||
<p>{{$Track.Lyrics}}</p>
|
{{if $Track.Lyrics}}
|
||||||
|
{{$Track.Lyrics}}
|
||||||
|
{{else}}
|
||||||
|
<span class="empty">No lyrics.</span>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{else}}
|
|
||||||
|
{{else if .Tracks}}
|
||||||
<div id="tracks">
|
<div id="tracks">
|
||||||
<h2>tracks:</h2>
|
<h2>tracks:</h2>
|
||||||
{{range $i, $track := .Tracks}}
|
{{range $i, $track := .Tracks}}
|
||||||
|
@ -154,7 +160,7 @@
|
||||||
{{if $Track.Lyrics}}
|
{{if $Track.Lyrics}}
|
||||||
<li><a href="#lyrics">lyrics</a></li>
|
<li><a href="#lyrics">lyrics</a></li>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{else}}
|
{{else if .Tracks}}
|
||||||
<li><a href="#tracks">tracks</a></li>
|
<li><a href="#tracks">tracks</a></li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -93,7 +93,5 @@
|
||||||
> <a href="mailto:ari@arimelody.me">ari@arimelody.me</a>
|
> <a href="mailto:ari@arimelody.me">ari@arimelody.me</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a href="#" id="backtotop">back to top</a>
|
|
||||||
</main>
|
</main>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{{define "prideflag"}}
|
{{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">
|
<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="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"/>
|
<path id="orange" d="M120,80 V40 L80,80 L100,100 Z" style="fill:#ef9c00"/>
|
||||||
|
|
Loading…
Reference in a new issue