TRM-coding | 130f05c | 2025-06-15 16:05:28 +0800 | [diff] [blame] | 1 | from flask import Blueprint, render_template |
| 2 | from .functions.Fpost import Fpost; |
| 3 | from sqlalchemy import create_engine |
| 4 | from sqlalchemy.orm import sessionmaker |
| 5 | from config import Config |
| 6 | from flask import jsonify,request |
| 7 | |
| 8 | main = Blueprint('main', __name__) |
| 9 | |
| 10 | |
| 11 | @main.route('/apostlist',methods=['POST','GET']) |
| 12 | def postlist(): |
| 13 | data=request.get_json() |
TRM-coding | 78aa966 | 2025-06-17 23:40:10 +0800 | [diff] [blame^] | 14 | print(data) |
TRM-coding | 130f05c | 2025-06-15 16:05:28 +0800 | [diff] [blame] | 15 | engine=create_engine(Config.SQLURL) |
| 16 | SessionLocal = sessionmaker(bind=engine) |
| 17 | session = SessionLocal() |
| 18 | f=Fpost(session) |
| 19 | checres=f.checkid(data['userid']) |
| 20 | if(not checres): |
| 21 | return jsonify({'status': 'error', 'message': 'Unauthorized'}) |
| 22 | res=f.getlist() |
| 23 | respons=[] |
| 24 | for datai in res: |
| 25 | respons.append({ |
| 26 | 'id': datai[0], |
| 27 | 'title': datai[1], |
| 28 | 'status': datai[2] |
| 29 | }) |
| 30 | return jsonify(respons) |
| 31 | |
| 32 | @main.route('/agetpost',methods=['POST','GET']) |
| 33 | def post(): |
| 34 | data=request.get_json() |
| 35 | engine=create_engine(Config.SQLURL) |
| 36 | SessionLocal = sessionmaker(bind=engine) |
| 37 | session = SessionLocal() |
| 38 | f=Fpost(session) |
| 39 | checres=f.checkid(data['userid']) |
| 40 | if(not checres): |
| 41 | return jsonify({'status': 'error', 'message': 'Unauthorized'}) |
| 42 | res=f.getpost(data['postid']) |
| 43 | |
| 44 | return jsonify(res.to_dict() if res else {}) |
| 45 | |
| 46 | @main.route('/areview',methods=['POST','GET']) |
| 47 | def review(): |
| 48 | data=request.get_json() |
| 49 | engine=create_engine(Config.SQLURL) |
| 50 | SessionLocal = sessionmaker(bind=engine) |
| 51 | session = SessionLocal() |
| 52 | f=Fpost(session) |
| 53 | checres=f.checkid(data['userid']) |
| 54 | if(not checres): |
| 55 | return jsonify({'status': 'error', 'message': 'Unauthorized'}) |
| 56 | |
| 57 | res=f.review(data['postid'],data['status']) |
| 58 | if not res: |
| 59 | return jsonify({'status': 'error', 'message': 'Post not found'}) |
| 60 | |
| 61 | return jsonify({'status': 'success', 'message': 'Post reviewed successfully'}) |
| 62 | |
| 63 | |
| 64 | |
TRM-coding | 78aa966 | 2025-06-17 23:40:10 +0800 | [diff] [blame^] | 65 | @main.route('/nginxauth',methods=['POST','GET']) |
| 66 | def nginxauth(): |
| 67 | data=request.get_json() |
| 68 | engine=create_engine(Config.SQLURL) |
| 69 | SessionLocal = sessionmaker(bind=engine) |
| 70 | session = SessionLocal() |
| 71 | f=Fpost(session) |
| 72 | checres=f.checkid(data['userid']) |
| 73 | if(not checres): |
| 74 | return jsonify({'status': 'error', 'message': 'Unauthorized'}) |
| 75 | |
| 76 | res=f.nginxauth(data['postid'],data['status']) |
| 77 | if not res: |
| 78 | return jsonify({'status': 'error', 'message': 'Post not found'}) |
| 79 | |
| 80 | return jsonify({'status': 'success', 'message': 'Nginx auth updated successfully'}) |