fix: 修改后端 api 脚本
This commit is contained in:
+83
-15
@@ -10,8 +10,8 @@ from flask_cors import CORS
|
|||||||
from myUtils.auth import check_cookie
|
from myUtils.auth import check_cookie
|
||||||
from flask import Flask, request, jsonify, Response, render_template, send_from_directory
|
from flask import Flask, request, jsonify, Response, render_template, send_from_directory
|
||||||
from conf import BASE_DIR
|
from conf import BASE_DIR
|
||||||
from myUtils.login import get_tencent_cookie, douyin_cookie_gen, get_ks_cookie
|
from myUtils.login import get_tencent_cookie, douyin_cookie_gen, get_ks_cookie, xiaohongshu_cookie_gen
|
||||||
from myUtils.postVideo import post_video_tencent, post_video_DouYin, post_video_ks
|
from myUtils.postVideo import post_video_tencent, post_video_DouYin, post_video_ks, post_video_xhs
|
||||||
|
|
||||||
active_queues = {}
|
active_queues = {}
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@@ -41,7 +41,6 @@ def hello_world(): # put application's code here
|
|||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
|
||||||
@app.route('/upload', methods=['POST'])
|
@app.route('/upload', methods=['POST'])
|
||||||
@app.route('/api/upload', methods=['POST'])
|
|
||||||
def upload_file():
|
def upload_file():
|
||||||
if 'file' not in request.files:
|
if 'file' not in request.files:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
@@ -67,7 +66,6 @@ def upload_file():
|
|||||||
return jsonify({"code":200,"msg": str(e),"data":None}), 500
|
return jsonify({"code":200,"msg": str(e),"data":None}), 500
|
||||||
|
|
||||||
@app.route('/getFile', methods=['GET'])
|
@app.route('/getFile', methods=['GET'])
|
||||||
@app.route('/api/getFile', methods=['GET'])
|
|
||||||
def get_file():
|
def get_file():
|
||||||
# 获取 filename 参数
|
# 获取 filename 参数
|
||||||
filename = request.args.get('filename')
|
filename = request.args.get('filename')
|
||||||
@@ -87,7 +85,6 @@ def get_file():
|
|||||||
|
|
||||||
|
|
||||||
@app.route('/uploadSave', methods=['POST'])
|
@app.route('/uploadSave', methods=['POST'])
|
||||||
@app.route('/api/uploadSave', methods=['POST'])
|
|
||||||
def upload_save():
|
def upload_save():
|
||||||
if 'file' not in request.files:
|
if 'file' not in request.files:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
@@ -149,7 +146,6 @@ def upload_save():
|
|||||||
}), 500
|
}), 500
|
||||||
|
|
||||||
@app.route('/getFiles', methods=['GET'])
|
@app.route('/getFiles', methods=['GET'])
|
||||||
@app.route('/api/getFiles', methods=['GET'])
|
|
||||||
def get_all_files():
|
def get_all_files():
|
||||||
try:
|
try:
|
||||||
# 使用 with 自动管理数据库连接
|
# 使用 with 自动管理数据库连接
|
||||||
@@ -178,7 +174,6 @@ def get_all_files():
|
|||||||
|
|
||||||
|
|
||||||
@app.route("/getValidAccounts",methods=['GET'])
|
@app.route("/getValidAccounts",methods=['GET'])
|
||||||
@app.route("/api/getValidAccounts",methods=['GET'])
|
|
||||||
async def getValidAccounts():
|
async def getValidAccounts():
|
||||||
with sqlite3.connect(Path(BASE_DIR / "db" / "database.db")) as conn:
|
with sqlite3.connect(Path(BASE_DIR / "db" / "database.db")) as conn:
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
@@ -210,7 +205,6 @@ async def getValidAccounts():
|
|||||||
}),200
|
}),200
|
||||||
|
|
||||||
@app.route('/deleteFile', methods=['GET'])
|
@app.route('/deleteFile', methods=['GET'])
|
||||||
@app.route('/api/deleteFile', methods=['GET'])
|
|
||||||
def delete_file():
|
def delete_file():
|
||||||
file_id = request.args.get('id')
|
file_id = request.args.get('id')
|
||||||
|
|
||||||
@@ -260,10 +254,49 @@ def delete_file():
|
|||||||
"data": None
|
"data": None
|
||||||
}), 500
|
}), 500
|
||||||
|
|
||||||
|
@app.route('/deleteAccount', methods=['GET'])
|
||||||
|
def delete_account():
|
||||||
|
account_id = int(request.args.get('id'))
|
||||||
|
|
||||||
|
try:
|
||||||
|
# 获取数据库连接
|
||||||
|
with sqlite3.connect(Path(BASE_DIR / "db" / "database.db")) as conn:
|
||||||
|
conn.row_factory = sqlite3.Row
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# 查询要删除的记录
|
||||||
|
cursor.execute("SELECT * FROM user_info WHERE id = ?", (account_id,))
|
||||||
|
record = cursor.fetchone()
|
||||||
|
|
||||||
|
if not record:
|
||||||
|
return jsonify({
|
||||||
|
"code": 404,
|
||||||
|
"msg": "account not found",
|
||||||
|
"data": None
|
||||||
|
}), 404
|
||||||
|
|
||||||
|
record = dict(record)
|
||||||
|
|
||||||
|
# 删除数据库记录
|
||||||
|
cursor.execute("DELETE FROM user_info WHERE id = ?", (account_id,))
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"code": 200,
|
||||||
|
"msg": "account deleted successfully",
|
||||||
|
"data": None
|
||||||
|
}), 200
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({
|
||||||
|
"code": 500,
|
||||||
|
"msg": str("delete failed!"),
|
||||||
|
"data": None
|
||||||
|
}), 500
|
||||||
|
|
||||||
|
|
||||||
# SSE 登录接口
|
# SSE 登录接口
|
||||||
@app.route('/login')
|
@app.route('/login')
|
||||||
@app.route('/api/login')
|
|
||||||
def login():
|
def login():
|
||||||
# 1 小红书 2 视频号 3 抖音 4 快手
|
# 1 小红书 2 视频号 3 抖音 4 快手
|
||||||
type = request.args.get('type')
|
type = request.args.get('type')
|
||||||
@@ -288,7 +321,6 @@ def login():
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
@app.route('/postVideo', methods=['POST'])
|
@app.route('/postVideo', methods=['POST'])
|
||||||
@app.route('/api/postVideo', methods=['POST'])
|
|
||||||
def postVideo():
|
def postVideo():
|
||||||
# 获取JSON数据
|
# 获取JSON数据
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
@@ -312,7 +344,8 @@ def postVideo():
|
|||||||
print("Account List:", account_list)
|
print("Account List:", account_list)
|
||||||
match type:
|
match type:
|
||||||
case 1:
|
case 1:
|
||||||
return
|
post_video_xhs(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
||||||
|
start_days)
|
||||||
case 2:
|
case 2:
|
||||||
post_video_tencent(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
post_video_tencent(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
||||||
start_days)
|
start_days)
|
||||||
@@ -323,17 +356,52 @@ def postVideo():
|
|||||||
post_video_ks(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
post_video_ks(title, file_list, tags, account_list, category, enableTimer, videos_per_day, daily_times,
|
||||||
start_days)
|
start_days)
|
||||||
# 返回响应给客户端
|
# 返回响应给客户端
|
||||||
return (jsonify(
|
return jsonify(
|
||||||
{
|
{
|
||||||
"code": 200,
|
"code": 200,
|
||||||
"msg": None,
|
"msg": None,
|
||||||
"data": None
|
"data": None
|
||||||
}), 200
|
}), 200
|
||||||
|
|
||||||
@app.route('/postVideoBatch', methods=['POST']))
|
|
||||||
|
@app.route('/updateUserinfo', methods=['POST'])
|
||||||
|
def updateUserinfo():
|
||||||
|
# 获取JSON数据
|
||||||
|
data = request.get_json()
|
||||||
|
|
||||||
|
# 从JSON数据中提取 type 和 userName
|
||||||
|
user_id = data.get('id')
|
||||||
|
type = data.get('type')
|
||||||
|
userName = data.get('userName')
|
||||||
|
try:
|
||||||
|
# 获取数据库连接
|
||||||
|
with sqlite3.connect(Path(BASE_DIR / "db" / "database.db")) as conn:
|
||||||
|
conn.row_factory = sqlite3.Row
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# 更新数据库记录
|
||||||
|
cursor.execute('''
|
||||||
|
UPDATE user_info
|
||||||
|
SET type = ?,
|
||||||
|
userName = ?
|
||||||
|
WHERE id = ?;
|
||||||
|
''', (type, userName, user_id))
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"code": 200,
|
||||||
|
"msg": "account update successfully",
|
||||||
|
"data": None
|
||||||
|
}), 200
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({
|
||||||
|
"code": 500,
|
||||||
|
"msg": str("update failed!"),
|
||||||
|
"data": None
|
||||||
|
}), 500
|
||||||
|
|
||||||
@app.route('/postVideoBatch', methods=['POST'])
|
@app.route('/postVideoBatch', methods=['POST'])
|
||||||
@app.route('/api/postVideoBatch', methods=['POST'])
|
|
||||||
def postVideoBatch():
|
def postVideoBatch():
|
||||||
data_list = request.get_json()
|
data_list = request.get_json()
|
||||||
|
|
||||||
@@ -383,7 +451,7 @@ def run_async_function(type,id,status_queue):
|
|||||||
case '1':
|
case '1':
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
loop.run_until_complete(get_tencent_cookie(id, status_queue))
|
loop.run_until_complete(xiaohongshu_cookie_gen(id, status_queue))
|
||||||
loop.close()
|
loop.close()
|
||||||
case '2':
|
case '2':
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
|
|||||||
Reference in New Issue
Block a user