]> littlesong.place Git - littlesongplace.git/commitdiff
Start work on tags and collaborators
authorChris Fulljames <christianfulljames@gmail.com>
Sun, 5 Jan 2025 00:10:09 +0000 (19:10 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Sun, 5 Jan 2025 00:10:09 +0000 (19:10 -0500)
main.py
schema.sql
templates/profile.html

diff --git a/main.py b/main.py
index d22eadf7f2795f11e15003fefb0355fb2c32471d..8952be5719786043814f89fcc720e98eb5bc9eb9 100644 (file)
--- a/main.py
+++ b/main.py
@@ -10,25 +10,14 @@ from flask import Flask, render_template, request, redirect, g, session, abort,
         send_from_directory
 from werkzeug.utils import secure_filename
 
-################################################################################
-# Check for Required Environment Variables
-################################################################################
-
-REQUIRED_VARS = ["SECRET_KEY", "DATA_DIR"]
-
-for var in REQUIRED_VARS:
-    if var not in os.environ:
-        print(f"{var} not set")
-        sys.exit(1)
-
-DATA_DIR = Path(os.environ["DATA_DIR"])
-
 ################################################################################
 # Routes
 ################################################################################
 
+DATA_DIR = Path(".")
+
 app = Flask(__name__)
-app.secret_key = os.environ["SECRET_KEY"]
+app.secret_key = "dev"
 
 @app.route("/")
 def index():
@@ -148,7 +137,9 @@ def upload_song():
 @app.get("/song/<userid>/<songid>")
 def song(userid, songid):
     try:
-        int(userid) # Make sure userid is a valid integer
+        # Make sure values are valid integers
+        int(userid) 
+        int(songid) 
     except ValueError:
         abort(404)
 
@@ -177,6 +168,7 @@ def query_db(query, args=(), one=False):
     cur.close()
     return (rv[0] if rv else None) if one else rv
 
+@app.cli.add_command
 @click.command("init-db")
 def init_db():
     """Clear the existing data and create new tables"""
@@ -191,18 +183,10 @@ def init_db():
 # Generate Session Key
 ################################################################################
 
+@app.cli.add_command
 @click.command("gen-key")
 def gen_key():
     """Generate a secret key for session cookie encryption"""
     import secrets
     print(secrets.token_hex())
 
-
-################################################################################
-# App Configuration
-################################################################################
-
-app.teardown_appcontext(close_db)
-app.cli.add_command(init_db)
-app.cli.add_command(gen_key)
-
index 331c5be87881983170e9f9dbf043de49558b3d4a..abf612640fb2e929d024cdcf245d918166a4320a 100644 (file)
@@ -1,12 +1,11 @@
 DROP TABLE IF EXISTS users;
-DROP TABLE IF EXISTS songs;
-
 CREATE TABLE users (
     userid INTEGER PRIMARY KEY AUTOINCREMENT,
     username TEXT UNIQUE NOT NULL,
     password TEXT NOT NULL
 );
 
+DROP TABLE IF EXISTS songs;
 CREATE TABLE songs (
     songid INTEGER PRIMARY KEY AUTOINCREMENT,
     userid INTEGER NOT NULL,
@@ -14,3 +13,29 @@ CREATE TABLE songs (
     description TEXT,
     FOREIGN KEY(userid) REFERENCES users(userid)
 );
+
+DROP TABLE IF EXISTS song_collaborators;
+CREATE TABLE song_collaborators (
+    collabid INTEGER NOT NULL,
+    songid INTEGER NOT NULL,
+    userid INTEGER,
+    name TEXT,
+    FOREIGN KEY(userid) REFERENCES users(userid),
+    PRIMARY KEY(collabid, songid),
+    CONSTRAINT userid_or_name CHECK ((userid IS NULL and name IS NOT NULL) OR (userid IS NOT NULL and name IS NULL))
+);
+
+DROP TABLE IF EXISTS tags;
+CREATE TABLE tags (
+    tagid INTEGER PRIMARY KEY,
+    name TEXT NOT NULL
+);
+
+DROP TABLE IF EXISTS song_tags;
+CREATE TABLE song_tags (
+    tagid INTEGER NOT NULL,
+    songid INTEGER NOT NULL,
+    FOREIGN KEY(tagid) REFERENCES tags(tagid),
+    FOREIGN KEY(songid) REFERENCES songs(songid),
+    PRIMARY KEY(tagid, songid)
+);
index 77d0a05da4e5bb375ba51d4a124c43abf88090a7..92fc9155a72f5c6110f7b94c09d8df7472ebd9d4 100644 (file)
         <input type="text" name="title" required></input>
     </div>
     <div class="upload-form">
-        <label for="title">Description (optional)</label>
+        <label for="title">Description</label>
         <textarea name="description"></textarea>
     </div>
+    <div class="upload-form">
+        <label for="tags">Tags</label>
+        <input type="text" name="tags" placeholder="country, extratone, vocals, ..."></input>
+    </div>
+    <div class="upload-form">
+        <label for="collabs">Collaborators</label>
+        <input type="text" name="collabs" placeholder="@fren_user, John Doe, ..."></input>
+    </div>
     <div class="upload-form">
         <input type="submit" value="Upload"></input>
     </div>