Merge branch 'master' into headers
This commit is contained in:
commit
4637714fc1
18 changed files with 210 additions and 148 deletions
|
@ -16,7 +16,7 @@ services:
|
|||
- SITE_NAME=Drama
|
||||
- CLOUDFLARE_ZONE=vcxvdfgfc6r554etrgd
|
||||
- CLOUDFLARE_KEY=vcxvdfgfc6r554etrgd
|
||||
- TENOR_KEY=vcxvdfgfc6r554etrgd
|
||||
- GIPHY_KEY=vcxvdfgfc6r554etrgd
|
||||
- MAILGUN_KEY=vcxvdfgfc6r554etrgd
|
||||
- MAILGUN_DOMAIN=rdrama.net
|
||||
- FORCE_HTTPS=0
|
||||
|
|
|
@ -37,7 +37,7 @@ app.config['DATABASE_URL'] = environ.get("DATABASE_CONNECTION_POOL_URL",environ.
|
|||
|
||||
app.config['SECRET_KEY'] = environ.get('MASTER_KEY')
|
||||
app.config["SERVER_NAME"] = environ.get("DOMAIN").strip()
|
||||
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 60*10
|
||||
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 31536000
|
||||
|
||||
app.config["SESSION_COOKIE_NAME"] = "session_" + environ.get("SITE_NAME").strip().lower()
|
||||
app.config["VERSION"] = "1.0.0"
|
||||
|
@ -87,8 +87,6 @@ app.config["CACHE_OPTIONS"]={'connection_pool':redispool} if app.config["CACHE_T
|
|||
app.config["READ_ONLY"]=bool(int(environ.get("READ_ONLY", "0")))
|
||||
app.config["BOT_DISABLE"]=bool(int(environ.get("BOT_DISABLE", False)))
|
||||
|
||||
app.config["TENOR_KEY"]=environ.get("TENOR_KEY",'').strip()
|
||||
|
||||
|
||||
Markdown(app)
|
||||
cache = Cache(app)
|
||||
|
@ -261,7 +259,7 @@ def after_request(response):
|
|||
response.headers.add("Referrer-Policy", "same-origin")
|
||||
|
||||
response.headers.add("Feature-Policy", "geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; vibrate 'none'; fullscreen 'none'; payment 'none';")
|
||||
if not request.path.startswith("/embed/"): response.headers.add("X-Frame-Options", "deny")
|
||||
response.headers.add("X-Frame-Options", "deny")
|
||||
|
||||
return response
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -13,11 +13,11 @@ def app_config(x):
|
|||
return app.config.get(x)
|
||||
|
||||
@app.template_filter("post_embed")
|
||||
def crosspost_embed(id):
|
||||
def post_embed(id, v):
|
||||
|
||||
id = int(id)
|
||||
try: id = int(id)
|
||||
except: return None
|
||||
|
||||
p = get_post(id, graceful=True)
|
||||
|
||||
if hasattr(g, 'v') and g.v: return render_template("submission_listing.html", listing=[p], v=g.v)
|
||||
else: return render_template("submission_listing.html", listing=[p], postembed=True)
|
||||
return render_template("submission_listing.html", listing=[p], v=v)
|
|
@ -13,4 +13,5 @@ from .static import *
|
|||
from .users import *
|
||||
from .votes import *
|
||||
from .feeds import *
|
||||
from .awards import *
|
||||
from .awards import *
|
||||
from .giphy import *
|
|
@ -35,8 +35,8 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
|||
|
||||
if not v and "logged_out" not in request.path: return redirect(f"/logged_out/comment/{cid}")
|
||||
|
||||
if v and "logged_out" in request.full_path: return redirect(f"/comment/{cid}")
|
||||
|
||||
if v and "logged_out" in request.full_path: v = None
|
||||
|
||||
try: cid = int(cid)
|
||||
except:
|
||||
try: cid = int(cid, 36)
|
||||
|
|
|
@ -191,7 +191,7 @@ def front_all(v):
|
|||
|
||||
if not v and request.path == "/": return redirect("/logged_out")
|
||||
|
||||
if v and "logged_out" in request.full_path: return redirect("/")
|
||||
if v and "logged_out" in request.full_path: v = None
|
||||
|
||||
try: page = int(request.args.get("page") or 1)
|
||||
except: abort(400)
|
||||
|
|
22
files/routes/giphy.py
Normal file
22
files/routes/giphy.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from flask import *
|
||||
from os import environ
|
||||
import requests
|
||||
|
||||
from files.__main__ import app
|
||||
|
||||
GIPHY_KEY = environ.get('GIPHY_KEY').rstrip()
|
||||
|
||||
|
||||
@app.route("/giphy", methods=["GET"])
|
||||
@app.route("/giphy<path>", methods=["GET"])
|
||||
def giphy():
|
||||
|
||||
searchTerm = request.args.get("searchTerm", "")
|
||||
limit = int(request.args.get("limit", ""))
|
||||
if searchTerm and limit:
|
||||
url = f"https://api.giphy.com/v1/gifs/search?q={searchTerm}&api_key={GIPHY_KEY}&limit={limit}"
|
||||
elif searchTerm and not limit:
|
||||
url = f"https://api.giphy.com/v1/gifs/search?q={searchTerm}&api_key={GIPHY_KEY}&limit=48"
|
||||
else:
|
||||
url = f"https://api.giphy.com/v1/gifs?api_key={GIPHY_KEY}&limit=48"
|
||||
return jsonify(requests.get(url).json())
|
|
@ -125,10 +125,7 @@ def login_post():
|
|||
# check for previous page
|
||||
|
||||
redir = request.form.get("redirect", "/")
|
||||
if redir:
|
||||
return redirect(redir)
|
||||
else:
|
||||
return redirect(account.url)
|
||||
return redirect(redir.replace("/logged_out", ""))
|
||||
|
||||
|
||||
@app.get("/me")
|
||||
|
|
|
@ -54,7 +54,7 @@ def post_id(pid, anything=None, v=None):
|
|||
|
||||
if not v and "logged_out" not in request.path: return redirect(f"/logged_out/post/{pid}")
|
||||
|
||||
if v and "logged_out" in request.full_path: return redirect(f"/post/{pid}")
|
||||
if v and "logged_out" in request.full_path: v = None
|
||||
|
||||
try: pid = int(pid)
|
||||
except Exception as e: pass
|
||||
|
|
|
@ -281,7 +281,7 @@ def u_username(username, v=None):
|
|||
|
||||
if not v and "logged_out" not in request.path: return redirect(f"/logged_out/@{username}")
|
||||
|
||||
if v and "logged_out" in request.full_path: return redirect(f"/@{username}")
|
||||
if v and "logged_out" in request.full_path: v = None
|
||||
|
||||
# username is unique so at most this returns one result. Otherwise 404
|
||||
|
||||
|
@ -402,7 +402,7 @@ def u_username_comments(username, v=None):
|
|||
|
||||
if not v and "logged_out" not in request.path: return redirect(f"/logged_out/@{username}/comments")
|
||||
|
||||
if v and "logged_out" in request.full_path: return redirect(f"/@{username}/comments")
|
||||
if v and "logged_out" in request.full_path: v = None
|
||||
|
||||
# username is unique so at most this returns one result. Otherwise 404
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
<nav class="navbar navbar-expand-md navbar-light shadow shadow-md fixed-top" id="navbar">
|
||||
<div class="container-fluid">
|
||||
<div class="flex-grow-1"><a href="/" class="navbar-brand"><img src="/assets/images/logo.png" height="20"><span class="text-small-extra text-uppercase text-gray-400"> Sigma</span></a></div>
|
||||
<div class="flex-grow-1"><a {% if v %}href="/"{% else %}href="/logged_out"{% endif %} class="navbar-brand"><img src="/assets/images/logo.png" height="20"><span class="text-small-extra text-uppercase text-gray-400"> Sigma</span></a></div>
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -25,11 +25,4 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function tenor_api_key() {
|
||||
return "{{'TENOR_KEY' | app_config}}"
|
||||
}
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<nav class="navbar navbar-expand-md navbar-light shadow shadow-md fixed-top" id="navbar">
|
||||
<div class="container-fluid">
|
||||
<div class="flex-grow-1"><a href="/" class="navbar-brand"><img src="/assets/images/logo.gif" height="20"><span class="text-small-extra text-uppercase text-gray-400"> Sigma</span></a></div>
|
||||
<div class="flex-grow-1"><a {% if v %}href="/"{% else %}href="/logged_out"{% endif %} class="navbar-brand"><img src="/assets/images/logo.gif" height="20"><span class="text-small-extra text-uppercase text-gray-400"> Sigma</span></a></div>
|
||||
<div class="flex-grow-1 d-fl d-none d-md-block">
|
||||
<form class="form-inline search flex-nowrap mx-0 mx-lg-auto" action="/search/posts/" method="get">
|
||||
<input class="form-control w-100" type="search" placeholder="Search" aria-label="Search" name="q" value="{{request.args.get('q', '')}}">
|
||||
|
|
|
@ -9,7 +9,12 @@
|
|||
{% endif %}
|
||||
</script>
|
||||
|
||||
{% if v %}
|
||||
{% set title=p.realtitle(v) %}
|
||||
{% else %}
|
||||
{% set title=p.title %}
|
||||
{% endif %}
|
||||
|
||||
{% set ups=p.upvotes_fuzzed %}
|
||||
{% set downs=p.downvotes_fuzzed %}
|
||||
{% set score=ups-downs %}
|
||||
|
@ -58,7 +63,7 @@
|
|||
<meta property="og:article:author" content="{{'@'+p.author.username}}" />
|
||||
<meta property="article:published_time" content="{{p.created_iso}}" />
|
||||
{% if p.edited_utc %}<meta property="article:modified_time" content="{{p.edited_string}}" />{% endif %}
|
||||
<meta property="og:description" name="description" content="{{p.body}}" />
|
||||
<meta property="og:description" name="description" content="{{p.realbody(V)}}" />
|
||||
<meta property="og:author" name="author" content="{{'@'+p.author.username}}" />
|
||||
<meta property="og:title" content="{{title}} - {{"SITE_NAME" | app_config}}" />
|
||||
<meta property="og:image" content="{% if p.is_image %}{{p.realurl(v)}}{% elif p.has_thumb%}{{p.thumb_url}}{% else %}{{'/assets/images/preview.png' | full_link}}{% endif %}" />
|
||||
|
@ -69,7 +74,7 @@
|
|||
<meta name="twitter:site" content="{{request.host_url}}">
|
||||
<meta name="twitter:title" content="{{title}} - {{"SITE_NAME" | app_config}}" />
|
||||
<meta name="twitter:creator" content="{{'@'+p.author.username}}">
|
||||
<meta name="twitter:description" content="{{p.body}}" />
|
||||
<meta name="twitter:description" content="{{p.realbody(v)}}" />
|
||||
<meta name="twitter:image" content="{% if p.is_image %}{{p.realurl(v)}}{% elif p.has_thumb %}{{p.thumb_url}}{% else %}{{'/assets/images/preview.png' | full_link}}{% endif %}" />
|
||||
<meta name="twitter:url" content="{{p.permalink | full_link}}" />
|
||||
|
||||
|
@ -303,7 +308,7 @@
|
|||
<div class="row no-gutters">
|
||||
<div id="frontpage" class="col-12 pt-0">
|
||||
<div class="posts" id="posts">
|
||||
{{ p.embed_url | post_embed | safe }}
|
||||
{{ p.embed_url | post_embed(v) | safe }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
{% endif %}
|
||||
|
||||
{% block title %}
|
||||
<title>{{p.title}}</title>
|
||||
<title>{{p.realtitle(v)}}</title>
|
||||
{% if p.is_banned %}
|
||||
<meta name="description" content="[removed by admins]">
|
||||
{% else %}
|
||||
|
@ -55,7 +55,7 @@
|
|||
<div id="post-{{p.id}}" class="card d-flex flex-row-reverse flex-nowrap justify-content-end border-0 p-0 {% if voted==1 %} upvoted{% elif voted==-1 %} downvoted{% endif %}">
|
||||
<div class="card-block my-md-auto{% if p.is_banned %} banned{% endif %}">
|
||||
<div class="post-meta text-left d-block d-md-none mb-1">{% if p.over_18 %}<span class="badge badge-danger">+18</span> {% endif %}{% if p.is_banned %}[Removed by admins]{% else %}[Deleted by user]{% endif %}</div>
|
||||
<h5 class="card-title post-title text-left mb-0 mb-md-1">{{p.title}}</h5>
|
||||
<h5 class="card-title post-title text-left mb-0 mb-md-1">{{p.realtitle(v)}}</h5>
|
||||
<div class="post-meta text-left d-none d-md-block">{% if p.over_18 %}<span class="badge badge-danger">+18</span> {% endif %}{% if p.is_banned %}[Removed by admins]{% else %}[Deleted by user]{% endif %}</div>
|
||||
|
||||
</div>
|
||||
|
|
22
giphy.py
Normal file
22
giphy.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from flask import *
|
||||
from os import environ
|
||||
import requests
|
||||
|
||||
from files.__main__ import app
|
||||
|
||||
GIPHY_KEY = environ.get('GIPHY_KEY').rstrip()
|
||||
|
||||
|
||||
@app.route("/giphy", methods=["GET"])
|
||||
@app.route("/giphy<path>", methods=["GET"])
|
||||
def giphy():
|
||||
|
||||
searchTerm = request.args.get("searchTerm", "")
|
||||
limit = int(request.args.get("limit", ""))
|
||||
if searchTerm and limit:
|
||||
url = f"https://api.giphy.com/v1/gifs/search?q={searchTerm}&api_key={GIPHY_KEY}&limit={limit}"
|
||||
elif searchTerm and not limit:
|
||||
url = f"https://api.giphy.com/v1/gifs/search?q={searchTerm}&api_key={GIPHY_KEY}&limit=48"
|
||||
else:
|
||||
url = f"https://api.giphy.com/v1/gifs?api_key={GIPHY_KEY}&limit=48"
|
||||
return jsonify(requests.get(url).json())
|
|
@ -24,7 +24,7 @@ docker-compose up
|
|||
|
||||
4- That's it! Visit `localhost` in your browser.
|
||||
|
||||
5- Optional: to configure the site settings and successsfully integrate it with the external services we use (hcaptcha, cloudflare, discord, tenor and mailgun), please edit the variables in the docker-compose.yml file.
|
||||
5- Optional: to configure the site settings and successsfully integrate it with the external services we use (hcaptcha, cloudflare, discord, giphy and mailgun), please edit the variables in the docker-compose.yml file.
|
||||
|
||||
---
|
||||
|
||||
|
@ -51,7 +51,7 @@ source setup
|
|||
4- That's it. Visit `localhost` in your browser.
|
||||
|
||||
|
||||
5- Optional: to configure the site settings and successsfully integrate it with the external services we use (hcaptcha, cloudflare, discord, tenor and mailgun), please run this command and edit the variables:
|
||||
5- Optional: to configure the site settings and successsfully integrate it with the external services we use (hcaptcha, cloudflare, discord, giphy and mailgun), please run this command and edit the variables:
|
||||
|
||||
```
|
||||
nano /drama/docker-compose.yml
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue