新增外链管理功能,完善外链创建、删除和获取接口,优化扫码登录逻辑,添加到期时间支持,更新前端页面以增强用户体验,确保外链使用次数和有效期的正确管理。
This commit is contained in:
parent
47839acb75
commit
aad2182d0c
0
.python-version
Normal file
0
.python-version
Normal file
1
.python-version
Normal file
1
.python-version
Normal file
@ -0,0 +1 @@
|
|||||||
|
python3.10
|
29
README.md
29
README.md
@ -42,4 +42,31 @@ flask
|
|||||||
2. 总额度: 数字
|
2. 总额度: 数字
|
||||||
3. 已使用额度: 数字
|
3. 已使用额度: 数字
|
||||||
4. 外链编码: 随机uuid-不重复
|
4. 外链编码: 随机uuid-不重复
|
||||||
5. 备注
|
5. 备注
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
完善外链管理功能
|
||||||
|
注意:不要轻易更改 datebase.py
|
||||||
|
1. 点击添加外链弹出模态框,网盘类型从[所有网盘服务商]获取里边的provider_name展示到下拉框
|
||||||
|
2. 当选中后,通过选项在[网盘账号管理]里筛选当前选项的网盘驱动账号
|
||||||
|
3. 配置完成点击保存后,生成外链地址例如 /exlink/ + uuid
|
||||||
|
4. 每访问#3获取的外链地址1次,相应的在剩余次数里-1,当次数为0时候[1. 外链显示禁用。2. 访问外链提示已经禁用]
|
||||||
|
|
||||||
|
|
||||||
|
问题
|
||||||
|
1. 添加外链并且保存后弹出两条信息,一条成功、一条”外链添加失败: 缺少必要的drive_id参数“
|
||||||
|
2. 网盘外链功能
|
||||||
|
1. 功能我已经实现,在index.html里
|
||||||
|
2. 复制一份作为网盘外链页面,每点击外链页面的【开始扫码】按钮[xpath为//*[@id="scan-button"]],并且扫码成功,则外链剩余次数-1
|
||||||
|
3. 页面显示剩余次数和剩余时间倒计时【例如:剩余时间 x时x分x秒,如果有天,前面加x天】
|
||||||
|
|
||||||
|
|
||||||
|
问题
|
||||||
|
1. 外链页面
|
||||||
|
正确:每扫码成功,并且登录成功,次数-1。
|
||||||
|
错误:访问一次,次数-1
|
||||||
|
2. 添加外链时候,需要配置到期时间,访问外链页面需要根据到期时间显示倒计时
|
||||||
|
|
||||||
|
添加网盘外链报错
|
||||||
|
创建外链错误: table external_links has no column named expiry_time
|
BIN
database.db
BIN
database.db
Binary file not shown.
265
main.py
265
main.py
@ -100,16 +100,102 @@ def login():
|
|||||||
# 获取POST请求中的JSON数据
|
# 获取POST请求中的JSON数据
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
token = data.get('token')
|
token = data.get('token')
|
||||||
|
link_uuid = data.get('link_uuid')
|
||||||
|
|
||||||
if not token:
|
if not token:
|
||||||
print('缺少token参数')
|
print('缺少token参数')
|
||||||
return jsonify({"status": False, "message": "缺少token参数"})
|
return jsonify({"status": False, "message": "缺少token参数"})
|
||||||
status = login_quark(token)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 如果有外链UUID,则更新其使用次数
|
||||||
|
if link_uuid:
|
||||||
|
db = get_db()
|
||||||
|
# 获取当前外链信息
|
||||||
|
link_info = db.get_external_link_by_uuid(link_uuid)
|
||||||
|
|
||||||
|
if link_info:
|
||||||
|
# 获取当前已使用次数和总次数
|
||||||
|
used_quota = link_info.get('used_quota', 0)
|
||||||
|
total_quota = link_info.get('total_quota', 0)
|
||||||
|
exdrive_id = link_info.get('drive_id',0)
|
||||||
|
|
||||||
|
# 确保不超过总次数
|
||||||
|
if used_quota < total_quota:
|
||||||
|
|
||||||
|
# 根据exdrive_id从drive_providers表查询config_vars
|
||||||
|
drive_info = db.get_user_drive(exdrive_id)
|
||||||
|
print(drive_info)
|
||||||
|
if drive_info:
|
||||||
|
config_vars = drive_info.get("login_config")
|
||||||
|
status = login_quark(token,config_vars)
|
||||||
|
|
||||||
|
# 增加使用次数
|
||||||
|
new_used_quota = used_quota + 1
|
||||||
|
update_success = db.update_external_link_quota(link_uuid, new_used_quota)
|
||||||
|
if update_success:
|
||||||
|
print(f"已更新外链 {link_uuid} 的使用次数: {new_used_quota}/{total_quota}")
|
||||||
|
|
||||||
return jsonify({"status": status})
|
return jsonify({"status": status})
|
||||||
|
|
||||||
@app.route('/exlink/<string:id>')
|
@app.route('/exlink/<string:id>')
|
||||||
def qrlink(id):
|
def qrlink(id):
|
||||||
info = exlink_info
|
db = get_db()
|
||||||
return info
|
data = {"status": False}
|
||||||
|
|
||||||
|
# 获取外链信息
|
||||||
|
link_info = db.get_external_link_by_uuid(id)
|
||||||
|
|
||||||
|
if link_info:
|
||||||
|
# 检查是否已过期
|
||||||
|
from datetime import datetime
|
||||||
|
expiry_time = link_info.get('expiry_time')
|
||||||
|
if expiry_time:
|
||||||
|
try:
|
||||||
|
expiry_datetime = datetime.strptime(expiry_time, '%Y-%m-%d %H:%M:%S')
|
||||||
|
if datetime.now() > expiry_datetime:
|
||||||
|
data["message"] = "此外链已过期"
|
||||||
|
return render_template('exlink_error.html', message=data["message"])
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
# 如果日期格式有误,忽略过期检查
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 检查使用次数是否超过限制
|
||||||
|
used_quota = link_info.get('used_quota', 0)
|
||||||
|
total_quota = link_info.get('total_quota', 0)
|
||||||
|
|
||||||
|
if used_quota < total_quota:
|
||||||
|
# 不再自动增加使用次数,而是由扫码登录成功后增加
|
||||||
|
# 获取关联的网盘信息
|
||||||
|
drive_id = link_info.get('drive_id')
|
||||||
|
drive_info = db.get_user_drive(drive_id)
|
||||||
|
|
||||||
|
if drive_info:
|
||||||
|
data["status"] = True
|
||||||
|
data["drive_info"] = {
|
||||||
|
"provider_name": drive_info.get('provider_name'),
|
||||||
|
"login_config": drive_info.get('login_config')
|
||||||
|
}
|
||||||
|
data["message"] = "外链访问成功"
|
||||||
|
data["remaining"] = total_quota - used_quota
|
||||||
|
|
||||||
|
# 返回页面和网盘信息
|
||||||
|
return render_template('exlink_view.html',
|
||||||
|
link_info=link_info,
|
||||||
|
drive_info=drive_info,
|
||||||
|
remaining_count=total_quota - used_quota,
|
||||||
|
expiry_time=link_info.get('expiry_time'))
|
||||||
|
else:
|
||||||
|
data["message"] = "找不到关联的网盘信息"
|
||||||
|
else:
|
||||||
|
data["message"] = "此外链已达到使用次数限制"
|
||||||
|
else:
|
||||||
|
data["message"] = "无效的外链ID"
|
||||||
|
|
||||||
|
# 如果失败,返回错误页面
|
||||||
|
return render_template('exlink_error.html', message=data["message"])
|
||||||
|
|
||||||
|
|
||||||
@app.route('/admin/')
|
@app.route('/admin/')
|
||||||
def admin():
|
def admin():
|
||||||
@ -167,11 +253,33 @@ def user_drive(metfunc):
|
|||||||
db = get_db()
|
db = get_db()
|
||||||
data = {"status":False}
|
data = {"status":False}
|
||||||
if metfunc == "get":
|
if metfunc == "get":
|
||||||
pass
|
body = request.get_json()
|
||||||
|
# 如果提供了ID,则返回特定驱动的信息
|
||||||
|
if body and 'id' in body:
|
||||||
|
drive_id = body.get('id')
|
||||||
|
user_drive = db.get_user_drive(drive_id)
|
||||||
|
if user_drive:
|
||||||
|
data["status"] = True
|
||||||
|
data["data"] = user_drive
|
||||||
|
else:
|
||||||
|
data["status"] = False
|
||||||
|
data["message"] = "未找到指定的网盘账号"
|
||||||
|
# 如果提供了provider_name,则返回该类型的所有账号
|
||||||
|
elif body and 'provider_name' in body:
|
||||||
|
provider_name = body.get('provider_name')
|
||||||
|
provider_drives = db.get_user_drives_by_provider(provider_name)
|
||||||
|
data["status"] = True
|
||||||
|
data["data"] = provider_drives if provider_drives else []
|
||||||
|
else:
|
||||||
|
# 否则返回所有驱动的信息
|
||||||
|
alluser_drives = db.get_all_user_drives()
|
||||||
|
# 即使列表为空也返回成功状态和空数组
|
||||||
|
data["status"] = True
|
||||||
|
data["data"] = alluser_drives if alluser_drives else []
|
||||||
elif metfunc == "add":
|
elif metfunc == "add":
|
||||||
body = request.get_json()
|
body = request.get_json()
|
||||||
print(body)
|
print(body)
|
||||||
status = db.add_user_drive(body.get("provider_name","测试网盘"),body.get("config_vars"),body.get("remarks","测试网盘"))
|
status = db.add_user_drive(body.get("provider_name","测试网盘"),body.get("login_config"),body.get("remarks","测试网盘"))
|
||||||
if status:
|
if status:
|
||||||
data["status"] = True
|
data["status"] = True
|
||||||
data["data"] = body
|
data["data"] = body
|
||||||
@ -183,11 +291,30 @@ def user_drive(metfunc):
|
|||||||
if status:
|
if status:
|
||||||
data["status"] = True
|
data["status"] = True
|
||||||
data["data"] = body
|
data["data"] = body
|
||||||
|
elif metfunc == "delete":
|
||||||
|
body = request.get_json()
|
||||||
|
drive_id = body.get("id")
|
||||||
|
if drive_id:
|
||||||
|
# 检查是否有关联的外链,如果有则不允许删除
|
||||||
|
external_links = db.get_external_links_by_drive(drive_id)
|
||||||
|
if external_links and len(external_links) > 0:
|
||||||
|
data["status"] = False
|
||||||
|
data["message"] = "该网盘账号有关联的外链,请先删除外链后再删除账号"
|
||||||
|
return data
|
||||||
|
|
||||||
|
status = db.delete_user_drive(drive_id)
|
||||||
|
if status:
|
||||||
|
data["status"] = True
|
||||||
|
data["message"] = "网盘账号删除成功"
|
||||||
|
else:
|
||||||
|
data["message"] = "网盘账号删除失败,可能不存在"
|
||||||
|
else:
|
||||||
|
data["message"] = "缺少必要的ID参数"
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
class Exlink(MethodView):
|
class Exlink(MethodView):
|
||||||
def get(self):
|
def demo(self):
|
||||||
db = get_db()
|
db = get_db()
|
||||||
db.add_drive_provider(
|
db.add_drive_provider(
|
||||||
"阿里网盘",
|
"阿里网盘",
|
||||||
@ -208,28 +335,126 @@ class Exlink(MethodView):
|
|||||||
"阿里网盘API配置"
|
"阿里网盘API配置"
|
||||||
)
|
)
|
||||||
return jsonify({"status": True, "message": "success"})
|
return jsonify({"status": True, "message": "success"})
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
db = get_db()
|
||||||
|
data = {"status": False}
|
||||||
|
try:
|
||||||
|
# 获取所有外链
|
||||||
|
external_links = []
|
||||||
|
results = db.cursor.execute("SELECT * FROM external_links").fetchall()
|
||||||
|
for row in results:
|
||||||
|
external_links.append(dict(row))
|
||||||
|
|
||||||
|
data["status"] = True
|
||||||
|
data["data"] = external_links
|
||||||
|
except Exception as e:
|
||||||
|
data["message"] = f"获取外链列表失败: {str(e)}"
|
||||||
|
|
||||||
|
return jsonify(data)
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
data = request.json
|
"""创建外链"""
|
||||||
db = get_db()
|
db = get_db()
|
||||||
cursor = db.cursor()
|
data = {"status": False}
|
||||||
cursor.execute('''
|
|
||||||
INSERT INTO exlinks (exlink_id, qr_limit, drivers, use_limit)
|
try:
|
||||||
VALUES (?, ?, ?, ?)
|
body = request.get_json()
|
||||||
''', (
|
|
||||||
data.get('exlink_id'),
|
# 处理前端可能传递的两种数据格式
|
||||||
data.get('qr_limit', 3),
|
# 1. 直接传递drive_id, total_quota, remarks
|
||||||
data.get('drivers', '["quark","wechat"]'),
|
# 2. 将这些参数封装在data字段中
|
||||||
data.get('use_limit', 0)
|
if body.get('data') and isinstance(body.get('data'), dict):
|
||||||
))
|
# 如果参数被封装在data字段中,提取出来
|
||||||
db.commit()
|
body_data = body.get('data')
|
||||||
return jsonify({"status": True, "message": "success"})
|
drive_id = body_data.get('account_id') # 前端传的是account_id
|
||||||
|
total_quota = float(body_data.get('total_quota', 1))
|
||||||
|
remarks = body_data.get('remarks', '')
|
||||||
|
expiry_time = body_data.get('expiry_time')
|
||||||
|
else:
|
||||||
|
# 直接从body中获取
|
||||||
|
drive_id = body.get('drive_id')
|
||||||
|
total_quota = float(body.get('total_quota', 1))
|
||||||
|
remarks = body.get('remarks', '')
|
||||||
|
expiry_time = body.get('expiry_time')
|
||||||
|
|
||||||
|
if not drive_id:
|
||||||
|
data["message"] = "缺少必要的drive_id参数"
|
||||||
|
return jsonify(data)
|
||||||
|
|
||||||
|
# 检查网盘是否存在
|
||||||
|
user_drive = db.get_user_drive(drive_id)
|
||||||
|
if not user_drive:
|
||||||
|
data["message"] = "指定的网盘账号不存在"
|
||||||
|
return jsonify(data)
|
||||||
|
|
||||||
|
# 创建外链
|
||||||
|
link_uuid = db.create_external_link(
|
||||||
|
drive_id=drive_id,
|
||||||
|
total_quota=total_quota,
|
||||||
|
remarks=remarks,
|
||||||
|
expiry_time=expiry_time
|
||||||
|
)
|
||||||
|
|
||||||
|
if link_uuid:
|
||||||
|
data["status"] = True
|
||||||
|
data["data"] = {
|
||||||
|
"link_uuid": link_uuid,
|
||||||
|
"url": f"/exlink/{link_uuid}"
|
||||||
|
}
|
||||||
|
data["message"] = "外链创建成功"
|
||||||
|
else:
|
||||||
|
data["message"] = "外链创建失败"
|
||||||
|
except Exception as e:
|
||||||
|
data["message"] = f"创建外链失败: {str(e)}"
|
||||||
|
|
||||||
|
return jsonify(data)
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
"""删除外链"""
|
||||||
|
db = get_db()
|
||||||
|
data = {"status": False}
|
||||||
|
|
||||||
|
try:
|
||||||
|
body = request.get_json()
|
||||||
|
link_uuid = body.get('link_uuid')
|
||||||
|
|
||||||
|
if not link_uuid:
|
||||||
|
data["message"] = "缺少必要的link_uuid参数"
|
||||||
|
return jsonify(data)
|
||||||
|
|
||||||
|
# 删除外链
|
||||||
|
status = db.delete_external_link(link_uuid)
|
||||||
|
|
||||||
|
if status:
|
||||||
|
data["status"] = True
|
||||||
|
data["message"] = "外链删除成功"
|
||||||
|
else:
|
||||||
|
data["message"] = "外链删除失败,可能不存在"
|
||||||
|
except Exception as e:
|
||||||
|
data["message"] = f"删除外链失败: {str(e)}"
|
||||||
|
|
||||||
|
return jsonify(data)
|
||||||
|
|
||||||
|
|
||||||
app.add_url_rule('/admin/exlink', view_func=Exlink.as_view('exlink'))
|
app.add_url_rule('/admin/exlink', view_func=Exlink.as_view('exlink'))
|
||||||
|
|
||||||
|
|
||||||
|
# 添加新的URL规则 - 外链管理API
|
||||||
|
@app.route('/admin/exlink/get', methods=['POST'])
|
||||||
|
def get_external_links():
|
||||||
|
return Exlink().get()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/admin/exlink/create', methods=['POST'])
|
||||||
|
def create_external_link():
|
||||||
|
return Exlink().post()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/admin/exlink/delete', methods=['POST'])
|
||||||
|
def delete_external_link():
|
||||||
|
return Exlink().delete()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
7
pyproject.toml
Normal file
7
pyproject.toml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[project]
|
||||||
|
name = "workspace"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Add your description here"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.10"
|
||||||
|
dependencies = []
|
@ -138,8 +138,8 @@
|
|||||||
<td><span class="badge bg-success">正常</span></td>
|
<td><span class="badge bg-success">正常</span></td>
|
||||||
<td>1.5TB / 2TB</td>
|
<td>1.5TB / 2TB</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn btn-sm btn-info" id="editudrivebtn" data-bs-toggle="modal" data-bs-target="#editudriveModal" tid="{{ user_drive.id }}"><i class="bi bi-pencil"></i></button>
|
<button class="btn btn-sm btn-info editudrivebtn" data-bs-toggle="modal" data-bs-target="#editudriveModal" tid="{{ user_drive.id }}"><i class="bi bi-pencil"></i></button>
|
||||||
<button class="btn btn-sm btn-danger"><i class="bi bi-trash"></i></button>
|
<button class="btn btn-sm btn-danger deleteudrivebtn" tid="{{ user_drive.id }}"><i class="bi bi-trash"></i></button>
|
||||||
</td>
|
</td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
@ -242,7 +242,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
|
||||||
<button type="button" class="btn btn-primary" id="saveAccount">保存</button>
|
<button type="button" class="btn btn-primary" id="saveNewAccount">保存</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -298,28 +298,32 @@
|
|||||||
<form id="addExlinkForm">
|
<form id="addExlinkForm">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">网盘类型</label>
|
<label class="form-label">网盘类型</label>
|
||||||
<select class="form-select" name="disk_type" required>
|
<select class="form-select" name="disk_type" id="exlinkDriveType" required>
|
||||||
<option value="">请选择网盘类型</option>
|
<option value="">请选择网盘类型</option>
|
||||||
<option value="aliyun">阿里云盘</option>
|
{% for provider in providers %}
|
||||||
<option value="baidu">百度网盘</option>
|
<option value="{{ provider.provider_name }}">{{ provider.provider_name }}</option>
|
||||||
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">账号</label>
|
<label class="form-label">账号</label>
|
||||||
<select class="form-select" name="account_id" required>
|
<select class="form-select" name="account_id" id="exlinkAccountId" required>
|
||||||
<option value="">请选择账号</option>
|
<option value="">请先选择网盘类型</option>
|
||||||
<!-- 这里应该通过JavaScript动态填充账号列表 -->
|
|
||||||
<option value="aliyun">阿里云盘</option>
|
|
||||||
<option value="baidu">百度网盘</option>
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">剩余次数</label>
|
<label class="form-label">使用次数限制</label>
|
||||||
<input type="number" class="form-control" name="remaining_count" required>
|
<input type="number" class="form-control" name="total_quota" required min="1" value="3">
|
||||||
|
<div class="form-text">设置此外链可以被使用的最大次数</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">有效期</label>
|
<label class="form-label">到期时间</label>
|
||||||
<input type="date" class="form-control" name="expiry_date" required>
|
<input type="datetime-local" class="form-control" name="expiry_time" id="exlinkExpiryTime" required>
|
||||||
|
<div class="form-text">设置此外链的有效期限,超过时间后将无法访问</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">备注说明</label>
|
||||||
|
<input type="text" class="form-control" name="remarks" placeholder="可选">
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@ -331,6 +335,25 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 删除确认对话框 -->
|
||||||
|
<div class="modal fade" id="deleteConfirmModal" tabindex="-1">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">确认删除</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p>确定要删除此网盘账号吗?此操作不可恢复。</p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
|
||||||
|
<button type="button" class="btn btn-danger" id="confirmDelete">确认删除</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
@ -411,57 +434,6 @@
|
|||||||
// showMessage('错误信息', 'error');
|
// showMessage('错误信息', 'error');
|
||||||
// showMessage('提示信息', 'info');
|
// showMessage('提示信息', 'info');
|
||||||
|
|
||||||
|
|
||||||
//添加保存外链事件
|
|
||||||
$('#saveExlink').on('click', function() {
|
|
||||||
// 获取表单数据
|
|
||||||
const formData = new FormData(document.querySelector('#addExlinkModal form'));
|
|
||||||
const formValues = {
|
|
||||||
disk_type: formData.get('disk_type'),
|
|
||||||
account_id: formData.get('account_id'),
|
|
||||||
remaining_count: formData.get('remaining_count'),
|
|
||||||
expiry_date: formData.get('expiry_date')
|
|
||||||
};
|
|
||||||
|
|
||||||
// 检查表单是否填写完整
|
|
||||||
if (!formValues.disk_type || !formValues.remaining_count || !formValues.account_id || !formValues.expiry_date) {
|
|
||||||
showMessage('请填写所有必填字段!', 'error');
|
|
||||||
return; // 停止提交
|
|
||||||
}
|
|
||||||
|
|
||||||
// 表单数据准备发送
|
|
||||||
const submitData = {
|
|
||||||
account_id: formValues.account_id,
|
|
||||||
remaining_count: formValues.remaining_count,
|
|
||||||
access_token: formValues.access_token
|
|
||||||
};
|
|
||||||
console.log('准备提交的数据:', submitData);
|
|
||||||
// 发送数据到服务器
|
|
||||||
$.ajax({
|
|
||||||
url: '/admin/exlink',
|
|
||||||
type: 'POST',
|
|
||||||
contentType: 'application/json',
|
|
||||||
data: JSON.stringify({
|
|
||||||
data: formValues
|
|
||||||
}),
|
|
||||||
success: function(data) {
|
|
||||||
if (data.status) {
|
|
||||||
showMessage('账号保存成功',"success");
|
|
||||||
// 清空表单
|
|
||||||
$('#accountName').val('');
|
|
||||||
$('#accountToken').val('');
|
|
||||||
|
|
||||||
} else {
|
|
||||||
showMessage('账号保存失败: ' + data.message,"warning");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function(error) {
|
|
||||||
console.error('保存账号出错:', error);
|
|
||||||
showMessage('保存账号时发生错误,请查看控制台',"error");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// 初始化图表
|
// 初始化图表
|
||||||
const accessCtx = document.getElementById('accessChart').getContext('2d');
|
const accessCtx = document.getElementById('accessChart').getContext('2d');
|
||||||
new Chart(accessCtx, {
|
new Chart(accessCtx, {
|
||||||
@ -559,6 +531,11 @@
|
|||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
setupJsonEditors(); // 初始化所有编辑器
|
setupJsonEditors(); // 初始化所有编辑器
|
||||||
|
bindEditButtonEvents(); // 初始化编辑按钮事件
|
||||||
|
bindDeleteButtonEvents(); // 初始化删除按钮事件
|
||||||
|
bindAddAccountEvent(); // 初始化添加账号事件
|
||||||
|
bindAddExlinkEvents(); // 初始化添加外链事件
|
||||||
|
loadExternalLinks(); // 加载外链列表
|
||||||
});
|
});
|
||||||
|
|
||||||
// 设置默认JSON模板 (Add Modal specific)
|
// 设置默认JSON模板 (Add Modal specific)
|
||||||
@ -586,36 +563,74 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 设置编辑用户驱动JSON模板 (Edit Modal specific)
|
// 绑定编辑按钮事件
|
||||||
document.querySelectorAll('#editudrivebtn').forEach(button => {
|
function bindEditButtonEvents() {
|
||||||
button.addEventListener('click', function() {
|
document.querySelectorAll('.editudrivebtn').forEach(button => {
|
||||||
const editModalEditorArea = document.querySelector('#editudriveModal .json-editor-area');
|
button.addEventListener('click', function() {
|
||||||
const editorElement = editModalEditorArea.querySelector('.ace-editor');
|
const editModalEditorArea = document.querySelector('#editudriveModal .json-editor-area');
|
||||||
const editor = ace.edit(editorElement); // Get the Ace editor instance
|
const editorElement = editModalEditorArea.querySelector('.ace-editor');
|
||||||
const selectedtid = this.getAttribute('tid');
|
const editor = ace.edit(editorElement); // Get the Ace editor instance
|
||||||
|
const selectedtid = this.getAttribute('tid');
|
||||||
if (selectedtid) {
|
|
||||||
let defaultJson = {};
|
|
||||||
// 解析返回的JSON字符串为JavaScript对象
|
|
||||||
const allUserDrivesStr = '{{ alluser_drives | tojson | safe }}';
|
|
||||||
const user_drives = JSON.parse(allUserDrivesStr); // Use safe filter
|
|
||||||
const selectedUdrive = user_drives.find(user_drive => user_drive.id == selectedtid);
|
|
||||||
if (selectedUdrive && selectedUdrive.login_config) {
|
|
||||||
defaultJson = selectedUdrive.login_config;
|
|
||||||
} else {
|
|
||||||
defaultJson = {
|
|
||||||
"provider_name": selectedtid, // Keep provider_name for context if no config
|
|
||||||
"config": { "api_key": "", "secret_key": "", "redirect_uri": "" },
|
|
||||||
"auth": { "token": "", "expires_in": 0 }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
editor.setValue(JSON.stringify(defaultJson, null, 2), -1);
|
|
||||||
|
|
||||||
// Store the selected ID in a data attribute for the save button to access
|
if (selectedtid) {
|
||||||
document.querySelector('#editudriveModal #saveAccount').setAttribute('data-tid', selectedtid);
|
// 获取最新的账号信息
|
||||||
}
|
$.ajax({
|
||||||
|
url: '/admin/user_drive/get',
|
||||||
|
type: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({ id: selectedtid }),
|
||||||
|
success: function(response) {
|
||||||
|
if (response.status && response.data) {
|
||||||
|
let selectedUdrive = null;
|
||||||
|
// 查找匹配的用户驱动
|
||||||
|
if (Array.isArray(response.data)) {
|
||||||
|
selectedUdrive = response.data.find(drive => drive.id == selectedtid);
|
||||||
|
} else if (response.data.id == selectedtid) {
|
||||||
|
selectedUdrive = response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedUdrive && selectedUdrive.login_config) {
|
||||||
|
let configData = selectedUdrive.login_config;
|
||||||
|
// 如果是字符串格式,解析为对象
|
||||||
|
if (typeof configData === 'string') {
|
||||||
|
try {
|
||||||
|
configData = JSON.parse(configData);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('解析配置JSON失败:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
editor.setValue(JSON.stringify(configData, null, 2), -1);
|
||||||
|
} else {
|
||||||
|
const defaultJson = {
|
||||||
|
"provider_name": selectedtid,
|
||||||
|
"config": { "api_key": "", "secret_key": "", "redirect_uri": "" },
|
||||||
|
"auth": { "token": "", "expires_in": 0 }
|
||||||
|
};
|
||||||
|
editor.setValue(JSON.stringify(defaultJson, null, 2), -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 存储选中的ID
|
||||||
|
document.querySelector('#editudriveModal #saveAccount').setAttribute('data-tid', selectedtid);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
console.error('获取账号信息出错:', error);
|
||||||
|
showMessage('获取账号信息时发生错误', 'error');
|
||||||
|
|
||||||
|
// 使用默认值
|
||||||
|
const defaultJson = {
|
||||||
|
"provider_name": selectedtid,
|
||||||
|
"config": { "api_key": "", "secret_key": "", "redirect_uri": "" },
|
||||||
|
"auth": { "token": "", "expires_in": 0 }
|
||||||
|
};
|
||||||
|
editor.setValue(JSON.stringify(defaultJson, null, 2), -1);
|
||||||
|
document.querySelector('#editudriveModal #saveAccount').setAttribute('data-tid', selectedtid);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
// 编辑用户驱动保存事件
|
// 编辑用户驱动保存事件
|
||||||
$('#editudriveModal #saveAccount').on('click', function() {
|
$('#editudriveModal #saveAccount').on('click', function() {
|
||||||
@ -645,8 +660,8 @@
|
|||||||
// 清空并关闭模态框
|
// 清空并关闭模态框
|
||||||
editor.setValue(configJson, -1);
|
editor.setValue(configJson, -1);
|
||||||
$('#editudriveModal').modal('hide');
|
$('#editudriveModal').modal('hide');
|
||||||
// 如果需要,可以在这里刷新页面或表格数据
|
// 刷新网盘账号列表
|
||||||
// 局部刷新表格内容
|
refreshAccountsList();
|
||||||
} else {
|
} else {
|
||||||
showMessage('配置更新失败: ' + response.message, 'error');
|
showMessage('配置更新失败: ' + response.message, 'error');
|
||||||
}
|
}
|
||||||
@ -664,6 +679,418 @@
|
|||||||
editorElement.classList.add('border-danger');
|
editorElement.classList.add('border-danger');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 绑定删除按钮事件
|
||||||
|
function bindDeleteButtonEvents() {
|
||||||
|
let selectedDriveId = null;
|
||||||
|
const deleteConfirmModal = new bootstrap.Modal(document.getElementById('deleteConfirmModal'));
|
||||||
|
|
||||||
|
// 为所有删除按钮添加点击事件
|
||||||
|
document.querySelectorAll('.deleteudrivebtn').forEach(button => {
|
||||||
|
button.addEventListener('click', function() {
|
||||||
|
selectedDriveId = this.getAttribute('tid');
|
||||||
|
// 重置对话框内容
|
||||||
|
document.querySelector('#deleteConfirmModal .modal-body p').textContent =
|
||||||
|
'确定要删除此网盘账号吗?此操作不可恢复。';
|
||||||
|
deleteConfirmModal.show(); // 显示确认对话框
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 确认删除按钮点击事件
|
||||||
|
document.getElementById('confirmDelete').addEventListener('click', function() {
|
||||||
|
if (selectedDriveId) {
|
||||||
|
// 发送删除请求
|
||||||
|
$.ajax({
|
||||||
|
url: '/admin/user_drive/delete',
|
||||||
|
type: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({ id: selectedDriveId }),
|
||||||
|
success: function(response) {
|
||||||
|
if (response.status) {
|
||||||
|
deleteConfirmModal.hide(); // 只有成功时才隐藏对话框
|
||||||
|
showMessage('网盘账号删除成功', 'success');
|
||||||
|
// 刷新网盘账号列表
|
||||||
|
refreshAccountsList();
|
||||||
|
} else {
|
||||||
|
// 显示错误消息在对话框中
|
||||||
|
document.querySelector('#deleteConfirmModal .modal-body p').textContent =
|
||||||
|
response.message || '网盘账号删除失败';
|
||||||
|
showMessage(response.message || '网盘账号删除失败', 'error');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
// 显示错误消息在对话框中
|
||||||
|
document.querySelector('#deleteConfirmModal .modal-body p').textContent =
|
||||||
|
'删除网盘账号时发生错误,请稍后重试。';
|
||||||
|
console.error('删除网盘账号出错:', error);
|
||||||
|
showMessage('删除网盘账号时发生错误,请查看控制台', 'error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 刷新网盘账号列表函数也需要更新,确保新添加的行的删除按钮也有事件绑定
|
||||||
|
function refreshAccountsList() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/admin/user_drive/get',
|
||||||
|
type: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({}),
|
||||||
|
success: function(response) {
|
||||||
|
// 清空现有表格内容
|
||||||
|
const accountsTableBody = $('#accounts table tbody');
|
||||||
|
accountsTableBody.empty();
|
||||||
|
|
||||||
|
if (response.status) {
|
||||||
|
// 检查是否有数据,如果没有也显示空表格而不是错误
|
||||||
|
if (response.data && response.data.length > 0) {
|
||||||
|
// 添加新的行
|
||||||
|
response.data.forEach(function(drive) {
|
||||||
|
const row = $('<tr></tr>');
|
||||||
|
row.append(`<td>${drive.provider_name}</td>`);
|
||||||
|
row.append(`<td>${drive.provider_name}</td>`);
|
||||||
|
row.append(`<td><span class="badge bg-success">正常</span></td>`);
|
||||||
|
row.append(`<td>1.5TB / 2TB</td>`);
|
||||||
|
row.append(`
|
||||||
|
<td>
|
||||||
|
<button class="btn btn-sm btn-info editudrivebtn" data-bs-toggle="modal" data-bs-target="#editudriveModal" tid="${drive.id}">
|
||||||
|
<i class="bi bi-pencil"></i>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-sm btn-danger deleteudrivebtn" tid="${drive.id}">
|
||||||
|
<i class="bi bi-trash"></i>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
`);
|
||||||
|
accountsTableBody.append(row);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 重新绑定编辑和删除按钮事件
|
||||||
|
bindEditButtonEvents();
|
||||||
|
bindDeleteButtonEvents();
|
||||||
|
} else {
|
||||||
|
// 如果没有数据,显示一个提示行
|
||||||
|
const emptyRow = $('<tr></tr>');
|
||||||
|
emptyRow.append(`<td colspan="5" class="text-center">暂无网盘账号,请添加。</td>`);
|
||||||
|
accountsTableBody.append(emptyRow);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果API返回失败,显示错误消息
|
||||||
|
showMessage(response.message || '获取网盘账号列表失败', 'error');
|
||||||
|
const errorRow = $('<tr></tr>');
|
||||||
|
errorRow.append(`<td colspan="5" class="text-center text-danger">获取数据失败,请刷新页面重试。</td>`);
|
||||||
|
accountsTableBody.append(errorRow);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
console.error('获取网盘账号列表出错:', error);
|
||||||
|
showMessage('获取网盘账号列表时发生错误', 'error');
|
||||||
|
|
||||||
|
// 显示错误消息在表格中
|
||||||
|
const accountsTableBody = $('#accounts table tbody');
|
||||||
|
accountsTableBody.empty();
|
||||||
|
const errorRow = $('<tr></tr>');
|
||||||
|
errorRow.append(`<td colspan="5" class="text-center text-danger">获取数据失败,请刷新页面重试。</td>`);
|
||||||
|
accountsTableBody.append(errorRow);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加网盘账号保存事件
|
||||||
|
function bindAddAccountEvent() {
|
||||||
|
document.getElementById('saveNewAccount').addEventListener('click', function() {
|
||||||
|
const addModalEditorArea = document.querySelector('#addAccountModal .json-editor-area');
|
||||||
|
const editorElement = addModalEditorArea.querySelector('.ace-editor');
|
||||||
|
const editor = ace.edit(editorElement);
|
||||||
|
const configJson = editor.getValue();
|
||||||
|
const driveType = document.getElementById('driveType').value;
|
||||||
|
|
||||||
|
if (!driveType) {
|
||||||
|
showMessage('请选择网盘类型', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 验证JSON格式
|
||||||
|
const configData = JSON.parse(configJson);
|
||||||
|
|
||||||
|
// 发送数据到服务器
|
||||||
|
$.ajax({
|
||||||
|
url: '/admin/user_drive/add',
|
||||||
|
type: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({
|
||||||
|
provider_name: driveType,
|
||||||
|
login_config: configData,
|
||||||
|
remarks: driveType + "的账号"
|
||||||
|
}),
|
||||||
|
success: function(response) {
|
||||||
|
if (response.status) {
|
||||||
|
showMessage('网盘账号添加成功', 'success');
|
||||||
|
// 清空并关闭模态框
|
||||||
|
document.getElementById('driveType').value = '';
|
||||||
|
editor.setValue('', -1);
|
||||||
|
$('#addAccountModal').modal('hide');
|
||||||
|
// 刷新网盘账号列表
|
||||||
|
refreshAccountsList();
|
||||||
|
} else {
|
||||||
|
showMessage('网盘账号添加失败: ' + (response.message || '未知错误'), 'error');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
console.error('添加网盘账号出错:', error);
|
||||||
|
showMessage('添加网盘账号时发生错误,请查看控制台', 'error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
showMessage('无效的JSON格式: ' + e.message, 'error');
|
||||||
|
const errorDisplay = addModalEditorArea.closest('.mb-3').querySelector('.json-error');
|
||||||
|
errorDisplay.textContent = '无效的JSON格式: ' + e.message;
|
||||||
|
errorDisplay.style.display = 'block';
|
||||||
|
editorElement.classList.add('border-danger');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载外链列表
|
||||||
|
function loadExternalLinks() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/admin/exlink/get',
|
||||||
|
type: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({}),
|
||||||
|
success: function(response) {
|
||||||
|
const linksTableBody = $('#links table tbody');
|
||||||
|
linksTableBody.empty();
|
||||||
|
|
||||||
|
if (response.status) {
|
||||||
|
if (response.data && response.data.length > 0) {
|
||||||
|
response.data.forEach(function(link) {
|
||||||
|
const row = $('<tr></tr>');
|
||||||
|
row.append(`<td>${link.link_uuid}</td>`);
|
||||||
|
row.append(`<td>${link.drive_id}</td>`);
|
||||||
|
|
||||||
|
// 创建时间和过期时间
|
||||||
|
row.append(`<td>-</td>`);
|
||||||
|
if (link.expiry_time) {
|
||||||
|
const expiryDate = new Date(link.expiry_time);
|
||||||
|
const formattedDate = expiryDate.toLocaleString();
|
||||||
|
row.append(`<td>${formattedDate}</td>`);
|
||||||
|
} else {
|
||||||
|
row.append(`<td>-</td>`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 剩余次数
|
||||||
|
const usedQuota = link.used_quota || 0;
|
||||||
|
const totalQuota = link.total_quota || 0;
|
||||||
|
const remainingCount = totalQuota - usedQuota;
|
||||||
|
row.append(`<td>${remainingCount} / ${totalQuota}</td>`);
|
||||||
|
|
||||||
|
// 状态
|
||||||
|
let statusBadge = '';
|
||||||
|
if (remainingCount <= 0) {
|
||||||
|
statusBadge = '<span class="badge bg-danger">已禁用</span>';
|
||||||
|
} else {
|
||||||
|
statusBadge = '<span class="badge bg-success">正常</span>';
|
||||||
|
}
|
||||||
|
row.append(`<td>${statusBadge}</td>`);
|
||||||
|
|
||||||
|
// 操作按钮
|
||||||
|
row.append(`
|
||||||
|
<td>
|
||||||
|
<a href="/exlink/${link.link_uuid}" target="_blank" class="btn btn-sm btn-info">
|
||||||
|
<i class="bi bi-box-arrow-up-right"></i>
|
||||||
|
</a>
|
||||||
|
<button class="btn btn-sm btn-danger deleteExlinkBtn" data-uuid="${link.link_uuid}">
|
||||||
|
<i class="bi bi-trash"></i>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
`);
|
||||||
|
|
||||||
|
linksTableBody.append(row);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 绑定删除外链按钮事件
|
||||||
|
bindDeleteExlinkEvents();
|
||||||
|
} else {
|
||||||
|
// 如果没有数据,显示一个提示行
|
||||||
|
const emptyRow = $('<tr></tr>');
|
||||||
|
emptyRow.append(`<td colspan="7" class="text-center">暂无外链数据,请添加。</td>`);
|
||||||
|
linksTableBody.append(emptyRow);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showMessage('获取外链列表失败: ' + (response.message || '未知错误'), 'error');
|
||||||
|
const errorRow = $('<tr></tr>');
|
||||||
|
errorRow.append(`<td colspan="7" class="text-center text-danger">获取数据失败,请刷新页面重试。</td>`);
|
||||||
|
linksTableBody.append(errorRow);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
console.error('获取外链列表出错:', error);
|
||||||
|
showMessage('获取外链列表时发生错误', 'error');
|
||||||
|
|
||||||
|
// 显示错误消息在表格中
|
||||||
|
const linksTableBody = $('#links table tbody');
|
||||||
|
linksTableBody.empty();
|
||||||
|
const errorRow = $('<tr></tr>');
|
||||||
|
errorRow.append(`<td colspan="7" class="text-center text-danger">获取数据失败,请刷新页面重试。</td>`);
|
||||||
|
linksTableBody.append(errorRow);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 绑定添加外链相关事件
|
||||||
|
function bindAddExlinkEvents() {
|
||||||
|
// 当选择网盘类型时,加载对应的账号列表
|
||||||
|
document.getElementById('exlinkDriveType').addEventListener('change', function() {
|
||||||
|
const selectedType = this.value;
|
||||||
|
const accountSelect = document.getElementById('exlinkAccountId');
|
||||||
|
|
||||||
|
// 清空当前选项
|
||||||
|
accountSelect.innerHTML = '<option value="">加载中...</option>';
|
||||||
|
|
||||||
|
if (selectedType) {
|
||||||
|
// 加载对应类型的网盘账号
|
||||||
|
$.ajax({
|
||||||
|
url: '/admin/user_drive/get',
|
||||||
|
type: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({ provider_name: selectedType }),
|
||||||
|
success: function(response) {
|
||||||
|
accountSelect.innerHTML = '<option value="">请选择账号</option>';
|
||||||
|
|
||||||
|
if (response.status && response.data && response.data.length > 0) {
|
||||||
|
response.data.forEach(function(drive) {
|
||||||
|
const option = document.createElement('option');
|
||||||
|
option.value = drive.id;
|
||||||
|
option.textContent = drive.provider_name + (drive.remarks ? ` (${drive.remarks})` : '');
|
||||||
|
accountSelect.appendChild(option);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
accountSelect.innerHTML = '<option value="">没有可用的账号,请先添加</option>';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
console.error('获取网盘账号出错:', error);
|
||||||
|
accountSelect.innerHTML = '<option value="">加载失败,请重试</option>';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
accountSelect.innerHTML = '<option value="">请先选择网盘类型</option>';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 设置默认到期时间为当前时间后24小时
|
||||||
|
function setDefaultExpiryTime() {
|
||||||
|
const expiryTimeInput = document.getElementById('exlinkExpiryTime');
|
||||||
|
if (expiryTimeInput) {
|
||||||
|
const now = new Date();
|
||||||
|
now.setHours(now.getHours() + 24);
|
||||||
|
|
||||||
|
// 格式化为datetime-local输入所需的格式:YYYY-MM-DDThh:mm
|
||||||
|
const year = now.getFullYear();
|
||||||
|
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(now.getDate()).padStart(2, '0');
|
||||||
|
const hours = String(now.getHours()).padStart(2, '0');
|
||||||
|
const minutes = String(now.getMinutes()).padStart(2, '0');
|
||||||
|
|
||||||
|
const formattedDateTime = `${year}-${month}-${day}T${hours}:${minutes}`;
|
||||||
|
expiryTimeInput.value = formattedDateTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化表单时设置默认到期时间
|
||||||
|
setDefaultExpiryTime();
|
||||||
|
|
||||||
|
// 每次打开模态框时重置到期时间
|
||||||
|
$('#addExlinkModal').on('show.bs.modal', function() {
|
||||||
|
setDefaultExpiryTime();
|
||||||
|
});
|
||||||
|
|
||||||
|
// 绑定保存外链按钮点击事件
|
||||||
|
document.getElementById('saveExlink').addEventListener('click', function() {
|
||||||
|
// 获取表单数据
|
||||||
|
const formData = new FormData(document.getElementById('addExlinkForm'));
|
||||||
|
const drive_id = formData.get('account_id');
|
||||||
|
const total_quota = formData.get('total_quota');
|
||||||
|
const expiry_time = formData.get('expiry_time');
|
||||||
|
const remarks = formData.get('remarks') || '';
|
||||||
|
|
||||||
|
if (!drive_id || !total_quota || !expiry_time) {
|
||||||
|
showMessage('请填写必要的信息', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转换日期时间格式:从YYYY-MM-DDThh:mm到YYYY-MM-DD hh:mm:ss
|
||||||
|
const expiryDate = new Date(expiry_time);
|
||||||
|
const formattedExpiryTime = expiryDate.toISOString().replace('T', ' ').substring(0, 19);
|
||||||
|
|
||||||
|
// 发送创建外链请求
|
||||||
|
$.ajax({
|
||||||
|
url: '/admin/exlink/create',
|
||||||
|
type: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({
|
||||||
|
drive_id: drive_id,
|
||||||
|
total_quota: total_quota,
|
||||||
|
expiry_time: formattedExpiryTime,
|
||||||
|
remarks: remarks
|
||||||
|
}),
|
||||||
|
success: function(response) {
|
||||||
|
if (response.status) {
|
||||||
|
showMessage('外链创建成功', 'success');
|
||||||
|
|
||||||
|
// 清空表单
|
||||||
|
document.getElementById('exlinkDriveType').value = '';
|
||||||
|
document.getElementById('exlinkAccountId').innerHTML = '<option value="">请先选择网盘类型</option>';
|
||||||
|
document.querySelector('[name="total_quota"]').value = '3';
|
||||||
|
document.querySelector('[name="remarks"]').value = '';
|
||||||
|
|
||||||
|
// 关闭模态框
|
||||||
|
$('#addExlinkModal').modal('hide');
|
||||||
|
|
||||||
|
// 重新加载外链列表
|
||||||
|
loadExternalLinks();
|
||||||
|
} else {
|
||||||
|
showMessage('外链创建失败: ' + (response.message || '未知错误'), 'error');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
console.error('创建外链出错:', error);
|
||||||
|
showMessage('创建外链时发生错误,请查看控制台', 'error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 绑定删除外链按钮事件
|
||||||
|
function bindDeleteExlinkEvents() {
|
||||||
|
document.querySelectorAll('.deleteExlinkBtn').forEach(button => {
|
||||||
|
button.addEventListener('click', function() {
|
||||||
|
const uuid = this.getAttribute('data-uuid');
|
||||||
|
if (confirm('确定要删除此外链吗?此操作不可恢复。')) {
|
||||||
|
$.ajax({
|
||||||
|
url: '/admin/exlink/delete',
|
||||||
|
type: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({ link_uuid: uuid }),
|
||||||
|
success: function(response) {
|
||||||
|
if (response.status) {
|
||||||
|
showMessage('外链删除成功', 'success');
|
||||||
|
loadExternalLinks(); // 重新加载外链列表
|
||||||
|
} else {
|
||||||
|
showMessage('外链删除失败: ' + (response.message || '未知错误'), 'error');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
console.error('删除外链出错:', error);
|
||||||
|
showMessage('删除外链时发生错误,请查看控制台', 'error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
81
templates/exlink_error.html
Normal file
81
templates/exlink_error.html
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>访问失败 - 网盘外链</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.main-content {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 40px 0;
|
||||||
|
}
|
||||||
|
.card {
|
||||||
|
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.card-header {
|
||||||
|
background-color: #dc3545;
|
||||||
|
color: white;
|
||||||
|
font-weight: bold;
|
||||||
|
padding: 15px 20px;
|
||||||
|
}
|
||||||
|
.error-icon {
|
||||||
|
font-size: 4rem;
|
||||||
|
color: #dc3545;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
.footer {
|
||||||
|
text-align: center;
|
||||||
|
padding: 20px;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
color: #6c757d;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container main-content">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-8 col-lg-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<span>访问失败</span>
|
||||||
|
</div>
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<div class="error-icon">
|
||||||
|
<i class="bi bi-exclamation-circle"></i>
|
||||||
|
</div>
|
||||||
|
<h5 class="card-title">无法访问网盘外链</h5>
|
||||||
|
<p class="card-text">{{ message }}</p>
|
||||||
|
|
||||||
|
<div class="d-grid gap-2 mt-4">
|
||||||
|
<a href="/" class="btn btn-primary">
|
||||||
|
<i class="bi bi-house me-2"></i>返回首页
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer class="footer">
|
||||||
|
<div class="container">
|
||||||
|
<p class="mb-0">网盘租户系统 © 2023</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
465
templates/exlink_view.html
Normal file
465
templates/exlink_view.html
Normal file
@ -0,0 +1,465 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>{{ drive_info.provider_name }} 扫码登录</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.main-content {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 20px 15px;
|
||||||
|
}
|
||||||
|
.card {
|
||||||
|
box-shadow: 0 2px 10px rgba(0,0,0,0.08);
|
||||||
|
border-radius: 12px;
|
||||||
|
border: none;
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
.card-body {
|
||||||
|
padding: 2rem;
|
||||||
|
}
|
||||||
|
.footer {
|
||||||
|
text-align: center;
|
||||||
|
padding: 15px;
|
||||||
|
background-color: #e9ecef;
|
||||||
|
color: #6c757d;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
.header-info {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: #6c757d;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.header-info span {
|
||||||
|
margin: 0 8px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.header-info .value {
|
||||||
|
color: #0d6efd;
|
||||||
|
font-weight: 500;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
.scan-area {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
padding-top: 75%;
|
||||||
|
margin-top: 1rem;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
border: 1px solid #e9ecef;
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
#camera-container, #scan-placeholder, #scan-result {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
#camera-container {
|
||||||
|
display: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
#scan-result {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
#scan-placeholder p {
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
color: #6c757d;
|
||||||
|
}
|
||||||
|
#video {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
#canvas {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.card-title {
|
||||||
|
text-align: center;
|
||||||
|
color: #343a40;
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
.btn {
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.btn-primary {
|
||||||
|
background-color: #0d6efd;
|
||||||
|
border-color: #0d6efd;
|
||||||
|
}
|
||||||
|
.btn-danger {
|
||||||
|
background-color: #dc3545;
|
||||||
|
border-color: #dc3545;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 576px) {
|
||||||
|
.card-body {
|
||||||
|
padding: 1.5rem;
|
||||||
|
}
|
||||||
|
.card-title {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
}
|
||||||
|
.header-info {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
.btn {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
padding: 0.6rem 0.8rem;
|
||||||
|
}
|
||||||
|
.scan-area {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container main-content">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-8 col-lg-6 col-xl-5">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">{{ drive_info.provider_name }}扫码登录</h5>
|
||||||
|
|
||||||
|
<div class="header-info">
|
||||||
|
<span>
|
||||||
|
<i class="bi bi-arrow-repeat"></i> 剩余次数:<span class="value" id="remaining-count">{{ remaining_count }}</span>
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
<i class="bi bi-clock"></i> 剩余时间:<span class="value" id="countdown">计算中...</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="scan-area">
|
||||||
|
<div id="camera-container">
|
||||||
|
<video id="video" playsinline></video>
|
||||||
|
<canvas id="canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
<div id="scan-placeholder">
|
||||||
|
<i class="bi bi-qr-code-scan fs-1 text-muted mb-3"></i>
|
||||||
|
<p class="mb-1 fw-bold">点击下方按钮启动扫码</p>
|
||||||
|
<p class="text-muted small">请将摄像头对准{{ drive_info.provider_name }} PC端的二维码</p>
|
||||||
|
</div>
|
||||||
|
<div id="scan-result">
|
||||||
|
<i class="bi bi-check-circle-fill fs-1 text-success mb-3"></i>
|
||||||
|
<p class="text-success fw-bold mb-2">扫码成功!</p>
|
||||||
|
<div id="result-content" class="text-center text-muted"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-grid gap-2">
|
||||||
|
<button class="btn btn-primary" id="scan-button">
|
||||||
|
<i class="bi bi-camera-video me-1"></i>开始扫码
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-danger" id="stop-button" style="display: none;">
|
||||||
|
<i class="bi bi-stop-circle me-1"></i>停止扫码
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer class="footer">
|
||||||
|
<div class="container">
|
||||||
|
<p class="mb-0">网盘租户系统 © 2023</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/jsqr@1.4.0/dist/jsQR.min.js"></script>
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const video = document.getElementById('video');
|
||||||
|
const canvas = document.getElementById('canvas');
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
const scanButton = document.getElementById('scan-button');
|
||||||
|
const stopButton = document.getElementById('stop-button');
|
||||||
|
const cameraContainer = document.getElementById('camera-container');
|
||||||
|
const scanPlaceholder = document.getElementById('scan-placeholder');
|
||||||
|
const scanResult = document.getElementById('scan-result');
|
||||||
|
const resultContent = document.getElementById('result-content');
|
||||||
|
const remainingCountEl = document.getElementById('remaining-count');
|
||||||
|
const countdownEl = document.getElementById('countdown');
|
||||||
|
|
||||||
|
let scanning = false;
|
||||||
|
let stream = null;
|
||||||
|
let qrCodeToken = null;
|
||||||
|
|
||||||
|
let remainingCount = parseInt("{{ remaining_count }}") || 0;
|
||||||
|
|
||||||
|
const expiryTimeString = "{{ expiry_time }}";
|
||||||
|
const expiryTime = expiryTimeString ? new Date(expiryTimeString.replace(/-/g, '/')) : null;
|
||||||
|
|
||||||
|
let countdownInterval = null;
|
||||||
|
|
||||||
|
function updateCountdown() {
|
||||||
|
if (!expiryTime || isNaN(expiryTime.getTime())) {
|
||||||
|
countdownEl.textContent = "未设置";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
const diff = expiryTime - now;
|
||||||
|
|
||||||
|
if (diff <= 0) {
|
||||||
|
countdownEl.textContent = "已过期";
|
||||||
|
if(countdownInterval) clearInterval(countdownInterval);
|
||||||
|
scanButton.disabled = true;
|
||||||
|
scanButton.classList.add('disabled');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
||||||
|
const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
||||||
|
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
|
||||||
|
const seconds = Math.floor((diff % (1000 * 60)) / 1000);
|
||||||
|
|
||||||
|
let timeText = "";
|
||||||
|
if (days > 0) {
|
||||||
|
timeText += `${days}天`;
|
||||||
|
}
|
||||||
|
timeText += `${String(hours).padStart(2, '0')}时${String(minutes).padStart(2, '0')}分${String(seconds).padStart(2, '0')}秒`;
|
||||||
|
|
||||||
|
countdownEl.textContent = timeText;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateCountdown();
|
||||||
|
|
||||||
|
if (expiryTime && !isNaN(expiryTime.getTime())) {
|
||||||
|
countdownInterval = setInterval(updateCountdown, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showMessage(message, type = 'info') {
|
||||||
|
const messageContainer = document.body;
|
||||||
|
const messageDiv = document.createElement('div');
|
||||||
|
let bgColor = 'bg-info';
|
||||||
|
let textColor = 'text-white';
|
||||||
|
switch(type) {
|
||||||
|
case 'success': bgColor = 'bg-success'; break;
|
||||||
|
case 'error': bgColor = 'bg-danger'; break;
|
||||||
|
case 'warning': bgColor = 'bg-warning'; textColor = 'text-dark'; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
messageDiv.className = `alert ${bgColor} ${textColor} position-fixed top-0 start-50 translate-middle-x mt-3 p-2 rounded shadow-sm fade show`;
|
||||||
|
messageDiv.style.zIndex = '1055';
|
||||||
|
messageDiv.style.minWidth = '200px';
|
||||||
|
messageDiv.style.textAlign = 'center';
|
||||||
|
messageDiv.setAttribute('role', 'alert');
|
||||||
|
messageDiv.textContent = message;
|
||||||
|
messageContainer.appendChild(messageDiv);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
messageDiv.classList.remove('show');
|
||||||
|
setTimeout(() => messageDiv.remove(), 150);
|
||||||
|
}, 3000);
|
||||||
|
|
||||||
|
console.log(`${type}: ${message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
scanButton.addEventListener('click', startScanning);
|
||||||
|
|
||||||
|
stopButton.addEventListener('click', stopScanning);
|
||||||
|
|
||||||
|
function startScanning() {
|
||||||
|
if (scanning) return;
|
||||||
|
|
||||||
|
if (remainingCount <= 0) {
|
||||||
|
showMessage('剩余次数已用完,无法继续扫码', 'warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!expiryTime || isNaN(expiryTime.getTime()) || expiryTime <= new Date()) {
|
||||||
|
showMessage('此外链已过期或无效,无法扫码', 'warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cameraContainer.style.display = 'flex';
|
||||||
|
scanPlaceholder.style.display = 'none';
|
||||||
|
scanResult.style.display = 'none';
|
||||||
|
scanButton.style.display = 'none';
|
||||||
|
stopButton.style.display = 'block';
|
||||||
|
|
||||||
|
navigator.mediaDevices.getUserMedia({
|
||||||
|
video: {
|
||||||
|
facingMode: 'environment',
|
||||||
|
width: { ideal: 1920 },
|
||||||
|
height: { ideal: 1080 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function(mediaStream) {
|
||||||
|
stream = mediaStream;
|
||||||
|
video.srcObject = mediaStream;
|
||||||
|
video.setAttribute('playsinline', true);
|
||||||
|
video.play();
|
||||||
|
scanning = true;
|
||||||
|
requestAnimationFrame(tick);
|
||||||
|
})
|
||||||
|
.catch(function(error) {
|
||||||
|
console.error('无法访问摄像头: ', error);
|
||||||
|
if (error.name === 'NotAllowedError') {
|
||||||
|
showMessage('请授予摄像头访问权限', 'error');
|
||||||
|
} else if (error.name === 'NotFoundError' || error.name === 'DevicesNotFoundError') {
|
||||||
|
showMessage('未找到可用的摄像头设备', 'error');
|
||||||
|
} else {
|
||||||
|
showMessage('无法启动摄像头', 'error');
|
||||||
|
}
|
||||||
|
resetScanUI();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopScanning() {
|
||||||
|
if (!scanning) return;
|
||||||
|
|
||||||
|
if (stream) {
|
||||||
|
stream.getTracks().forEach(track => {
|
||||||
|
track.stop();
|
||||||
|
});
|
||||||
|
stream = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
scanning = false;
|
||||||
|
resetScanUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetScanUI() {
|
||||||
|
cameraContainer.style.display = 'none';
|
||||||
|
scanPlaceholder.style.display = 'flex';
|
||||||
|
scanResult.style.display = 'none';
|
||||||
|
stopButton.style.display = 'none';
|
||||||
|
scanButton.style.display = 'block';
|
||||||
|
if (remainingCount > 0 && expiryTime && expiryTime > new Date()) {
|
||||||
|
scanButton.disabled = false;
|
||||||
|
scanButton.classList.remove('disabled');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function tick() {
|
||||||
|
if (!scanning || !video.srcObject || video.paused || video.ended) return;
|
||||||
|
|
||||||
|
if (video.readyState === video.HAVE_ENOUGH_DATA) {
|
||||||
|
canvas.width = video.videoWidth;
|
||||||
|
canvas.height = video.videoHeight;
|
||||||
|
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
||||||
|
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||||
|
const code = jsQR(imageData.data, imageData.width, imageData.height, {
|
||||||
|
inversionAttempts: "dontInvert",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (code && code.data) {
|
||||||
|
handleScanResult(code.data);
|
||||||
|
stopScanning();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
requestAnimationFrame(tick);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleScanResult(data) {
|
||||||
|
cameraContainer.style.display = 'none';
|
||||||
|
scanPlaceholder.style.display = 'none';
|
||||||
|
scanResult.style.display = 'flex';
|
||||||
|
resultContent.textContent = "正在验证...";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const urlParams = new URLSearchParams(data.substring(data.indexOf('?') + 1));
|
||||||
|
qrCodeToken = urlParams.get('token');
|
||||||
|
|
||||||
|
if (qrCodeToken) {
|
||||||
|
callLoginAPI(qrCodeToken);
|
||||||
|
} else {
|
||||||
|
console.error("无法从二维码中提取token: ", data);
|
||||||
|
showMessage("二维码格式无效或无法识别", 'error');
|
||||||
|
resultContent.textContent = "二维码格式无效";
|
||||||
|
setTimeout(resetScanUI, 2000);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("处理二维码内容失败:", e, "Data:", data);
|
||||||
|
showMessage("处理二维码内容失败", 'error');
|
||||||
|
resultContent.textContent = "无法处理扫描内容";
|
||||||
|
setTimeout(resetScanUI, 2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function callLoginAPI(token) {
|
||||||
|
resultContent.textContent = "正在登录...";
|
||||||
|
|
||||||
|
fetch('/login', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json; charset=utf-8"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({"token": token, "link_uuid": "{{ link_info.link_uuid }}"}),
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
return response.json().then(errData => {
|
||||||
|
throw new Error(errData.message || `HTTP error! status: ${response.status}`);
|
||||||
|
}).catch(() => {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
if (data && data.status) {
|
||||||
|
remainingCount--;
|
||||||
|
remainingCountEl.textContent = parseInt(remainingCount);
|
||||||
|
resultContent.textContent = "登录成功!";
|
||||||
|
showMessage("登录成功!", 'success');
|
||||||
|
|
||||||
|
if (remainingCount <= 0) {
|
||||||
|
scanButton.disabled = true;
|
||||||
|
scanButton.classList.add('disabled');
|
||||||
|
showMessage("剩余次数已用完", 'warning');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
resultContent.textContent = "登录失败: " + (data.message || "未知错误");
|
||||||
|
showMessage("登录失败: " + (data.message || "未知错误"), 'error');
|
||||||
|
setTimeout(resetScanUI, 3000);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error("登录请求失败:", error);
|
||||||
|
resultContent.textContent = "登录请求失败";
|
||||||
|
showMessage(`登录请求失败: ${error.message}`, 'error');
|
||||||
|
setTimeout(resetScanUI, 3000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remainingCount <= 0) {
|
||||||
|
scanButton.disabled = true;
|
||||||
|
scanButton.classList.add('disabled');
|
||||||
|
showMessage("此链接剩余次数已用完", "warning");
|
||||||
|
}
|
||||||
|
if (expiryTime && expiryTime <= new Date()) {
|
||||||
|
scanButton.disabled = true;
|
||||||
|
scanButton.classList.add('disabled');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -155,13 +155,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
<!-- 引入Element UI组件库 -->
|
<!-- 引入Element UI组件库 -->
|
||||||
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
|
<!-- <script src="https://unpkg.com/element-ui/lib/index.js"></script> -->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/jsqr@1.4.0/dist/jsQR.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/jsqr@1.4.0/dist/jsQR.min.js"></script>
|
||||||
<script src="static/js/app.js"></script>
|
<script src="static/js/app.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var vConsole = new window.VConsole();
|
//var vConsole = new window.VConsole();
|
||||||
//将控制台输出重定向到我们的调试容器
|
//将控制台输出重定向到我们的调试容器
|
||||||
vConsole.execInContext(document.getElementById('debug-output'));
|
//vConsole.execInContext(document.getElementById('debug-output'));
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -13,7 +13,7 @@ class CloudDriveDatabase:
|
|||||||
self._create_tables()
|
self._create_tables()
|
||||||
|
|
||||||
def _create_tables(self):
|
def _create_tables(self):
|
||||||
"""创建所需的数据库表"""
|
"""创建所需的数据库表并确保表结构是最新的"""
|
||||||
# 1. 网盘驱动表
|
# 1. 网盘驱动表
|
||||||
self.cursor.execute('''
|
self.cursor.execute('''
|
||||||
CREATE TABLE IF NOT EXISTS drive_providers (
|
CREATE TABLE IF NOT EXISTS drive_providers (
|
||||||
@ -48,8 +48,23 @@ class CloudDriveDatabase:
|
|||||||
)
|
)
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
# 检查并添加expiry_time列到external_links表
|
||||||
|
self._add_column_if_not_exists('external_links', 'expiry_time', 'TEXT')
|
||||||
|
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
|
def _add_column_if_not_exists(self, table_name: str, column_name: str, column_type: str):
|
||||||
|
"""检查表是否存在指定列,如果不存在则添加"""
|
||||||
|
self.cursor.execute(f"PRAGMA table_info({table_name})")
|
||||||
|
columns = [column[1] for column in self.cursor.fetchall()]
|
||||||
|
if column_name not in columns:
|
||||||
|
try:
|
||||||
|
self.cursor.execute(f"ALTER TABLE {table_name} ADD COLUMN {column_name} {column_type}")
|
||||||
|
self.conn.commit()
|
||||||
|
print(f"已成功添加列 '{column_name}' 到表 '{table_name}'")
|
||||||
|
except sqlite3.OperationalError as e:
|
||||||
|
print(f"添加列 '{column_name}' 到表 '{table_name}' 时出错: {e}")
|
||||||
|
|
||||||
# 网盘驱动表操作
|
# 网盘驱动表操作
|
||||||
def add_drive_provider(self, provider_name: str, config_vars: Dict[str, Any], remarks: Optional[str] = None) -> bool:
|
def add_drive_provider(self, provider_name: str, config_vars: Dict[str, Any], remarks: Optional[str] = None) -> bool:
|
||||||
"""添加网盘服务商"""
|
"""添加网盘服务商"""
|
||||||
@ -202,7 +217,7 @@ class CloudDriveDatabase:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# 外链表操作
|
# 外链表操作
|
||||||
def create_external_link(self, drive_id: int, total_quota: float, remarks: Optional[str] = None) -> Optional[str]:
|
def create_external_link(self, drive_id: int, total_quota: float, remarks: Optional[str] = None, expiry_time: str = None) -> Optional[str]:
|
||||||
"""创建外链"""
|
"""创建外链"""
|
||||||
try:
|
try:
|
||||||
# 检查用户网盘是否存在
|
# 检查用户网盘是否存在
|
||||||
@ -213,10 +228,15 @@ class CloudDriveDatabase:
|
|||||||
link_uuid = str(uuid.uuid4())
|
link_uuid = str(uuid.uuid4())
|
||||||
while self.get_external_link_by_uuid(link_uuid):
|
while self.get_external_link_by_uuid(link_uuid):
|
||||||
link_uuid = str(uuid.uuid4())
|
link_uuid = str(uuid.uuid4())
|
||||||
|
|
||||||
|
# 如果没有指定到期时间,默认为24小时后
|
||||||
|
if not expiry_time:
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
expiry_time = (datetime.now() + timedelta(hours=24)).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
self.cursor.execute(
|
self.cursor.execute(
|
||||||
"INSERT INTO external_links (drive_id, total_quota, used_quota, link_uuid, remarks) VALUES (?, ?, 0, ?, ?)",
|
"INSERT INTO external_links (drive_id, total_quota, used_quota, link_uuid, remarks, expiry_time) VALUES (?, ?, 0, ?, ?, ?)",
|
||||||
(drive_id, total_quota, link_uuid, remarks)
|
(drive_id, total_quota, link_uuid, remarks, expiry_time)
|
||||||
)
|
)
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
return link_uuid
|
return link_uuid
|
||||||
|
@ -1,15 +1,31 @@
|
|||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
def login_quark(token):
|
def login_quark(token,config_vars):
|
||||||
"""
|
"""
|
||||||
夸克登录
|
夸克登录
|
||||||
:param token: 登录token
|
:param token: 登录token
|
||||||
:return: 是否登录成功
|
:return: 是否登录成功
|
||||||
"""
|
"""
|
||||||
|
aa = {
|
||||||
|
'data': {
|
||||||
|
'client_id': '515',
|
||||||
|
'kps_wg': '',
|
||||||
|
'request_id': '',
|
||||||
|
'sign_wg': '',
|
||||||
|
'token': '',
|
||||||
|
'v': '1.2',
|
||||||
|
'vcode': ''
|
||||||
|
},
|
||||||
|
'kps_wg': '',
|
||||||
|
'redirect_uri': 'https://uop.quark.cn/cas/ajax/loginWithKpsAndQrcodeToken',
|
||||||
|
'sign_wg': ''
|
||||||
|
}
|
||||||
|
if len(config_vars) > 0:
|
||||||
|
_config_vars = config_vars.get("data")
|
||||||
s = requests.Session()
|
s = requests.Session()
|
||||||
s.headers = {
|
s.headers = {
|
||||||
'Accept': 'application/json, text/plain, */*',
|
'Accept': 'application/json, text/plain, */*',
|
||||||
@ -22,23 +38,25 @@ def login_quark(token):
|
|||||||
'sec-ch-ua-mobile': '?1',
|
'sec-ch-ua-mobile': '?1',
|
||||||
'sec-ch-ua-platform': '"Android"'
|
'sec-ch-ua-platform': '"Android"'
|
||||||
}
|
}
|
||||||
sign_wg = "AAQHaE4ww2nnIPvofH2SfMv3N6OplcPRjxlgScTZozm/ZCMfQP74bsMLyKW883hZCGY="
|
# sign_wg = "AAQHaE4ww2nnIPvofH2SfMv3N6OplcPRjxlgScTZozm/ZCMfQP74bsMLyKW883hZCGY="
|
||||||
kps_wg = "AARWcp9UM71t5VzV9i5pBJ4dLXjJ7EZL5a9qz2QVVQtkkmcqS4wQGYtk38CRzW6HH4+5c7qsB9/EtUgkWcd8x/k7h9+PmAHUDvxKHUWnX7iL3h2fH86XJ4cEqwvUnQ77QGs=";
|
# kps_wg = "AARWcp9UM71t5VzV9i5pBJ4dLXjJ7EZL5a9qz2QVVQtkkmcqS4wQGYtk38CRzW6HH4+5c7qsB9/EtUgkWcd8x/k7h9+PmAHUDvxKHUWnX7iL3h2fH86XJ4cEqwvUnQ77QGs="
|
||||||
vcode = int(time.time() * 1000) # 相当于JavaScript中的Date.now(),返回当前时间的毫秒数
|
vcode = int(time.time() * 1000) # 相当于JavaScript中的Date.now(),返回当前时间的毫秒数
|
||||||
request_id = vcode + 5
|
request_id = vcode + 5
|
||||||
is_login = False
|
is_login = False
|
||||||
url = 'https://uop.quark.cn/cas/ajax/loginWithKpsAndQrcodeToken'
|
url = 'https://uop.quark.cn/cas/ajax/loginWithKpsAndQrcodeToken'
|
||||||
queryParams = 'uc_param_str=dsdnfrpfbivesscpgimibtbmnijblauputogpintnwktprchmt&ds=AANx101uRUMl2l2Ot6hnNFQe%2F%2B%2Fmm2JHIQ2Gw28Yo%2FGa2g%3D%3D&dn=85507213341-12b7840e&fr=android&pf=3300&bi=35825&ve=7.9.2.771&ss=407x853&pc=AASZtg30J6cEZGl0meB9hj0E8U9brcrtYubvdgeP%2BOWEz0vpfLJPZfnxjOm%2Fxul3xW7j9n4com6OOMCVoviOk4QO&gi=bTkwBCbSxTOAXUWiJmZaMx19GVxo&mi=2312DRA50C&ni=bTkwBHemD30PJEvXSga2ki3ciKarGqoowKzIca0Rj7inq8M%3D&la=zh&ut=AANx101uRUMl2l2Ot6hnNFQe%2F%2B%2Fmm2JHIQ2Gw28Yo%2FGa2g%3D%3D&nt=5&nw=0&kt=4&pr=ucpro&ch=kk%40store&mt=73ABKMNLPFhfbAKV15H%2BDiEkS8zWXwui&__dt=31265&__t=' + str(int(time.time() * 1000))
|
queryParams = config_vars.get("queryParams") + str(int(time.time() * 1000))
|
||||||
data = {
|
data = {
|
||||||
'client_id': '532',
|
'client_id': _config_vars.get("client_id"),
|
||||||
'v': '1.2',
|
'v': _config_vars.get("v"),
|
||||||
'request_id': request_id,
|
'request_id': request_id,
|
||||||
'sign_wg': sign_wg,
|
'sign_wg': _config_vars.get("sign_wg"),
|
||||||
'kps_wg': kps_wg,
|
'kps_wg': _config_vars.get("kps_wg"),
|
||||||
'vcode': vcode,
|
'vcode': vcode,
|
||||||
'token': token
|
'token': token
|
||||||
}
|
}
|
||||||
|
print(data)
|
||||||
res =s.post(url, data=data, params=queryParams)
|
res =s.post(url, data=data, params=queryParams)
|
||||||
|
print(res.json())
|
||||||
if res.json().get('status') == 2000000:
|
if res.json().get('status') == 2000000:
|
||||||
is_login = True
|
is_login = True
|
||||||
return is_login
|
return is_login
|
Loading…
x
Reference in New Issue
Block a user