新增数据库支持,创建CloudDriveDatabase类以管理网盘驱动和用户网盘信息,更新主程序以实现数据库连接和相关API接口,完善管理员面板功能,更新README文档以描述数据库设计。
This commit is contained in:
@ -131,6 +131,18 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<!-- 账号列表将通过JavaScript动态填充 -->
|
||||
<tr>
|
||||
{% for user_drive in alluser_drives %}
|
||||
<td>{{user_drive.provider_name}}</td>
|
||||
<td>{{user_drive.provider_name}}</td>
|
||||
<td><span class="badge bg-success">正常</span></td>
|
||||
<td>1.5TB / 2TB</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-danger"><i class="bi bi-trash"></i></button>
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@ -201,23 +213,30 @@
|
||||
<form id="addAccountForm">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">网盘类型</label>
|
||||
<select class="form-select" name="type" required>
|
||||
<select class="form-select" name="type" id="driveType" required>
|
||||
<option value="">请选择网盘类型</option>
|
||||
<option value="aliyun">阿里云盘</option>
|
||||
<option value="baidu">百度网盘</option>
|
||||
{% set provider_options = providers %}
|
||||
{% for provider in provider_options %}
|
||||
<option value="{{ provider.provider_name }}" data-needs-api="{{ provider.provider_name }}">{{ provider.provider_name}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">账号名称</label>
|
||||
<input type="text" class="form-control" name="name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">API密钥</label>
|
||||
<input type="password" class="form-control" name="api_key" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">访问令牌</label>
|
||||
<input type="password" class="form-control" name="access_token" required>
|
||||
<label class="form-label">配置信息 (JSON)</label>
|
||||
<div class="position-relative">
|
||||
<div id="jsonEditor" class="border rounded" style="height: 200px; font-family: monospace;"></div>
|
||||
<textarea class="form-control d-none" name="config_json" id="jsonConfig"></textarea>
|
||||
<div class="position-absolute top-0 end-0 p-2">
|
||||
<button class="btn btn-sm btn-outline-secondary" type="button" id="formatJsonBtn">
|
||||
<i class="bi bi-code-square"></i> 格式化
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between mt-1">
|
||||
<div class="form-text">请输入有效的JSON格式配置信息</div>
|
||||
<div class="form-text text-end"><span id="jsonLineCount">0</span> 行 | <span id="jsonCharCount">0</span> 字符</div>
|
||||
</div>
|
||||
<div id="jsonError" class="invalid-feedback"></div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@ -230,6 +249,43 @@
|
||||
</div>
|
||||
|
||||
|
||||
<!-- 编辑网盘账号模态框 -->
|
||||
<div class="modal fade" id="editudriveModal" 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">
|
||||
<form id="editudriveForm">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">配置信息 (JSON)</label>
|
||||
<div class="position-relative">
|
||||
<div id="jsonEditor1" class="border rounded" style="height: 200px; font-family: monospace;"></div>
|
||||
<textarea class="form-control d-none" name="config_json" id="jsonConfig1"></textarea>
|
||||
<div class="position-absolute top-0 end-0 p-2">
|
||||
<button class="btn btn-sm btn-outline-secondary" type="button" id="formatJsonBtn">
|
||||
<i class="bi bi-code-square"></i> 格式化
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between mt-1">
|
||||
<div class="form-text">请输入有效的JSON格式配置信息</div>
|
||||
<div class="form-text text-end"><span id="jsonLineCount1">0</span> 行 | <span id="jsonCharCount1">0</span> 字符</div>
|
||||
</div>
|
||||
<div id="jsonError" class="invalid-feedback"></div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
|
||||
<button type="button" class="btn btn-primary" id="saveAccount">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 添加网盘外链模态框 -->
|
||||
<div class="modal fade" id="addExlinkModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
@ -279,6 +335,8 @@
|
||||
<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://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js" integrity="sha512-GZ1RIgZaSc8rnco/8CXfRdCpDxRCphenIiZ2ztLy3XQfCbQUSCuk8IudvNHxkRA3oUg6q0qejgN/qqyG1duv5Q==" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ext-language_tools.min.js"></script>
|
||||
<script>
|
||||
|
||||
// 导航切换
|
||||
@ -430,6 +488,162 @@
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
||||
// 添加Ace编辑器的CDN引用
|
||||
function loadAceEditor() {
|
||||
if (typeof ace === 'undefined') {
|
||||
// 如果ace未定义,直接初始化编辑器
|
||||
initAceEditor();
|
||||
} else {
|
||||
initAceEditor();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// json编辑器处理
|
||||
function initAceEditor() {
|
||||
// 初始化编辑器
|
||||
const editor = ace.edit("jsonEditor");
|
||||
const editor1 = ace.edit("jsonEditor1");
|
||||
|
||||
// 配置两个编辑器
|
||||
const configureEditor = function(editor, configId, lineCountId, charCountId) {
|
||||
editor.setTheme("ace/theme/monokai");
|
||||
editor.session.setMode("ace/mode/json");
|
||||
editor.setOptions({
|
||||
fontSize: "12pt",
|
||||
showPrintMargin: false,
|
||||
enableBasicAutocompletion: true,
|
||||
enableLiveAutocompletion: true
|
||||
});
|
||||
|
||||
// 同步到隐藏的textarea
|
||||
editor.getSession().on('change', function() {
|
||||
document.getElementById(configId).value = editor.getSession().getValue();
|
||||
document.getElementById(lineCountId).textContent = editor.getSession().getLength();
|
||||
document.getElementById(charCountId).textContent = editor.getSession().getValue().length;
|
||||
});
|
||||
};
|
||||
|
||||
// 应用配置到两个编辑器
|
||||
configureEditor(editor, 'jsonConfig', 'jsonLineCount', 'jsonCharCount');
|
||||
configureEditor(editor1, 'jsonConfig1', 'jsonLineCount1', 'jsonCharCount1');
|
||||
|
||||
// 格式化按钮
|
||||
document.getElementById('formatJsonBtn').addEventListener('click', function() {
|
||||
const activeEditor = document.activeElement.closest('#jsonEditor') ? editor :
|
||||
document.activeElement.closest('#jsonEditor1') ? editor1 : editor;
|
||||
const editorElement = activeEditor === editor ? 'jsonEditor' : 'jsonEditor1';
|
||||
|
||||
try {
|
||||
const json = JSON.parse(activeEditor.getSession().getValue());
|
||||
activeEditor.setValue(JSON.stringify(json, null, 2), -1);
|
||||
document.getElementById('jsonError').textContent = '';
|
||||
document.getElementById(editorElement).classList.remove('border-danger');
|
||||
} catch (e) {
|
||||
document.getElementById('jsonError').textContent = '无效的JSON格式: ' + e.message;
|
||||
document.getElementById('jsonError').style.display = 'block';
|
||||
document.getElementById(editorElement).classList.add('border-danger');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadAceEditor();
|
||||
});
|
||||
|
||||
// 设置默认JSON模板
|
||||
document.getElementById('driveType').addEventListener('change', function() {
|
||||
const editor = ace.edit("jsonEditor");
|
||||
const selectedType = this.value;
|
||||
|
||||
if (selectedType) {
|
||||
let defaultJson = {};
|
||||
|
||||
// 获取所有网盘提供商数据
|
||||
const providers = JSON.parse('{{ providers | tojson }}');
|
||||
|
||||
// 查找选中的网盘提供商
|
||||
const selectedProvider = providers.find(provider => provider.provider_name === selectedType);
|
||||
|
||||
if (selectedProvider && selectedProvider.config_vars) {
|
||||
// 如果找到对应的提供商配置,直接使用
|
||||
defaultJson = selectedProvider.config_vars;
|
||||
} else {
|
||||
// 如果没有找到对应配置,使用默认模板
|
||||
defaultJson = {
|
||||
"provider_name": selectedType,
|
||||
"config": {
|
||||
"api_key": "",
|
||||
"secret_key": "",
|
||||
"redirect_uri": ""
|
||||
},
|
||||
"auth": {
|
||||
"token": "",
|
||||
"expires_in": 0
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// 设置编辑器内容
|
||||
editor.setValue(JSON.stringify(defaultJson, null, 2), -1);
|
||||
}
|
||||
});
|
||||
|
||||
// 设置编辑用户驱动JSON模板
|
||||
document.getElementById('editudrivebtn').addEventListener('click', function() {
|
||||
const editor = ace.edit("jsonEditor1");
|
||||
const selectedtid = this.getAttribute('tid');
|
||||
if (selectedtid) {
|
||||
let defaultJson = {};
|
||||
|
||||
// 获取所有网盘提供商数据
|
||||
const user_drives = JSON.parse('{{ alluser_drives | tojson }}');
|
||||
// 查找选中的网盘提供商
|
||||
console.log(typeof(selectedtid));
|
||||
const selectedUdrive = user_drives.find(user_drive => user_drive.id == selectedtid);
|
||||
console.log(selectedtid,selectedUdrive)
|
||||
if (selectedUdrive && selectedUdrive.login_config) {
|
||||
// 如果找到对应的提供商配置,直接使用
|
||||
defaultJson = selectedUdrive.login_config;
|
||||
} else {
|
||||
// 如果没有找到对应配置,使用默认模板
|
||||
defaultJson = {
|
||||
"provider_name": selectedtid,
|
||||
"config": {
|
||||
"api_key": "",
|
||||
"secret_key": "",
|
||||
"redirect_uri": ""
|
||||
},
|
||||
"auth": {
|
||||
"token": "",
|
||||
"expires_in": 0
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// 设置编辑器内容
|
||||
editor.setValue(JSON.stringify(defaultJson, null, 2), -1);
|
||||
}
|
||||
});
|
||||
|
||||
// 初始化时设置一个空的JSON结构
|
||||
window.addEventListener('load', function() {
|
||||
const editor = ace.edit("jsonEditor");
|
||||
const editor1 = ace.edit("jsonEditor1");
|
||||
const emptyJson = {
|
||||
"provider_name": "",
|
||||
"config": {},
|
||||
"auth": {}
|
||||
};
|
||||
const jsonString = JSON.stringify(emptyJson, null, 2);
|
||||
|
||||
// 为两个编辑器设置相同的初始值
|
||||
editor.setValue(jsonString, -1);
|
||||
editor1.setValue(jsonString, -1);
|
||||
document.getElementById('jsonConfig').value = jsonString;
|
||||
document.getElementById('jsonConfig1').value = jsonString;
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user