Compare commits

..

No commits in common. "5284b8a7cc03f3a05480d43ed6e35f613b47793f" and "96cc64464fb581364f485eb7e52013cb1eaf2367" have entirely different histories.

6 changed files with 27 additions and 79 deletions

View file

@ -16,11 +16,7 @@ easy! just `git clone` this repo and `go build` from the root. `arimelody-web(.e
the webserver depends on some environment variables (don't worry about forgetting some; it'll be sure to bug you about them): the webserver depends on some environment variables (don't worry about forgetting some; it'll be sure to bug you about them):
- `ARIMELODY_HTTP_DOMAIN`: the domain the webserver will use for generating oauth redirect URIs (default `https://arimelody.me`) - `HTTP_DOMAIN`: the domain the webserver will use for generating oauth redirect URIs (default `https://arimelody.me`)
- `ARIMELODY_DB_HOST`: the host address of a postgres database.
- `ARIMELODY_DB_NAME`: the name of the database.
- `ARIMELODY_DB_USER`: the username for the database.
- `ARIMELODY_DB_PASS`: the password for the database.
- `DISCORD_ADMIN`[^1]: the user ID of your discord account (discord auth is intended to be temporary, and will be replaced with its own auth system later) - `DISCORD_ADMIN`[^1]: the user ID of your discord account (discord auth is intended to be temporary, and will be replaced with its own auth system later)
- `DISCORD_CLIENT`[^1]: the client ID of your discord OAuth application. - `DISCORD_CLIENT`[^1]: the client ID of your discord OAuth application.
- `DISCORD_SECRET`[^1]: the client secret of your discord OAuth application. - `DISCORD_SECRET`[^1]: the client secret of your discord OAuth application.

View file

