fix: 修改后端 api 脚本
Browse files- sau_backend/app.py +83 -15
sau_backend/app.py
CHANGED
|
@@ -10,8 +10,8 @@ from flask_cors import CORS
|
|
| 10 |
from myUtils.auth import check_cookie
|
| 11 |
from flask import Flask, request, jsonify, Response, render_template, send_from_directory
|
| 12 |
from conf import BASE_DIR
|
| 13 |
-
from myUtils.login import get_tencent_cookie, douyin_cookie_gen, get_ks_cookie
|
| 14 |
-
from myUtils.postVideo import post_video_tencent, post_video_DouYin, post_video_ks
|
| 15 |
|
| 16 |
active_queues = {}
|
| 17 |
app = Flask(__name__)
|
|
@@ -41,7 +41,6 @@ def hello_world(): # put application's code here
|
|
| 41 |
return render_template('index.html')
|
| 42 |
|
| 43 |
@app.route('/upload', methods=['POST'])
|
| 44 |
-
@app.route('/api/upload', methods=['POST'])
|
| 45 |
def upload_file():
|
| 46 |
if 'file' not in request.files:
|
| 47 |
return jsonify({
|
|
@@ -67,7 +66,6 @@ def upload_file():
|
|
| 67 |
return jsonify({"code":200,"msg": str(e),"data":None}), 500
|
| 68 |
|
| 69 |
@app.route('/getFile', methods=['GET'])
|
| 70 |
-
@app.route('/api/getFile', methods=['GET'])
|
| 71 |
def get_file():
|
| 72 |
# 获取 filename 参数
|
| 73 |
filename = request.args.get('filename')
|
|
@@ -87,7 +85,6 @@ def get_file():
|
|
| 87 |
|
| 88 |
|
| 89 |
@app.route('/uploadSave', methods=['POST'])
|
| 90 |
-
@app.route('/api/uploadSave', methods=['POST'])
|
| 91 |
def upload_save():
|
| 92 |
if 'file' not in request.files:
|
| 93 |
return jsonify({
|
|
@@ -149,7 +146,6 @@ def upload_save():
|
|
| 149 |
}), 500
|
| 150 |
|
| 151 |
@app.route('/getFiles', methods=['GET'])
|
| 152 |
-
@app.route('/api/getFiles', methods=['GET'])
|
| 153 |
def get_all_files():
|
| 154 |
try:
|
| 155 |
# 使用 with 自动管理数据库连接
|
|
@@ -178,7 +174,6 @@ def get_all_files():
|
|
| 178 |
|
| 179 |
|
| 180 |
@app.route("/getValidAccounts",methods=['GET'])
|
| 181 |
-
@app.route("/api/getValidAccounts",methods=['GET'])
|
| 182 |
async def getValidAccounts():
|
| 183 |
with sqlite3.connect(Path(BASE_DIR / "db" / "database.db")) as conn:
|
| 184 |
cursor = conn.cursor()
|
|
@@ -210,7 +205,6 @@ async def getValidAccounts():
|
|
| 210 |
}),200
|
| 211 |
|
| 212 |
@app.route('/deleteFile', methods=['GET'])
|
| 213 |
-
@app.route('/api/deleteFile', methods=['GET'])
|
| 214 |
def delete_file():
|
| 215 |
file_id = request.args.get('id')
|
| 216 |
|
|
@@ -260,10 +254,49 @@ def delete_file():
|
|
| 260 |
"data": None
|
| 261 |
}), 500
|
| 262 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
# SSE 登录接口
|
| 265 |
@app.route('/login')
|
| 266 |
-
@app.route('/api/login')
|
| 267 |
def login():
|
| 268 |
# 1 小红书 2 视频号 3 抖音 4 快手
|
| 269 |
type = request.args.get('type')
|
|
@@ -288,7 +321,6 @@ def login():
|
|
| 288 |
return response
|
| 289 |
|
| 290 |
@app.route('/postVideo', methods=['POST'])
|
| 291 |
-
@app.route('/api/postVideo', methods=['POST'])
|
| 292 |
def postVideo():
|
| 293 |
# 获取JSON数据
|
| 294 |
data = request.get_json()
|
|
@@ -312,7 +344,8 @@ def postVideo():
|
|
| 312 |
print("Account List:", account_list)
|
| 313 |
match type:
|
| 314 |
case 1:
|
| 315 |
-
|
|
|
|
| 316 |
case 2:
|
| 317 |
post_video_tencent(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
| 318 |
start_days)
|
|
@@ -323,17 +356,52 @@ def postVideo():
|
|
| 323 |
post_video_ks(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
| 324 |
start_days)
|
| 325 |
# 返回响应给客户端
|
| 326 |
-
return
|
| 327 |
{
|
| 328 |
"code": 200,
|
| 329 |
"msg": None,
|
| 330 |
"data": None
|
| 331 |
}), 200
|
| 332 |
|
| 333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
|
| 335 |
@app.route('/postVideoBatch', methods=['POST'])
|
| 336 |
-
@app.route('/api/postVideoBatch', methods=['POST'])
|
| 337 |
def postVideoBatch():
|
| 338 |
data_list = request.get_json()
|
| 339 |
|
|
@@ -383,7 +451,7 @@ def run_async_function(type,id,status_queue):
|
|
| 383 |
case '1':
|
| 384 |
loop = asyncio.new_event_loop()
|
| 385 |
asyncio.set_event_loop(loop)
|
| 386 |
-
loop.run_until_complete(
|
| 387 |
loop.close()
|
| 388 |
case '2':
|
| 389 |
loop = asyncio.new_event_loop()
|
|
|
|
| 10 |
from myUtils.auth import check_cookie
|
| 11 |
from flask import Flask, request, jsonify, Response, render_template, send_from_directory
|
| 12 |
from conf import BASE_DIR
|
| 13 |
+
from myUtils.login import get_tencent_cookie, douyin_cookie_gen, get_ks_cookie, xiaohongshu_cookie_gen
|
| 14 |
+
from myUtils.postVideo import post_video_tencent, post_video_DouYin, post_video_ks, post_video_xhs
|
| 15 |
|
| 16 |
active_queues = {}
|
| 17 |
app = Flask(__name__)
|
|
|
|
| 41 |
return render_template('index.html')
|
| 42 |
|
| 43 |
@app.route('/upload', methods=['POST'])
|
|
|
|
| 44 |
def upload_file():
|
| 45 |
if 'file' not in request.files:
|
| 46 |
return jsonify({
|
|
|
|
| 66 |
return jsonify({"code":200,"msg": str(e),"data":None}), 500
|
| 67 |
|
| 68 |
@app.route('/getFile', methods=['GET'])
|
|
|
|
| 69 |
def get_file():
|
| 70 |
# 获取 filename 参数
|
| 71 |
filename = request.args.get('filename')
|
|
|
|
| 85 |
|
| 86 |
|
| 87 |
@app.route('/uploadSave', methods=['POST'])
|
|
|
|
| 88 |
def upload_save():
|
| 89 |
if 'file' not in request.files:
|
| 90 |
return jsonify({
|
|
|
|
| 146 |
}), 500
|
| 147 |
|
| 148 |
@app.route('/getFiles', methods=['GET'])
|
|
|
|
| 149 |
def get_all_files():
|
| 150 |
try:
|
| 151 |
# 使用 with 自动管理数据库连接
|
|
|
|
| 174 |
|
| 175 |
|
| 176 |
@app.route("/getValidAccounts",methods=['GET'])
|
|
|
|
| 177 |
async def getValidAccounts():
|
| 178 |
with sqlite3.connect(Path(BASE_DIR / "db" / "database.db")) as conn:
|
| 179 |
cursor = conn.cursor()
|
|
|
|
| 205 |
}),200
|
| 206 |
|
| 207 |
@app.route('/deleteFile', methods=['GET'])
|
|
|
|
| 208 |
def delete_file():
|
| 209 |
file_id = request.args.get('id')
|
| 210 |
|
|
|
|
| 254 |
"data": None
|
| 255 |
}), 500
|
| 256 |
|
| 257 |
+
@app.route('/deleteAccount', methods=['GET'])
|
| 258 |
+
def delete_account():
|
| 259 |
+
account_id = int(request.args.get('id'))
|
| 260 |
+
|
| 261 |
+
try:
|
| 262 |
+
# 获取数据库连接
|
| 263 |
+
with sqlite3.connect(Path(BASE_DIR / "db" / "database.db")) as conn:
|
| 264 |
+
conn.row_factory = sqlite3.Row
|
| 265 |
+
cursor = conn.cursor()
|
| 266 |
+
|
| 267 |
+
# 查询要删除的记录
|
| 268 |
+
cursor.execute("SELECT * FROM user_info WHERE id = ?", (account_id,))
|
| 269 |
+
record = cursor.fetchone()
|
| 270 |
+
|
| 271 |
+
if not record:
|
| 272 |
+
return jsonify({
|
| 273 |
+
"code": 404,
|
| 274 |
+
"msg": "account not found",
|
| 275 |
+
"data": None
|
| 276 |
+
}), 404
|
| 277 |
+
|
| 278 |
+
record = dict(record)
|
| 279 |
+
|
| 280 |
+
# 删除数据库记录
|
| 281 |
+
cursor.execute("DELETE FROM user_info WHERE id = ?", (account_id,))
|
| 282 |
+
conn.commit()
|
| 283 |
+
|
| 284 |
+
return jsonify({
|
| 285 |
+
"code": 200,
|
| 286 |
+
"msg": "account deleted successfully",
|
| 287 |
+
"data": None
|
| 288 |
+
}), 200
|
| 289 |
+
|
| 290 |
+
except Exception as e:
|
| 291 |
+
return jsonify({
|
| 292 |
+
"code": 500,
|
| 293 |
+
"msg": str("delete failed!"),
|
| 294 |
+
"data": None
|
| 295 |
+
}), 500
|
| 296 |
+
|
| 297 |
|
| 298 |
# SSE 登录接口
|
| 299 |
@app.route('/login')
|
|
|
|
| 300 |
def login():
|
| 301 |
# 1 小红书 2 视频号 3 抖音 4 快手
|
| 302 |
type = request.args.get('type')
|
|
|
|
| 321 |
return response
|
| 322 |
|
| 323 |
@app.route('/postVideo', methods=['POST'])
|
|
|
|
| 324 |
def postVideo():
|
| 325 |
# 获取JSON数据
|
| 326 |
data = request.get_json()
|
|
|
|
| 344 |
print("Account List:", account_list)
|
| 345 |
match type:
|
| 346 |
case 1:
|
| 347 |
+
post_video_xhs(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
| 348 |
+
start_days)
|
| 349 |
case 2:
|
| 350 |
post_video_tencent(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
| 351 |
start_days)
|
|
|
|
| 356 |
post_video_ks(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
| 357 |
start_days)
|
| 358 |
# 返回响应给客户端
|
| 359 |
+
return jsonify(
|
| 360 |
{
|
| 361 |
"code": 200,
|
| 362 |
"msg": None,
|
| 363 |
"data": None
|
| 364 |
}), 200
|
| 365 |
|
| 366 |
+
|
| 367 |
+
@app.route('/updateUserinfo', methods=['POST'])
|
| 368 |
+
def updateUserinfo():
|
| 369 |
+
# 获取JSON数据
|
| 370 |
+
data = request.get_json()
|
| 371 |
+
|
| 372 |
+
# 从JSON数据中提取 type 和 userName
|
| 373 |
+
user_id = data.get('id')
|
| 374 |
+
type = data.get('type')
|
| 375 |
+
userName = data.get('userName')
|
| 376 |
+
try:
|
| 377 |
+
# 获取数据库连接
|
| 378 |
+
with sqlite3.connect(Path(BASE_DIR / "db" / "database.db")) as conn:
|
| 379 |
+
conn.row_factory = sqlite3.Row
|
| 380 |
+
cursor = conn.cursor()
|
| 381 |
+
|
| 382 |
+
# 更新数据库记录
|
| 383 |
+
cursor.execute('''
|
| 384 |
+
UPDATE user_info
|
| 385 |
+
SET type = ?,
|
| 386 |
+
userName = ?
|
| 387 |
+
WHERE id = ?;
|
| 388 |
+
''', (type, userName, user_id))
|
| 389 |
+
conn.commit()
|
| 390 |
+
|
| 391 |
+
return jsonify({
|
| 392 |
+
"code": 200,
|
| 393 |
+
"msg": "account update successfully",
|
| 394 |
+
"data": None
|
| 395 |
+
}), 200
|
| 396 |
+
|
| 397 |
+
except Exception as e:
|
| 398 |
+
return jsonify({
|
| 399 |
+
"code": 500,
|
| 400 |
+
"msg": str("update failed!"),
|
| 401 |
+
"data": None
|
| 402 |
+
}), 500
|
| 403 |
|
| 404 |
@app.route('/postVideoBatch', methods=['POST'])
|
|
|
|
| 405 |
def postVideoBatch():
|
| 406 |
data_list = request.get_json()
|
| 407 |
|
|
|
|
| 451 |
case '1':
|
| 452 |
loop = asyncio.new_event_loop()
|
| 453 |
asyncio.set_event_loop(loop)
|
| 454 |
+
loop.run_until_complete(xiaohongshu_cookie_gen(id, status_queue))
|
| 455 |
loop.close()
|
| 456 |
case '2':
|
| 457 |
loop = asyncio.new_event_loop()
|