完善: CSRF安全修复 + 后台任务管理 + 压测全模块覆盖 + 文档
This commit is contained in:
@@ -4,7 +4,12 @@
|
||||
{% block content %}
|
||||
<div class="page-header">
|
||||
<h2>文件管理</h2>
|
||||
<div>
|
||||
<div style="display:flex;gap:8px;align-items:center;">
|
||||
<form method="get" style="display:flex;gap:8px;align-items:center;">
|
||||
<input type="text" name="q" class="form-control" style="width:200px;" placeholder="搜索文件名..." value="{{ search_q }}">
|
||||
<button type="submit" class="btn btn-sm btn-primary">搜索</button>
|
||||
{% if search_q %}<a href="/admin/files/" class="btn btn-sm">清除</a>{% endif %}
|
||||
</form>
|
||||
<form method="post" enctype="multipart/form-data" style="display:flex;gap:8px;align-items:center;">
|
||||
<input type="file" name="file" class="form-control" style="width:auto;" required>
|
||||
<button type="submit" class="btn btn-primary btn-sm">上传</button>
|
||||
@@ -26,21 +31,39 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
{% for file in files %}
|
||||
<div class="file-item">
|
||||
<div class="file-item" style="flex-wrap:wrap;">
|
||||
<span class="icon" style="margin-right:10px;">{% if file.is_dir %}📁{% else %}📄{% endif %}</span>
|
||||
<span class="name">
|
||||
<span class="name" style="min-width:150px;">
|
||||
{% if file.is_dir %}
|
||||
<a href="/admin/files/?path={{ file.path }}">{{ file.name }}</a>
|
||||
{% else %}
|
||||
<a href="/admin/files/download/?path={{ file.path }}" target="_blank">{{ file.name }}</a>
|
||||
<a href="/uploads/{{ file.path }}" target="_blank">{{ file.name }}</a>
|
||||
{% endif %}
|
||||
</span>
|
||||
{% if not file.is_dir %}
|
||||
<span class="size">{{ file.size }}</span>
|
||||
{% endif %}
|
||||
<span class="date">{{ file.modified }}</span>
|
||||
<a href="/admin/files/delete/?path={{ file.path }}" class="btn btn-sm btn-danger" onclick="return confirm('确定删除 {{ file.name }} 吗?')">删除</a>
|
||||
{% if not file.is_dir %}
|
||||
{% if file.ext in ['png', 'jpg', 'jpeg', 'gif', 'svg', 'webp'] %}
|
||||
<button class="btn btn-sm btn-success" onclick="copyMarkdown('{{ file.name }}', '/uploads/{{ file.path }}')">复制图片链接</button>
|
||||
{% else %}
|
||||
<button class="btn btn-sm btn-info" onclick="copyLink('/uploads/{{ file.path }}')">复制链接</button>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<form method="post" action="/admin/files/delete/" style="display:inline;" onsubmit="return confirm('确定删除 {{ file.name }} 吗?')">
|
||||
<input type="hidden" name="path" value="{{ file.path }}">
|
||||
{% if search_q %}<input type="hidden" name="dir" value="">{% else %}<input type="hidden" name="dir" value="{{ current_path }}">{% endif %}
|
||||
<button type="submit" class="btn btn-sm btn-danger">删除</button>
|
||||
</form>
|
||||
</div>
|
||||
{% if not file.is_dir %}
|
||||
{% if file.ext in ['png', 'jpg', 'jpeg', 'gif', 'svg', 'webp'] %}
|
||||
<div class="file-item" style="padding:8px 12px 12px 42px;border-bottom:1px solid var(--border);">
|
||||
<img src="/uploads/{{ file.path }}" style="max-width:200px;max-height:120px;border-radius:4px;border:1px solid var(--border);object-fit:cover;" alt="{{ file.name }}">
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
@@ -51,4 +74,50 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function copyMarkdown(filename, url) {
|
||||
var md = '';
|
||||
navigator.clipboard.writeText(md).then(function() {
|
||||
showToast('已复制 Markdown 图片语法: ' + md);
|
||||
}).catch(function() {
|
||||
// Fallback
|
||||
var ta = document.createElement('textarea');
|
||||
ta.value = md;
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(ta);
|
||||
alert('已复制: ' + md);
|
||||
});
|
||||
}
|
||||
|
||||
function copyLink(url) {
|
||||
navigator.clipboard.writeText(url).then(function() {
|
||||
showToast('已复制链接: ' + url);
|
||||
}).catch(function() {
|
||||
var ta = document.createElement('textarea');
|
||||
ta.value = url;
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(ta);
|
||||
alert('已复制: ' + url);
|
||||
});
|
||||
}
|
||||
|
||||
function showToast(msg) {
|
||||
var container = document.querySelector('.toast-container');
|
||||
if (!container) {
|
||||
container = document.createElement('div');
|
||||
container.className = 'toast-container';
|
||||
document.body.appendChild(container);
|
||||
}
|
||||
var toast = document.createElement('div');
|
||||
toast.className = 'toast toast-success';
|
||||
toast.textContent = msg;
|
||||
container.appendChild(toast);
|
||||
setTimeout(function() { toast.remove(); }, 3000);
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user