diff --git a/app/api/alpha/routes.py b/app/api/alpha/routes.py index 5eccf6e8..2e046237 100644 --- a/app/api/alpha/routes.py +++ b/app/api/alpha/routes.py @@ -496,79 +496,3 @@ def alpha_emoji(): return jsonify({"error": "not_yet_implemented"}), 400 -# HTML routes -from flask import abort, render_template -from app.models import Community -from app.utils import current_theme -import os - -@bp.route('/api/alpha/', methods=['GET']) -def get_alpha(): - if not current_app.debug: - abort(404) - - template_name = "index.html" - - theme = current_theme() - if theme != '' and os.path.exists(f'app/templates/themes/{theme}/{template_name}'): - return render_template(f'themes/{theme}/{template_name}') - else: - return render_template(template_name) - - -@bp.route('/api/alpha/auth/login', methods=['GET']) -def get_alpha_auth_login(): - if not current_app.debug: - abort(404) - - template_name = "auth/login.html" - - theme = current_theme() - if theme != '' and os.path.exists(f'app/templates/themes/{theme}/{template_name}'): - return render_template(f'themes/{theme}/{template_name}') - else: - return render_template(template_name) - - -@bp.route('/api/alpha/auth/logout', methods=['GET']) -def get_alpha_auth_logout(): - if not current_app.debug: - abort(404) - - template_name = "auth/logout.html" - - theme = current_theme() - if theme != '' and os.path.exists(f'app/templates/themes/{theme}/{template_name}'): - return render_template(f'themes/{theme}/{template_name}') - else: - return render_template(template_name) - - -@bp.route('/api/alpha/communities', methods=['GET']) -def get_alpha_communities(): - if not current_app.debug: - abort(404) - - template_name = "list_communities.html" - - theme = current_theme() - if theme != '' and os.path.exists(f'app/templates/themes/{theme}/{template_name}'): - return render_template(f'themes/{theme}/{template_name}') - else: - return render_template(template_name) - - -@bp.route('/api/alpha/c/', methods=['GET']) -def community_profile(actor): - if '@' in actor: - community = Community.query.filter_by(ap_id=actor.lower(), banned=False).first() - else: - community = Community.query.filter_by(name=actor, ap_id=None).first() - - template_name = "community.html" - - theme = current_theme() - if theme != '' and os.path.exists(f'app/templates/themes/{theme}/{template_name}'): - return render_template(f'themes/{theme}/{template_name}', community_id=community.id) - else: - return render_template(template_name, community_id=community.id) diff --git a/app/templates/themes/x_api/auth/login.html b/app/templates/themes/x_api/auth/login.html deleted file mode 100644 index 18f8d20b..00000000 --- a/app/templates/themes/x_api/auth/login.html +++ /dev/null @@ -1,38 +0,0 @@ -{% extends 'themes/' + theme() + '/base.html' %} - -{% block app_content %} -

-
JSON
- -

POST /api/alpha/user/login

-
JSON
- -
- -
-
- - -
- -
- - -
- -
- - -
- -
- -

- {{ _('New User?') }} {{ _('Register new account') }} -

-

- {{ _('Forgot Your Password?') }} {{ _('Reset it') }} -

- - -{% endblock %} diff --git a/app/templates/themes/x_api/auth/logout.html b/app/templates/themes/x_api/auth/logout.html deleted file mode 100644 index f09d3703..00000000 --- a/app/templates/themes/x_api/auth/logout.html +++ /dev/null @@ -1,5 +0,0 @@ -{% extends 'themes/' + theme() + '/base.html' %} - -{% block app_content %} - -{% endblock %} diff --git a/app/templates/themes/x_api/base.html b/app/templates/themes/x_api/base.html deleted file mode 100644 index 74ecd2a0..00000000 --- a/app/templates/themes/x_api/base.html +++ /dev/null @@ -1,114 +0,0 @@ -{% macro render_username(user, add_domain=True) -%} - - {% if user.deleted -%} - [deleted] - {% else -%} - - {{ user.display_name() }}{% if not user.is_local() %}@{{ user.ap_domain }}{% endif %} - - {% if user.bot -%} - - {% endif -%} - {% endif -%} - -{% endmacro -%} - -{% macro render_communityname(community, add_domain=True) -%} - - - {{ community.title }}{% if not community.is_local() %}@{{ community.ap_domain }}{% endif %} - - -{% endmacro -%} - - - - - - - - - - - - - - - - - - - - - - - {{ bootstrap.load_css() }} - - - - - - - - - - - -
- {% block app_content %}{% endblock %} -
-
- - - - {{ bootstrap.load_js() }} - - - diff --git a/app/templates/themes/x_api/community.html b/app/templates/themes/x_api/community.html deleted file mode 100644 index 63083251..00000000 --- a/app/templates/themes/x_api/community.html +++ /dev/null @@ -1,12 +0,0 @@ -{% extends 'themes/' + theme() + '/base.html' %} - -{% block app_content %} -

-
JSON
-

GET /api/alpha/community?id={{ community_id }}

-
JSON
-

GET /api/alpha/post/list?sort=Hot&page=1&community_id={{ community_id }}

-
JSON
- - -{% endblock %} diff --git a/app/templates/themes/x_api/css/color-modes.css b/app/templates/themes/x_api/css/color-modes.css deleted file mode 100644 index 9e9beed0..00000000 --- a/app/templates/themes/x_api/css/color-modes.css +++ /dev/null @@ -1,29 +0,0 @@ -.bi { - vertical-align: -.125em; - fill: currentColor; -} - -.btn-bd-primary { - --bd-violet-bg: #712cf9; - --bd-violet-rgb: 112.520718, 44.062154, 249.437846; - - --bs-btn-font-weight: 600; - --bs-btn-color: var(--bs-white); - --bs-btn-bg: var(--bd-violet-bg); - --bs-btn-border-color: var(--bd-violet-bg); - --bs-btn-hover-color: var(--bs-white); - --bs-btn-hover-bg: #6528e0; - --bs-btn-hover-border-color: #6528e0; - --bs-btn-focus-shadow-rgb: var(--bd-violet-rgb); - --bs-btn-active-color: var(--bs-btn-hover-color); - --bs-btn-active-bg: #5a23c8; - --bs-btn-active-border-color: #5a23c8; -} - -.bd-mode-toggle { - z-index: 1500; -} - -.bd-mode-toggle .dropdown-menu .active .bi { - display: block !important; -} diff --git a/app/templates/themes/x_api/css/navbars.css b/app/templates/themes/x_api/css/navbars.css deleted file mode 100644 index e717c1cd..00000000 --- a/app/templates/themes/x_api/css/navbars.css +++ /dev/null @@ -1,8 +0,0 @@ -body { - padding-bottom: 20px; -} - -.navbar { - margin-bottom: 20px; -} - diff --git a/app/templates/themes/x_api/donate.html b/app/templates/themes/x_api/donate.html deleted file mode 100644 index 4a820aa0..00000000 --- a/app/templates/themes/x_api/donate.html +++ /dev/null @@ -1,12 +0,0 @@ -{% extends 'themes/' + theme() + '/base.html' %} - -{% block app_content %} -

{{ _('Donate') }}

-

PieFed is free and open-source software while operating without any advertising, monetization, or reliance on - venture capital. Your contributions are vital in supporting the PieFed development effort, - allowing us to expand and enhance PieFed with new features.

- -
- Donate using Patreon -
-{% endblock %} diff --git a/app/templates/themes/x_api/index.html b/app/templates/themes/x_api/index.html deleted file mode 100644 index 495c2b83..00000000 --- a/app/templates/themes/x_api/index.html +++ /dev/null @@ -1,12 +0,0 @@ -{% extends 'themes/' + theme() + '/base.html' %} - -{% block app_content %} -

-
JSON
- -
- -

-
JSON
- -{% endblock%} diff --git a/app/templates/themes/x_api/js/color-modes.js b/app/templates/themes/x_api/js/color-modes.js deleted file mode 100644 index f5d5dbf3..00000000 --- a/app/templates/themes/x_api/js/color-modes.js +++ /dev/null @@ -1,81 +0,0 @@ -/*! - * Color mode toggler for Bootstrap's docs (https://getbootstrap.com/) - * Copyright 2011-2024 The Bootstrap Authors - * Licensed under the Creative Commons Attribution 3.0 Unported License. - */ - -(() => { - 'use strict' - - const getStoredTheme = () => localStorage.getItem('theme') - const setStoredTheme = theme => localStorage.setItem('theme', theme) - - const getPreferredTheme = () => { - const storedTheme = getStoredTheme() - if (storedTheme) { - return storedTheme - } - - return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' - } - - const setTheme = theme => { - if (theme === 'auto') { - document.documentElement.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) - } else { - document.documentElement.setAttribute('data-bs-theme', theme) - } - } - - setTheme(getPreferredTheme()) - - const showActiveTheme = (theme, focus = false) => { - const themeSwitcher = document.querySelector('#bd-theme') - - if (!themeSwitcher) { - return - } - - const themeSwitcherText = document.querySelector('#bd-theme-text') - const activeThemeIcon = document.querySelector('.theme-icon-active use') - const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`) - const svgOfActiveBtn = btnToActive.querySelector('svg use').getAttribute('href') - - document.querySelectorAll('[data-bs-theme-value]').forEach(element => { - element.classList.remove('active') - element.setAttribute('aria-pressed', 'false') - }) - - btnToActive.classList.add('active') - btnToActive.setAttribute('aria-pressed', 'true') - activeThemeIcon.setAttribute('href', svgOfActiveBtn) - const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})` - themeSwitcher.setAttribute('aria-label', themeSwitcherLabel) - - if (focus) { - themeSwitcher.focus() - } - } - - window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { - const storedTheme = getStoredTheme() - if (storedTheme !== 'light' && storedTheme !== 'dark') { - setTheme(getPreferredTheme()) - } - }) - - window.addEventListener('DOMContentLoaded', () => { - showActiveTheme(getPreferredTheme()) - - document.querySelectorAll('[data-bs-theme-value]') - .forEach(toggle => { - toggle.addEventListener('click', () => { - const theme = toggle.getAttribute('data-bs-theme-value') - setStoredTheme(theme) - setTheme(theme) - showActiveTheme(theme, true) - }) - }) - }) -})() - diff --git a/app/templates/themes/x_api/js/community.js b/app/templates/themes/x_api/js/community.js deleted file mode 100644 index 865d70cf..00000000 --- a/app/templates/themes/x_api/js/community.js +++ /dev/null @@ -1,26 +0,0 @@ -const element = document.getElementById('community_request'); -const community_id = element.getAttribute('data-value'); - -import { baseUrl } from './site.js'; -const community_api = baseUrl + '/api/alpha/community?id=' + community_id; -const community_post_list_api = baseUrl + '/api/alpha/post/list?sort=Hot&page=1&community_id=' + community_id; - -import { jwt } from './site.js'; -if (jwt != null) { - var request = {method: "GET", headers: {Authorization: `Bearer ${jwt}`}}; -} else { - var request = {method: "GET"}; -} - -fetch(community_api, request) - .then(response => response.json()) - .then(data => { - document.querySelector('#community_json').textContent = JSON.stringify(data, null, 2); - }) - - -fetch(community_post_list_api, request) - .then(response => response.json()) - .then(data => { - document.querySelector('#community_post_list_json').textContent = JSON.stringify(data, null, 2); - }) diff --git a/app/templates/themes/x_api/js/list_communities.js b/app/templates/themes/x_api/js/list_communities.js deleted file mode 100644 index 6946b581..00000000 --- a/app/templates/themes/x_api/js/list_communities.js +++ /dev/null @@ -1,15 +0,0 @@ -import { baseUrl } from './site.js'; -const api = baseUrl + '/api/alpha/community/list'; - -import { jwt } from './site.js'; -if (jwt != null) { - var request = {method: "GET", headers: {Authorization: `Bearer ${jwt}`}}; -} else { - var request = {method: "GET"}; -} - -fetch(api, request) - .then(response => response.json()) - .then(data => { - document.querySelector('#community_list_json').textContent = JSON.stringify(data, null, 2); - }) diff --git a/app/templates/themes/x_api/js/login.js b/app/templates/themes/x_api/js/login.js deleted file mode 100644 index 0f7bd0c7..00000000 --- a/app/templates/themes/x_api/js/login.js +++ /dev/null @@ -1,38 +0,0 @@ -document.querySelector('#login_json').textContent = '{"username_or_email": "", "password": ""}' - -const login_form = document.getElementById('login_form'); -const username = document.getElementById('username'); -const password = document.getElementById('password'); -const remember_me = document.getElementById('remember_me'); - -login_form.addEventListener('submit', async event => { - event.preventDefault(); - - json_string = JSON.stringify({ username_or_email: username.value, password: password.value }) - - const url = new URL(window.location.href); - const baseUrl = `${url.protocol}//${url.host}`; - const api = baseUrl + '/api/alpha/user/login'; - - try { - const response = await fetch(api, {method: 'POST', body: json_string}); - if (!response.ok) { - throw new Error(`Response status: ${response.status}`); - } - - const response_json = await response.json(); - - if (remember_me.checked == true) { - localStorage.setItem('jwt', response_json['jwt']); - } else { - sessionStorage.setItem('jwt', response_json['jwt']); - } - - window.location.href = baseUrl; - - } catch (error) { - console.error(error.message); - } -}); - - diff --git a/app/templates/themes/x_api/js/logout.js b/app/templates/themes/x_api/js/logout.js deleted file mode 100644 index d22a4e53..00000000 --- a/app/templates/themes/x_api/js/logout.js +++ /dev/null @@ -1,6 +0,0 @@ -localStorage.removeItem('jwt'); -sessionStorage.removeItem('jwt'); - -const url = new URL(window.location.href); -const baseUrl = `${url.protocol}//${url.host}`; -window.location.href = baseUrl; diff --git a/app/templates/themes/x_api/js/site.js b/app/templates/themes/x_api/js/site.js deleted file mode 100644 index 4b3f3225..00000000 --- a/app/templates/themes/x_api/js/site.js +++ /dev/null @@ -1,150 +0,0 @@ -const url = new URL(window.location.href); -export const baseUrl = `${url.protocol}//${url.host}`; -const api_site = baseUrl + '/api/alpha/site'; - -let jwt = null; -let session_jwt = sessionStorage.getItem('jwt'); -if (session_jwt != null) { - jwt = session_jwt; -} else { - let local_jwt = localStorage.getItem('jwt'); - if (local_jwt != null) { - jwt = local_jwt; - } -} -export { jwt }; - -const navbar = document.getElementById('navbar_items'); -if (jwt != null) { - var request = {method: "GET", headers: {Authorization: `Bearer ${jwt}`}}; -} else { - var request = {method: "GET"}; - navbar.innerHTML = '' + - '' + - '' + - ''; -} - -fetch(api_site, request) - .then(response => response.json()) - .then(data => { - // head - document.querySelector('#head_title').textContent = data.site.name; - document.querySelector('#icon_152').href = data.site.icon_152; - document.querySelector('#icon_32').href = data.site.icon_32; - document.querySelector('#icon_16').href = data.site.icon_16; - document.querySelector('#icon_shortcut').href = data.site.icon_32; - - // navbar - document.querySelector('#navbar_title').innerHTML = 'Logo' + ' ' + data.site.name; - - if (jwt != null) { - const all_communities_item = document.createElement('li'); - all_communities_item.innerHTML = 'All communities' - - const communities_menu = document.createElement('ul'); - communities_menu.className = 'dropdown-menu' - communities_menu.appendChild(all_communities_item) - - if (data.my_user.moderates.length > 0) { - const dropdown_divider = document.createElement('li'); - dropdown_divider.innerHTML = '' - communities_menu.appendChild(dropdown_divider) - const dropdown_header = document.createElement('li'); - dropdown_header.innerHTML = '' - communities_menu.appendChild(dropdown_header) - - for (let mods of data.my_user.moderates) { - let moderated_community_item = document.createElement('li'); - if (mods.community.local) { - moderated_community_item.innerHTML = '' + - mods.community.title + '' + ' (' + mods.community.ap_domain + ')' + - '' - } else { - moderated_community_item.innerHTML = '' + - mods.community.title + '' + ' (' + mods.community.ap_domain + ')' + - '' - } - communities_menu.appendChild(moderated_community_item) - } - } - - if (data.my_user.follows.length > 0) { - const dropdown_divider = document.createElement('li'); - dropdown_divider.innerHTML = '' - communities_menu.appendChild(dropdown_divider) - const dropdown_header = document.createElement('li'); - dropdown_header.innerHTML = '' - communities_menu.appendChild(dropdown_header) - - for (let follows of data.my_user.follows) { - let followed_community_item = document.createElement('li'); - if (follows.community.local) { - followed_community_item.innerHTML = '' + - follows.community.title + '' + ' (' + follows.community.ap_domain + ')' + - '' - } else { - followed_community_item.innerHTML = '' + - follows.community.title + '' + ' (' + follows.community.ap_domain + ')' + - '' - } - communities_menu.appendChild(followed_community_item) - } - } - - const communities_item = document.createElement('li') - communities_item.className = 'nav-item dropdown' - communities_item.innerHTML = '' - communities_item.appendChild(communities_menu) - navbar.appendChild(communities_item) - - const user_settings_item = document.createElement('li') - user_settings_item.className = 'nav-item' - user_settings_item.innerHTML = 'User settings'; - navbar.appendChild(user_settings_item) - - const logout_item = document.createElement('li') - logout_item.className = 'nav-item' - logout_item.innerHTML = 'Log out (via API)'; - navbar.appendChild(logout_item) - } - - // site info - let postlist = document.querySelector('#post_list_request') - if (jwt != null) { - document.querySelector('#site_request').innerHTML = 'GET /api/alpha/site [LOGGED IN]' - if (postlist) { - postlist.innerHTML = 'GET /api/alpha/post/list?type_=Subscribed&sort=New&page=1

' - } - } else { - document.querySelector('#site_request').innerHTML = 'GET /api/alpha/site [LOGGED OUT]' - if (postlist) { - postlist.innerHTML = 'GET /api/alpha/post/list?type_=Popular&sort=Hot&page=1

' - } - } - - document.querySelector('#site_json').textContent = JSON.stringify(data, null, 2); - }) - - -let postlist = document.querySelector('#post_list_request'); -if (postlist) { - if (jwt != null) { - var api_postlist = baseUrl + '/api/alpha/post/list?type_=Subscribed&sort=New&page=1'; - } else { - var api_postlist = baseUrl + '/api/alpha/post/list?type_=Popular&sort=Hot&page=1'; - } - - fetch(api_postlist, request) - .then(response => response.json()) - .then(data => { - document.querySelector('#post_list_json').textContent = JSON.stringify(data, null, 2); - }) -} diff --git a/app/templates/themes/x_api/list_communities.html b/app/templates/themes/x_api/list_communities.html deleted file mode 100644 index 21b3df21..00000000 --- a/app/templates/themes/x_api/list_communities.html +++ /dev/null @@ -1,10 +0,0 @@ -{% extends 'themes/' + theme() + '/base.html' %} - -{% block app_content %} -

-
JSON
-

GET /api/alpha/community/list

-
JSON
- - -{% endblock %} diff --git a/app/templates/themes/x_api/svg/color-modes.svg b/app/templates/themes/x_api/svg/color-modes.svg deleted file mode 100644 index 9c9a3e88..00000000 --- a/app/templates/themes/x_api/svg/color-modes.svg +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/app/templates/themes/x_api/x_api.json b/app/templates/themes/x_api/x_api.json deleted file mode 100644 index eb0ad78c..00000000 --- a/app/templates/themes/x_api/x_api.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "X API", - "debug": true -} diff --git a/app/utils.py b/app/utils.py index 91966a04..52c91a91 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1106,8 +1106,6 @@ def theme_list(): for dir in dirs: if os.path.exists(f'app/templates/themes/{dir}/{dir}.json'): theme_settings = json.loads(file_get_contents(f'app/templates/themes/{dir}/{dir}.json')) - if 'debug' in theme_settings and theme_settings['debug'] == True and not current_app.debug: - continue result.append((dir, theme_settings['name'])) return result