From: Chris Fulljames Date: Sun, 6 Jul 2025 22:15:34 +0000 (-0400) Subject: Add ntfy instructions, uuid X-Git-Url: https://littlesong.place/gitweb/?a=commitdiff_plain;h=1143ae9a49e466afc8b1aea33768abc2c134a2aa;p=littlesongplace.git Add ntfy instructions, uuid --- diff --git a/src/littlesongplace/__init__.py b/src/littlesongplace/__init__.py index 5754392..b2648fa 100644 --- a/src/littlesongplace/__init__.py +++ b/src/littlesongplace/__init__.py @@ -91,6 +91,10 @@ def site_news(): def about(): return render_template("about.html") +@app.get("/notifications") +def notifications(): + return render_template("notifications.html") + def get_gif_data(): # Convert all .gifs to base64 strings and embed them as dataset entries # in
s. This is used by nav.js:customImage() - it replaces specific diff --git a/src/littlesongplace/auth.py b/src/littlesongplace/auth.py index 174a5f2..b32a05b 100644 --- a/src/littlesongplace/auth.py +++ b/src/littlesongplace/auth.py @@ -4,7 +4,7 @@ from datetime import datetime, timezone import bcrypt from flask import Blueprint, render_template, redirect, flash, g, request, current_app, session -from . import comments, db +from . import comments, db, users from .logutils import flash_and_log bp = Blueprint("auth", __name__) @@ -108,10 +108,14 @@ def requires_login(f): if not "userid" in session: return redirect("/login") - g.userid = session["userid"] - g.username = session["username"] - return f(*args, **kwargs) return _wrapper +@bp.before_app_request +def load_user(): + if "userid" in session: + g.userid = session["userid"] + g.username = session["username"] + g.user = users.by_id(session["userid"]) + diff --git a/src/littlesongplace/db.py b/src/littlesongplace/db.py index ec1ebad..0fd94c9 100644 --- a/src/littlesongplace/db.py +++ b/src/littlesongplace/db.py @@ -6,7 +6,7 @@ from flask import abort, g, current_app from . import datadir -DB_VERSION = 5 +DB_VERSION = 6 def get(): db = getattr(g, '_database', None) diff --git a/src/littlesongplace/sql/schema.sql b/src/littlesongplace/sql/schema.sql index 51057b6..6b34013 100644 --- a/src/littlesongplace/sql/schema.sql +++ b/src/littlesongplace/sql/schema.sql @@ -1,3 +1,17 @@ +DROP TABLE IF EXISTS jam_events; +CREATE TABLE jam_events( + eventid INTEGER PRIMARY KEY, + jamid INTEGER NOT NULL, + threadid INTEGER NOT NULL, + created TEXT NOT NULL, + title TEXT NOT NULL, -- Hidden until startdate + startdate TEXT, + enddate TEXT, + description TEXT, -- Hidden until startdate + FOREIGN KEY(jamid) REFERENCES jams(jamid), + FOREIGN KEY(threadid) REFERENCES comment_threads(threadid) +); + DROP TABLE IF EXISTS users; CREATE TABLE users ( userid INTEGER PRIMARY KEY AUTOINCREMENT, @@ -21,9 +35,12 @@ CREATE TABLE songs ( title TEXT NOT NULL, description TEXT, threadid INTEGER, - FOREIGN KEY(userid) REFERENCES users(userid) + eventid INTEGER, + FOREIGN KEY(userid) REFERENCES users(userid), + FOREIGN KEY(eventid) REFERENCES jam_events(eventid) ); CREATE INDEX idx_songs_by_user ON songs(userid); +CREATE INDEX idx_songs_by_eventid ON songs(eventid); DROP TABLE IF EXISTS song_collaborators; CREATE TABLE song_collaborators ( @@ -159,5 +176,15 @@ BEGIN DELETE FROM notifications WHERE objectid = OLD.commentid AND objecttype = 0; END; -PRAGMA user_version = 4; +DROP TABLE IF EXISTS jams; +CREATE TABLE jams ( + jamid INTEGER PRIMARY KEY, + ownerid INTEGER NOT NULL, + created TEXT NOT NULL, + title TEXT NOT NULL, + description TEXT, + FOREIGN KEY(ownerid) REFERENCES users(userid) +); + +PRAGMA user_version = 5; diff --git a/src/littlesongplace/sql/schema_revert.sql b/src/littlesongplace/sql/schema_revert.sql index a6cd883..b4b96af 100644 --- a/src/littlesongplace/sql/schema_revert.sql +++ b/src/littlesongplace/sql/schema_revert.sql @@ -1,7 +1,3 @@ -DROP INDEX idx_songs_by_eventid; -ALTER TABLE songs DROP COLUMN eventid; -DROP TABLE IF EXISTS jams; -DROP TABLE IF EXISTS jam_events; - -PRAGMA user_version = 4; +ALTER TABLE users DROP COLUMN ntfyuuid; +PRAGMA user_version = 5; diff --git a/src/littlesongplace/sql/schema_update.sql b/src/littlesongplace/sql/schema_update.sql index ffb9b60..2e1021a 100644 --- a/src/littlesongplace/sql/schema_update.sql +++ b/src/littlesongplace/sql/schema_update.sql @@ -1,29 +1,3 @@ ---DROP TABLE IF EXISTS jams; -CREATE TABLE jams ( - jamid INTEGER PRIMARY KEY, - ownerid INTEGER NOT NULL, - created TEXT NOT NULL, - title TEXT NOT NULL, - description TEXT, - FOREIGN KEY(ownerid) REFERENCES users(userid) -); - ---DROP TABLE IF EXISTS jam_events; -CREATE TABLE jam_events( - eventid INTEGER PRIMARY KEY, - jamid INTEGER NOT NULL, - threadid INTEGER NOT NULL, - created TEXT NOT NULL, - title TEXT NOT NULL, -- Hidden until startdate - startdate TEXT, - enddate TEXT, - description TEXT, -- Hidden until startdate - FOREIGN KEY(jamid) REFERENCES jams(jamid), - FOREIGN KEY(threadid) REFERENCES comment_threads(threadid) -); - -ALTER TABLE songs ADD COLUMN eventid INTEGER REFERENCES jam_events(eventid); -CREATE INDEX idx_songs_by_eventid ON songs(eventid); - -PRAGMA user_version = 5; +ALTER TABLE users ADD COLUMN ntfyuuid TEXT; +PRAGMA user_version = 6; diff --git a/src/littlesongplace/static/ntfy_done.webp b/src/littlesongplace/static/ntfy_done.webp new file mode 100644 index 0000000..da3444e Binary files /dev/null and b/src/littlesongplace/static/ntfy_done.webp differ diff --git a/src/littlesongplace/static/ntfy_server.webp b/src/littlesongplace/static/ntfy_server.webp new file mode 100644 index 0000000..faf5f0f Binary files /dev/null and b/src/littlesongplace/static/ntfy_server.webp differ diff --git a/src/littlesongplace/static/ntfy_sub.webp b/src/littlesongplace/static/ntfy_sub.webp new file mode 100644 index 0000000..ff47abe Binary files /dev/null and b/src/littlesongplace/static/ntfy_sub.webp differ diff --git a/src/littlesongplace/templates/activity.html b/src/littlesongplace/templates/activity.html index 19f8f25..9a33dc0 100644 --- a/src/littlesongplace/templates/activity.html +++ b/src/littlesongplace/templates/activity.html @@ -4,6 +4,8 @@ {% block body %} +

[push notifications available]

+ {% if comments %}

activity

diff --git a/src/littlesongplace/templates/index.html b/src/littlesongplace/templates/index.html index 587ff5d..edc7f79 100644 --- a/src/littlesongplace/templates/index.html +++ b/src/littlesongplace/templates/index.html @@ -33,6 +33,7 @@

hot new tunes

+

[push notifications available]

{% include "song-list.html" %} {% endblock %} diff --git a/src/littlesongplace/templates/news.html b/src/littlesongplace/templates/news.html index 36bd090..d552f81 100644 --- a/src/littlesongplace/templates/news.html +++ b/src/littlesongplace/templates/news.html @@ -6,6 +6,8 @@

site news

+

[push notifications available]

+

2025-07-01 - Download Button

You can now download your own songs as mp3 files from the dedicated button on diff --git a/src/littlesongplace/templates/notifications.html b/src/littlesongplace/templates/notifications.html new file mode 100644 index 0000000..82dccab --- /dev/null +++ b/src/littlesongplace/templates/notifications.html @@ -0,0 +1,32 @@ +{% extends "base.html" %} + +{% block title %}Push Notifications{% endblock %} + +{% block body %} + +

Push Notifications

+ +

+littlesong.place can send you push notifications on your phone via +ntfy. +It takes a few minutes to set up (I know, it's a little clunky), but you only have to do it once. +Here's how it works: +

+
    +
  1. Install the ntfy app on your device.
  2. +
  3. Open the app and grant it permission to send you push notifications when asked.
  4. +
  5. In the ntfy app, open the Settings tab, and set Default server to https://ntfy.littlesong.place.
  6. +
  7. Subscribe to each topic you'd like to be notified about using the '+' button in the app (see available topics below).
  8. +
  9. When you're done, it should look something like this:

  10. +
+Available topics include: + + +{% endblock %} diff --git a/src/littlesongplace/users.py b/src/littlesongplace/users.py index 857196d..8d8de2d 100644 --- a/src/littlesongplace/users.py +++ b/src/littlesongplace/users.py @@ -1,3 +1,4 @@ +import uuid from dataclasses import dataclass from . import colors, datadir, db @@ -9,6 +10,7 @@ class User: fgcolor: str bgcolor: str accolor: str + _ntfy_uuid: str @property def colors(self): @@ -18,12 +20,23 @@ class User: "accolor": self.accolor, } + @property + def ntfy_uuid(self): + if not self._ntfy_uuid: + self._ntfy_uuid = str(uuid.uuid4()) + db.query( + "UPDATE users SET ntfyuuid = ? WHERE userid = ?", + [self._ntfy_uuid, self.userid]) + db.commit() + return self._ntfy_uuid + @classmethod def from_row(cls, row): user_colors = get_user_colors(row) return User( userid=row["userid"], username=row["username"], + _ntfy_uuid=row["ntfyuuid"], **user_colors) def by_id(userid):