remotes/1693045480750635534/spooky-22
Aevann1 2022-03-22 02:56:41 +02:00
parent 1bbb462025
commit 30c8410500
5 changed files with 36 additions and 15 deletions

View File

@ -1,6 +1,8 @@
from files.helpers.const import SITE
if SITE=='pcmemes.net':
if SITE in ('pcmemes.net', 'localhost'):
count = 0
import time
from files.helpers.wrappers import auth_required
from files.helpers.sanitize import sanitize
@ -10,15 +12,14 @@ if SITE=='pcmemes.net':
from flask import render_template
import sys
socketio = SocketIO(app, async_mode='gevent')
@app.get("/chat")
@auth_required
def chat( v):
return render_template("chat.html", v=v)
sex = SocketIO(app, async_mode='gevent')
@sex.on('speak')
@socketio.on('speak')
@auth_required
def speak(data, v):
@ -27,9 +28,20 @@ if SITE=='pcmemes.net':
"username":v.username,
"namecolor":v.namecolor,
"text":sanitize(data[:1000].strip()),
"time": time.strftime("%d %b %Y at %H:%M:%S", time.gmtime(int(time.time()))),
"userlink":v.url
"time": time.strftime("%d %b %Y at %H:%M:%S", time.gmtime(int(time.time())))
}
emit('speak', data, broadcast=True)
return '', 204
return '', 204
@socketio.on('connect')
def connect():
global count
count += 1
emit("count", count)
@socketio.on('disconnect')
def disconnect():
global count
count -= 1
emit("count", count)

View File

@ -89,7 +89,7 @@ def upvoters_posts(v, username, uid):
page = max(1, int(request.values.get("page", 1)))
listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Vote.vote_type==1, Submission.author_id==id, Vote.user_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost==False, Vote.vote_type==1, Submission.author_id==id, Vote.user_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = [p.id for p in listing]
next_exists = len(listing) > 25
@ -108,7 +108,7 @@ def upvoters_comments(v, username, uid):
page = max(1, int(request.values.get("page", 1)))
listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==1, Comment.author_id==id, CommentVote.user_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost==False, CommentVote.vote_type==1, Comment.author_id==id, CommentVote.user_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = [c.id for c in listing]
next_exists = len(listing) > 25
@ -126,7 +126,7 @@ def downvoters_posts(v, username, uid):
uid = int(uid)
page = max(1, int(request.values.get("page", 1)))
listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Vote.vote_type==-1, Submission.author_id==id, Vote.user_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost==False, Vote.vote_type==-1, Submission.author_id==id, Vote.user_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = [p.id for p in listing]
next_exists = len(listing) > 25
@ -144,7 +144,7 @@ def downvoters_comments(v, username, uid):
uid = int(uid)
page = max(1, int(request.values.get("page", 1)))
listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==-1, Comment.author_id==id, CommentVote.user_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost==False, CommentVote.vote_type==-1, Comment.author_id==id, CommentVote.user_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
listing = [c.id for c in listing]
next_exists = len(listing) > 25

View File

@ -7,6 +7,13 @@
{% block content %}
<div class="border-right py-3 px-3">
<span data-toggle="tooltip" data-placement="bottom" title="people online right now" class="text-muted">
<i class="far fa-user fa-sm mr-1"></i>
<span class="board-chat-count">0</span>
</span>
</div>
<div id="chat-line-template" class="d-none">
<div class="chat-line my-2">
<div class="d-flex align-items-center">
@ -42,12 +49,12 @@
<span id="loading-indicator" class="d-none"></span>
</div>
<input id="input-text" type="text" class="form-control" placeholder="Message" autocomplete="off" autofocus />
<button id="chatsend" class="btn btn-primary ml-3" type="submit">Send</button>
<button id="chatsend" onclick="send()" class="btn btn-primary ml-3" type="submit">Send</button>
</div>
</div>
<script src="/assets/js/socketio.js"></script>
<script src="/assets/js/chat.js?v=12"></script>
<script src="/assets/js/chat.js?v=13"></script>
<style>

View File

@ -5,7 +5,9 @@ Flask-Caching
Flask-Compress
Flask-Limiter
Flask-Mail
Flask-Socketio
gevent
gevent-websocket
greenlet
gunicorn
lxml

View File

@ -5,7 +5,7 @@ logfile=/tmp/supervisord.log
[program:service]
directory=/service
command=gunicorn files.__main__:app -k gevent -w 1 --reload -b 0.0.0.0:80 --max-requests 1000 --max-requests-jitter 500
command=gunicorn files.__main__:app -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 --reload -b 0.0.0.0:80 --max-requests 1000 --max-requests-jitter 500
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr