Browse Source

举报功能

master
hole-thu 5 years ago
parent
commit
4408133f43
  1. 28
      hole.py

28
hole.py

@ -112,8 +112,6 @@ def do_post():
cw = request.form.get('cw') cw = request.form.get('cw')
cw = cw.strip() if cw else None cw = cw.strip() if cw else None
print(content, post_type, cw)
if not content or len(content) > 4096: abort(422) if not content or len(content) > 4096: abort(422)
if cw and len(cw)>32: abort(422) if cw and len(cw)>32: abort(422)
@ -233,7 +231,6 @@ def get_attention():
ats = Attention.query.filter_by(name_hash=hash_name(u.name), disabled=False) ats = Attention.query.filter_by(name_hash=hash_name(u.name), disabled=False)
posts = [Post.query.get(at.pid) for at in ats.all()] posts = [Post.query.get(at.pid) for at in ats.all()]
print(posts)
data = [ map_post(post, u.name, 10) data = [ map_post(post, u.name, 10)
for post in posts[::-1] for post in posts[::-1]
if post and not post.deleted if post and not post.deleted
@ -293,21 +290,40 @@ def delete():
def system_log(): def system_log():
u = require_token() u = require_token()
ss = Syslog.query.all() ss = Syslog.query.order_by(db.desc('timestamp')).limit(100).all()
return { return {
'start_time': app.config['START_TIME'], 'start_time': app.config['START_TIME'],
'salt': look(app.config['SALT'][:3]), 'salt': look(app.config['SALT']),
'data' : [{ 'data' : [{
'type': s.log_type, 'type': s.log_type,
'detail': s.log_detail, 'detail': s.log_detail,
'user': look(s.name_hash), 'user': look(s.name_hash),
'timestamp': s.timestamp 'timestamp': s.timestamp
} for s in ss[::-1] } for s in ss
] ]
} }
@app.route('/_api/v1/report', methods=['POST'])
def report():
u = require_token()
pid = request.form.get('pid')
if pid and pid.isdigit():
p = int(pid)
else:
abort(422)
reason = request.form.get('reason', '')
db.session.add(Syslog(
log_type='REPORT',
log_detail=f"pid={pid}\n{reason}",
name_hash=hash_name(u.name)
))
db.session.commit()
return {'code': 0}
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save