Initial commit for new v2

This commit is contained in:
Thomas Sileo
2022-06-22 20:11:22 +02:00
commit d528369954
63 changed files with 7961 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
{%- import "utils.html" as utils with context -%}
{% extends "layout.html" %}
{% block content %}
<form action="{{ request.url_for("admin_actions_new") }}" enctype="multipart/form-data" method="POST">
{{ utils.embed_csrf_token() }}
{{ utils.embed_redirect_url() }}
<textarea name="content" rows="10" cols="50" autofocus="autofocus" designMode="on" style="font-size:1.2em;width:95%;"></textarea>
<input name="files" type="file" multiple>
<input type="submit" value="Publish">
</form>
{% endblock %}

View File

@@ -0,0 +1,25 @@
{%- import "utils.html" as utils with context -%}
{% extends "layout.html" %}
{% block content %}
{% for inbox_object in stream %}
{% if inbox_object.ap_type == "Announce" %}
{% if inbox_object.relates_to_inbox_object_id %}
{{ utils.display_object(inbox_object.relates_to_inbox_object) }}
{% else %}
{% endif %}
{% else %}
{{ utils.display_object(inbox_object) }}
{% if inbox_object.liked_via_outbox_object_ap_id %}
{{ utils.admin_undo_button(inbox_object.liked_via_outbox_object_ap_id, "Unlike") }}
{% else %}
{{ utils.admin_like_button(inbox_object.ap_id) }}
{% endif %}
{{ utils.admin_announce_button(inbox_object.ap_id) }}
{% endif %}
{% endfor %}
{% endblock %}

View File

@@ -0,0 +1,12 @@
{%- import "utils.html" as utils -%}
{% extends "layout.html" %}
{% block content %}
{% include "header.html" %}
<div id="followers">
<ul>
{% for follower in followers %}
<li>{{ utils.display_actor(follower.actor, actors_metadata) }}</li>
{% endfor %}
</ul>
</div>
{% endblock %}

View File

@@ -0,0 +1,12 @@
{%- import "utils.html" as utils with context -%}
{% extends "layout.html" %}
{% block content %}
{% include "header.html" %}
<div id="following">
<ul>
{% for follow in following %}
<li>{{ utils.display_actor(follow.actor, actors_metadata) }}</li>
{% endfor %}
</ul>
</div>
{% endblock %}

31
app/templates/header.html Normal file
View File

@@ -0,0 +1,31 @@
<header id="header">
<div class="h-card p-author">
<data class="u-photo" value="{{ local_actor.icon_url }}"></data>
<a href="{{ local_actor.url }}" class="u-url u-uid no-hover title">
<span style="font-size:1.1em;">{{ local_actor.name }}</span>
<span style="font-size:0.85em;" class="subtitle-username">{{ local_actor.handle }}</span>
</a>
<div class="p-note summary">
{{ local_actor.summary | safe }}
</div>
</div>
{%- macro header_link(url, text) -%}
{% set url_for = request.url_for(url) %}
<a href="{{ url_for }}" {% if request.url == url_for %}class="active"{% endif %}>{{ text }}</a>
{% endmacro %}
<div style="margin:30px 0;">
<nav class="flexbox">
<ul>
<li>{{ header_link("index", "Notes") }} <span>{{ objects_count }}</span></li>
<li>{{ header_link("followers", "Followers") }} <span>{{ followers_count }}</span></li>
<li>{{ header_link("following", "Following") }} <span>{{ following_count }}</span></li>
</ul>
</nav>
</header>

14
app/templates/index.html Normal file
View File

@@ -0,0 +1,14 @@
{%- import "utils.html" as utils with context -%}
{% extends "layout.html" %}
{% block content %}
{% include "header.html" %}
{% for outbox_object in objects %}
{{ outbox_object.likes_count }}
{{ outbox_object.announces_count }}
{{ utils.display_object(outbox_object) }}
{% endfor %}
{% endblock %}

46
app/templates/layout.html Normal file
View File

@@ -0,0 +1,46 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="/static/css/main.css">
<style>
{{ highlight_css }}
</style>
</head>
<body>
<div id="main">
<main>
{% if is_admin %}
<div id="admin">
{% macro admin_link(url, text) %}
{% set url_for = request.url_for(url) %}
<a href="{{ url_for }}" {% if request.url == url_for %}class="active"{% endif %}>{{ text }}</a>
{% endmacro %}
<div style="margin-bottom:30px;">
<nav class="flexbox">
<ul>
<li>Admin</li>
<li>{{ admin_link("index", "Public") }}</li>
<li>{{ admin_link("admin_new", "New") }}</li>
<li>{{ admin_link("stream", "Stream") }}</li>
<li>{{ admin_link("get_notifications", "Notifications") }} {% if notifications_count %}({{ notifications_count }}){% endif %}</li>
<li>{{ admin_link("get_lookup", "Lookup") }}</li>
<li><a href="">Bookmarks</a></li>
<li><a href="{{ request.url_for("logout")}}">Logout</a></li>
</ul>
</nav>
</div>
</div>
{% endif %}
{% block content %}{% endblock %}
</main>
</div>
<footer class="footer">
Powered by <a href="https://microblog.pub">microblog.pub</a> <small class="microblogpub-version"><code>{{ microblogpub_version }}</code></small> (<a href="https://github.com/tsileo/microblog.pub">source code</a>) and the <a href="https://activitypub.rocks/">ActivityPub</a> protocol
</footer>
</body>
</html>