@ -1,7 +1,6 @@
package api package api
import ( import (
"arimelody-web/global"
"bufio" "bufio"
"encoding/base64" "encoding/base64"
"errors" "errors"
@ -16,7 +15,6 @@ func HandleImageUpload(data *string, directory string, filename string) (string,
header := split[0] header := split[0]
imageData, err := base64.StdEncoding.DecodeString(split[1]) imageData, err := base64.StdEncoding.DecodeString(split[1])
ext, _ := strings.CutPrefix(header, "data:image/") ext, _ := strings.CutPrefix(header, "data:image/")
directory = filepath.Join(global.DATA_DIR, directory)
switch ext { switch ext {
case "png": case "png":

View file

@ -7,12 +7,8 @@ services:
volumes: volumes:
- ./uploads:/app/uploads - ./uploads:/app/uploads
environment: environment:
ARIMELODY_PORT: 8080 HTTP_DOMAIN: "https://arimelody.me"
ARIMELODY_HTTP_DOMAIN: "https://arimelody.me"
ARIMELODY_DB_HOST: db ARIMELODY_DB_HOST: db
ARIMELODY_DB_NAME: arimelody
ARIMELODY_DB_USER: arimelody
ARIMELODY_DB_PASS: fuckingpassword
DISCORD_ADMIN: # your discord user ID. DISCORD_ADMIN: # your discord user ID.
DISCORD_CLIENT: # your discord OAuth client ID. DISCORD_CLIENT: # your discord OAuth client ID.
DISCORD_SECRET: # your discord OAuth secret. DISCORD_SECRET: # your discord OAuth secret.

View file

@ -3,7 +3,6 @@ package global
import ( import (
"fmt" "fmt"
"os" "os"
"path/filepath"
"strings" "strings"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
@ -35,31 +34,12 @@ var Args = func() map[string]string {
return args return args
}() }()
var HTTP_DOMAIN = func() string { var HTTP_DOMAIN = func() string {
domain := os.Getenv("ARIMELODY_HTTP_DOMAIN") domain := os.Getenv("HTTP_DOMAIN")
if domain == "" { if domain == "" {
return "https://arimelody.me" return "https://arimelody.me"
} }
return domain return domain
}() }()
var DATA_DIR = func() string {
dir, err := filepath.Abs(os.Getenv("ARIMELODY_DATA_DIR"))
if err != nil {
fmt.Printf("FATAL: Failed to get working directory: %s\n", err.Error())
os.Exit(1)
}
if dir != "" {
os.MkdirAll(dir, os.ModePerm)
} else {
var err error
dir, err = os.Getwd()
if err != nil {
fmt.Printf("FATAL: Failed to get working directory: %s\n", err.Error())
os.Exit(1)
}
}
return dir
}()
var DB *sqlx.DB var DB *sqlx.DB

34
main.go
View file

@ -7,46 +7,27 @@ import (
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"strconv"
"time" "time"
"arimelody-web/admin" "arimelody-web/admin"
"arimelody-web/api" "arimelody-web/api"
"arimelody-web/global" "arimelody-web/global"
"arimelody-web/templates"
"arimelody-web/view" "arimelody-web/view"
"arimelody-web/templates"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
_ "github.com/lib/pq" _ "github.com/lib/pq"
) )
const DEFAULT_PORT int64 = 8080 const DEFAULT_PORT int = 8080
func main() { func main() {
// initialise database connection // initialise database connection
var dbHost = os.Getenv("ARIMELODY_DB_HOST") var dbHost = os.Getenv("ARIMELODY_DB_HOST")
var dbName = os.Getenv("ARIMELODY_DB_NAME") if dbHost == "" { dbHost = "127.0.0.1" }
var dbUser = os.Getenv("ARIMELODY_DB_USER")
var dbPass = os.Getenv("ARIMELODY_DB_PASS")
if dbHost == "" {
fmt.Fprintf(os.Stderr, "FATAL: ARIMELODY_DB_HOST not provided! Exiting...\n")
os.Exit(1)
}
if dbName == "" {
fmt.Fprintf(os.Stderr, "FATAL: ARIMELODY_DB_NAME not provided! Exiting...\n")
os.Exit(1)
}
if dbUser == "" {
fmt.Fprintf(os.Stderr, "FATAL: ARIMELODY_DB_USER not provided! Exiting...\n")
os.Exit(1)
}
if dbPass == "" {
fmt.Fprintf(os.Stderr, "FATAL: ARIMELODY_DB_PASS not provided! Exiting...\n")
os.Exit(1)
}
var err error var err error
global.DB, err = sqlx.Connect("postgres", fmt.Sprintf("host=%s user=%s dbname=%s password=%s sslmode=disable", dbHost, dbUser, dbName, dbPass)) global.DB, err = sqlx.Connect("postgres", "host=" + dbHost + " user=arimelody dbname=arimelody password=fuckingpassword sslmode=disable")
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "FATAL: Unable to create database connection pool: %v\n", err) fmt.Fprintf(os.Stderr, "FATAL: Unable to create database connection pool: %v\n", err)
os.Exit(1) os.Exit(1)
@ -58,10 +39,7 @@ func main() {
// start the web server! // start the web server!
mux := createServeMux() mux := createServeMux()
port, err := strconv.ParseInt(os.Getenv("ARIMELODY_PORT"), 10, 0) port := DEFAULT_PORT
if err != nil {
port = DEFAULT_PORT
}
fmt.Printf("Now serving at http://127.0.0.1:%d\n", port) fmt.Printf("Now serving at http://127.0.0.1:%d\n", port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), global.HTTPLog(mux))) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), global.HTTPLog(mux)))
} }
@ -72,7 +50,7 @@ func createServeMux() *http.ServeMux {
mux.Handle("/admin/", http.StripPrefix("/admin", admin.Handler())) mux.Handle("/admin/", http.StripPrefix("/admin", admin.Handler()))
mux.Handle("/api/", http.StripPrefix("/api", api.Handler())) mux.Handle("/api/", http.StripPrefix("/api", api.Handler()))
mux.Handle("/music/", http.StripPrefix("/music", view.MusicHandler())) mux.Handle("/music/", http.StripPrefix("/music", view.MusicHandler()))
mux.Handle("/uploads/", http.StripPrefix("/uploads", staticHandler(filepath.Join(global.DATA_DIR, "uploads")))) mux.Handle("/uploads/", http.StripPrefix("/uploads", staticHandler("uploads")))
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/" || r.URL.Path == "/index.html" { if r.URL.Path == "/" || r.URL.Path == "/index.html" {
err := templates.Pages["index"].Execute(w, nil) err := templates.Pages["index"].Execute(w, nil)

View file

@ -1,18 +1,18 @@
-- --
-- Artists (should be applicable to all art) -- Artists (should be applicable to all art)
-- --
CREATE TABLE artist ( CREATE TABLE public.artist (
id character varying(64), id character varying(64),
name text NOT NULL, name text NOT NULL,
website text, website text,
avatar text avatar text
); );
ALTER TABLE artist ADD CONSTRAINT artist_pk PRIMARY KEY (id); ALTER TABLE public.artist ADD CONSTRAINT artist_pk PRIMARY KEY (id);
-- --
-- Music releases -- Music releases
-- --
CREATE TABLE musicrelease ( CREATE TABLE public.musicrelease (
id character varying(64) NOT NULL, id character varying(64) NOT NULL,
visible bool DEFAULT false, visible bool DEFAULT false,
title text NOT NULL, title text NOT NULL,
@ -25,56 +25,56 @@ CREATE TABLE musicrelease (
copyright text, copyright text,
copyrightURL text copyrightURL text
); );
ALTER TABLE musicrelease ADD CONSTRAINT musicrelease_pk PRIMARY KEY (id); ALTER TABLE public.musicrelease ADD CONSTRAINT musicrelease_pk PRIMARY KEY (id);
-- --
-- Music links (external platform links under a release) -- Music links (external platform links under a release)
-- --
CREATE TABLE musiclink ( CREATE TABLE public.musiclink (
release character varying(64) NOT NULL, release character varying(64) NOT NULL,
name text NOT NULL, name text NOT NULL,
url text NOT NULL url text NOT NULL
); );
ALTER TABLE musiclink ADD CONSTRAINT musiclink_pk PRIMARY KEY (release, name); ALTER TABLE public.musiclink ADD CONSTRAINT musiclink_pk PRIMARY KEY (release, name);
-- --
-- Music credits (artist credits under a release) -- Music credits (artist credits under a release)
-- --
CREATE TABLE musiccredit ( CREATE TABLE public.musiccredit (
release character varying(64) NOT NULL, release character varying(64) NOT NULL,
artist character varying(64) NOT NULL, artist character varying(64) NOT NULL,
role text NOT NULL, role text NOT NULL,
is_primary boolean DEFAULT false is_primary boolean DEFAULT false
); );
ALTER TABLE musiccredit ADD CONSTRAINT musiccredit_pk PRIMARY KEY (release, artist); ALTER TABLE public.musiccredit ADD CONSTRAINT musiccredit_pk PRIMARY KEY (release, artist);
-- --
-- Music tracks (tracks under a release) -- Music tracks (tracks under a release)
-- --
CREATE TABLE musictrack ( CREATE TABLE public.musictrack (
id uuid DEFAULT gen_random_uuid(), id uuid DEFAULT gen_random_uuid(),
title text NOT NULL, title text NOT NULL,
description text, description text,
lyrics text, lyrics text,
preview_url text preview_url text
); );
ALTER TABLE musictrack ADD CONSTRAINT musictrack_pk PRIMARY KEY (id); ALTER TABLE public.musictrack ADD CONSTRAINT musictrack_pk PRIMARY KEY (id);
-- --
-- Music release/track pairs -- Music release/track pairs
-- --
CREATE TABLE musicreleasetrack ( CREATE TABLE public.musicreleasetrack (
release character varying(64) NOT NULL, release character varying(64) NOT NULL,
track uuid NOT NULL, track uuid NOT NULL,
number integer NOT NULL number integer NOT NULL
); );
ALTER TABLE musicreleasetrack ADD CONSTRAINT musicreleasetrack_pk PRIMARY KEY (release, track); ALTER TABLE public.musicreleasetrack ADD CONSTRAINT musicreleasetrack_pk PRIMARY KEY (release, track);
-- --
-- Foreign keys -- Foreign keys
-- --
ALTER TABLE musiccredit ADD CONSTRAINT musiccredit_artist_fk FOREIGN KEY (artist) REFERENCES artist(id) ON DELETE CASCADE ON UPDATE CASCADE; ALTER TABLE public.musiccredit ADD CONSTRAINT musiccredit_artist_fk FOREIGN KEY (artist) REFERENCES public.artist(id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE musiccredit ADD CONSTRAINT musiccredit_release_fk FOREIGN KEY (release) REFERENCES musicrelease(id) ON DELETE CASCADE; ALTER TABLE public.musiccredit ADD CONSTRAINT musiccredit_release_fk FOREIGN KEY (release) REFERENCES public.musicrelease(id) ON DELETE CASCADE;
ALTER TABLE musiclink ADD CONSTRAINT musiclink_release_fk FOREIGN KEY (release) REFERENCES musicrelease(id) ON UPDATE CASCADE ON DELETE CASCADE; ALTER TABLE public.musiclink ADD CONSTRAINT musiclink_release_fk FOREIGN KEY (release) REFERENCES public.musicrelease(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE musicreleasetrack ADD CONSTRAINT music_pair_trackref_fk FOREIGN KEY (release) REFERENCES musicrelease(id) ON DELETE CASCADE; ALTER TABLE public.musicreleasetrack ADD CONSTRAINT music_pair_trackref_fk FOREIGN KEY (release) REFERENCES public.musicrelease(id) ON DELETE CASCADE;
ALTER TABLE musicreleasetrack ADD CONSTRAINT music_pair_releaseref_fk FOREIGN KEY (track) REFERENCES musictrack(id) ON DELETE CASCADE; ALTER TABLE public.musicreleasetrack ADD CONSTRAINT music_pair_releaseref_fk FOREIGN KEY (track) REFERENCES public.musictrack(id) ON DELETE CASCADE;