summaryrefslogtreecommitdiff
path: root/src/db/rest/media
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-04-01 15:02:51 -0400
committerFreya Murphy <freya@freyacat.org>2024-04-01 15:02:51 -0400
commit9ed46c335d6020b10f720d9738b8252d424dd24c (patch)
treefd8751ebf01472d16c6f1bb00797ba921a246d3f /src/db/rest/media
parentlogin and register, liking on homepage (diff)
downloadxssbook2-9ed46c335d6020b10f720d9738b8252d424dd24c.tar.gz
xssbook2-9ed46c335d6020b10f720d9738b8252d424dd24c.tar.bz2
xssbook2-9ed46c335d6020b10f720d9738b8252d424dd24c.zip
start custom banner and avatar loading
Diffstat (limited to 'src/db/rest/media')
-rw-r--r--src/db/rest/media/api_profile_avatar.sql36
-rw-r--r--src/db/rest/media/api_profile_banner.sql13
2 files changed, 49 insertions, 0 deletions
diff --git a/src/db/rest/media/api_profile_avatar.sql b/src/db/rest/media/api_profile_avatar.sql
new file mode 100644
index 0000000..8607999
--- /dev/null
+++ b/src/db/rest/media/api_profile_avatar.sql
@@ -0,0 +1,36 @@
+CREATE FUNCTION api.profile_avatar(
+ user_id INTEGER DEFAULT 0
+)
+RETURNS sys."*/*"
+LANGUAGE plpgsql VOLATILE
+AS $BODY$
+DECLARE
+ _id INTEGER;
+ _mod INTEGER;
+ _name TEXT;
+BEGIN
+ SELECT media_id INTO _id
+ FROM admin.user_media m
+ WHERE m.user_id = profile_avatar.user_id
+ AND type = 'avatar'::admin.user_media_type;
+
+ -- get default if not exists
+ IF NOT FOUND THEN
+ _mod = MOD(user_id, 24);
+ _name = 'default_avatar_' || _mod || '.png';
+
+ SELECT id INTO _id
+ FROM admin.media
+ WHERE name = _name;
+ END IF;
+
+ RETURN _api.serve_media(_id);
+END
+$BODY$;
+
+GRANT EXECUTE ON FUNCTION api.profile_avatar(INTEGER)
+ TO rest_anon, rest_user;
+GRANT SELECT ON TABLE admin.user_media
+ TO rest_anon, rest_user;
+GRANT SELECT ON TABLE admin.media
+ TO rest_anon, rest_user;
diff --git a/src/db/rest/media/api_profile_banner.sql b/src/db/rest/media/api_profile_banner.sql
new file mode 100644
index 0000000..272d021
--- /dev/null
+++ b/src/db/rest/media/api_profile_banner.sql
@@ -0,0 +1,13 @@
+CREATE FUNCTION api.profile_banner(
+ user_id INTEGER DEFAULT 0
+)
+RETURNS sys."*/*"
+LANGUAGE plpgsql VOLATILE
+AS $BODY$
+BEGIN
+ PERFORM _api.raise_deny();
+END
+$BODY$;
+
+GRANT EXECUTE ON FUNCTION api.profile_banner(INTEGER)
+ TO rest_anon, rest_user;