13
app/templates/login.html Normal file
View File

@@ -0,0 +1,13 @@
{%- import "utils.html" as utils with context -%}
{% extends "layout.html" %}
{% block content %}
<div style="display:grid;height:80%;">
<div style="margin:auto;">
<form action="/admin/login" method="POST">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
<input type="password" name="password">
<input type="submit" value="Login">
</form>
</div>
</div>
{% endblock %}

14
app/templates/lookup.html Normal file
View File

@@ -0,0 +1,14 @@
{%- import "utils.html" as utils with context -%}
{% extends "layout.html" %}
{% block content %}
<form action="{{ url_for("get_lookup") }}" method="GET">
<input type="text" name="query" value="{{ query if query else "" }}">
<input type="submit" value="Lookup">
</form>
{{ actors_metadata }}
{% if ap_object and ap_object.ap_type == "Person" %}
{{ utils.display_actor(ap_object, actors_metadata) }}
{% elif ap_object %}
{{ utils.display_object(ap_object) }}
{% endif %}
{% endblock %}

View File

@@ -0,0 +1,45 @@
{%- import "utils.html" as utils with context -%}
{% extends "layout.html" %}
{% block content %}
<h2>Notifications</h2>
<div id="notifications">
{%- for notif in notifications %}
<div>
{%- if notif.notification_type.value == "new_follower" %}
<div title="{{ notif.created_at.isoformat() }}">
<a style="font-weight:bold;" href="{{ notif.actor.url }}">{{ notif.actor.name or notif.actor.preferred_username }}</a> followed you
</div>
{{ utils.display_actor(notif.actor, actors_metadata) }}
{% elif notif.notification_type.value == "unfollow" %}
<div title="{{ notif.created_at.isoformat() }}">
<a style="font-weight:bold;" href="{{ notif.actor.url }}">{{ notif.actor.name or notif.actor.preferred_username }}</a> unfollowed you
</div>
{{ utils.display_actor(notif.actor, actors_metadata) }}
{% elif notif.notification_type.value == "like" %}
<div title="{{ notif.created_at.isoformat() }}">
<a style="font-weight:bold;" href="{{ notif.actor.url }}">{{ notif.actor.name or notif.actor.preferred_username }}</a> liked a post
</div>
{{ utils.display_object(notif.outbox_object) }}
{% elif notif.notification_type.value == "undo_like" %}
<div title="{{ notif.created_at.isoformat() }}">
<a style="font-weight:bold;" href="{{ notif.actor.url }}">{{ notif.actor.name or notif.actor.preferred_username }}</a> un-liked a post
</div>
{{ utils.display_object(notif.outbox_object) }}
{% elif notif.notification_type.value == "announce" %}
<div title="{{ notif.created_at.isoformat() }}">
<a style="font-weight:bold;" href="{{ notif.actor.url }}">{{ notif.actor.name or notif.actor.preferred_username }}</a> boosted a post
</div>
{{ utils.display_object(notif.outbox_object) }}
{% elif notif.notification_type.value == "undo_announce" %}
<div title="{{ notif.created_at.isoformat() }}">
<a style="font-weight:bold;" href="{{ notif.actor.url }}">{{ notif.actor.name or notif.actor.preferred_username }}</a> un-boosted a post
</div>
{{ utils.display_object(notif.outbox_object) }}
{% else %}
{{ notif }}
{%- endif %}
</div>
{%- endfor %}
</div>
{% endblock %}

View File

@@ -0,0 +1,8 @@
{%- import "utils.html" as utils with context -%}
{% extends "layout.html" %}
{% block content %}
{% include "header.html" %}
{{ utils.display_object(outbox_object) }}
{% endblock %}

143
app/templates/utils.html Normal file
View File

@@ -0,0 +1,143 @@
{% macro embed_csrf_token() %}
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
{% endmacro %}
{% macro embed_redirect_url() %}
<input type="hidden" name="redirect_url" value="{{ request.url }}">
{% endmacro %}
{% macro admin_follow_button(actor) %}
<form action="{{ request.url_for("admin_actions_follow") }}" method="POST">
{{ embed_csrf_token() }}
{{ embed_redirect_url() }}
<input type="hidden" name="ap_actor_id" value="{{ actor.ap_id }}">
<input type="submit" value="Follow">
</form>
{% endmacro %}
{% macro admin_like_button(ap_object_id) %}
<form action="{{ request.url_for("admin_actions_like") }}" method="POST">
{{ embed_csrf_token() }}
{{ embed_redirect_url() }}
<input type="hidden" name="ap_object_id" value="{{ ap_object_id }}">
<input type="submit" value="Like">
</form>
{% endmacro %}
{% macro admin_announce_button(ap_object_id) %}
<form action="{{ request.url_for("admin_actions_announce") }}" method="POST">
{{ embed_csrf_token() }}
{{ embed_redirect_url() }}
<input type="hidden" name="ap_object_id" value="{{ ap_object_id }}">
<input type="submit" value="Announce">
</form>
{% endmacro %}
{% macro admin_undo_button(ap_object_id, action="Undo") %}
<form action="{{ request.url_for("admin_actions_undo") }}" method="POST">
{{ embed_csrf_token() }}
{{ embed_redirect_url() }}
<input type="hidden" name="ap_object_id" value="{{ ap_object_id }}">
<input type="submit" value="{{ action }}">
</form>
{% endmacro %}
{% macro sensitive_button(permalink_id) %}
<form action="" method="GET">
<input type="hidden" name="show_sensitive" value="{{ permalink_id }}">
{% for k, v in request.query_params.items() %}
<input type="hidden" name="{{k}}" value="{{v}}">
{% endfor %}
<button type="submit">display sensitive content</button>
</form>
{% endmacro %}
{% macro display_actor(actor, actors_metadata) %}
{{ actors_metadata }}
{% set metadata = actors_metadata.get(actor.ap_id) %}
<div style="display: flex;column-gap: 20px;margin:20px 0 10px 0;" class="actor-box">
<div style="flex: 0 0 48px;">
<img src="{{ actor.icon_url | media_proxy_url }}" style="max-width:45px;">
</div>
<a href="{{ actor.url }}" style="">
<div><strong>{{ actor.name or actor.preferred_username }}</strong></div>
<div>{{ actor.handle }}</div>
</a>
</div>
{% if metadata %}
<div>
<nav class="flexbox">
<ul>
<li>
{% if metadata.is_following %}already following {{ admin_undo_button(metadata.outbox_follow_ap_id, "Unfollow")}}
{% elif metadata.is_follow_request_sent %}follow request sent
{% else %}
{{ admin_follow_button(actor) }}
{% endif %}
</li>
<li>
{% if metadata.is_follower %}follows you{% else %}
{% endif %}
</li>
</ul>
</nav>
</div>
{% endif %}
{% endmacro %}
{% macro display_object(object) %}
{% if object.ap_type in ["Note", "Article", "Video"] %}
<div class="activity-wrap" id="{{ object.permalink_id }}">
<div class="activity-content">
<img src="{% if object.actor.icon_url %}{{ object.actor.icon_url | media_proxy_url }}{% else %}/static/nopic.png{% endif %}" alt="" class="actor-icon">
<div class="activity-header">
<strong>{{ object.actor.name or object.actor.preferred_username }}</strong>
<span>{{ object.actor.handle }}</span>
<span class="activity-date" title="{{ object.ap_published_at.isoformat() }}">
<a href="{{ object.url }}">{{ object.ap_published_at | timeago }}</a>
</span>
<div class="activity-main">
{{ object.content | clean_html | safe }}
</div>
</div>
</div>
{% if object.attachments and object.sensitive and not request.query_params["show_sensitive"] == object.permalink_id %}
<div class="activity-attachment">
{{ sensitive_button(object.permalink_id )}}
</div>
{% endif %}
{% if object.attachments and (not object.sensitive or (object.sensitive and request.query_params["show_sensitive"] == object.permalink_id)) %}
<div class="activity-attachment">
{% for attachment in object.attachments %}
{% if attachment.type == "Image" or (attachment | has_media_type("image")) %}
<img src="{{ attachment.url | media_proxy_url }}"{% if attachment.name %} alt="{{ attachment.name }}"{% endif %} class="attachment">
{% elif attachment.type == "Video" or (attachment | has_media_type("video")) %}
<video controls preload="metadata" src="{{ attachment.url | media_proxy_url }}"{% if attachment.name %} title="{{ attachment.name }}"{% endif %} class="attachmeent"></video>
{% elif attachment.type == "Audio" or (attachment | has_media_type("audio")) %}
<audio controls preload="metadata" src="{{ attachment.url | media_proxy_url }}"{% if attachment.name%} title="{{ attachment.name }}"{% endif %} style="width:480px;" class="attachment"></audio>
{% else %}
<a href="{{ attachment.url | media_proxy_url }}"{% if attachment.name %} title="{{ attachment.name }}"{% endif %} class="attachment">{{ attachment.url }}</a>
{% endif %}
{% endfor %}
</div>
{% endif %}
<div class="activity-bar">
<div class="bar-item">
<div class="comment-count">33</div>
</div>
<div class="bar-item">
<div class="retweet-count">397</div>
</div>
<div class="bar-item">
<div class="likes-count">
2.6k
</div>
</div>
</div>
</div>
{% endif %}
{% endmacro %}