完善: CSRF安全修复 + 后台任务管理 + 压测全模块覆盖 + 文档

This commit is contained in:
张志挺
2026-08-26 15:21:48 +08:00
parent f39008193f
commit 36ac5f737b
61 changed files with 7281 additions and 867 deletions
+63
View File
@@ -0,0 +1,63 @@
{% extends "base.html" %}
{% block title %}编辑帖子 - {{ site_name }}{% endblock %}
{% block content %}
<div class="page-title">
<h1>编辑帖子</h1>
<p><a href="/my/topics/">← 返回我的帖子</a></p>
</div>
<div class="card">
<div class="card-body">
<div id="error-box" style="display:none;margin-bottom:12px;" class="form-error"></div>
<form id="edit-form">
<div class="form-group">
<label>标题</label>
<input type="text" name="title" id="edit-title" class="form-control" required>
</div>
<div class="form-group">
<label>分类</label>
<select name="category" id="edit-category" class="form-control"></select>
</div>
<div class="form-group">
<label>内容(支持 Markdown)</label>
<textarea name="content" id="edit-content" class="form-control" required></textarea>
</div>
<button type="submit" class="btn btn-primary">保存</button>
<a href="/my/topics/" class="btn">取消</a>
</form>
</div>
</div>
<script>
(async function() {
var id = window.location.pathname.match(/\/my\/topics\/(\d+)\/edit\//)[1];
var res = await fetch('/api/my/topics/' + id + '/');
var data = await res.json();
if (!data.success) return;
document.getElementById('edit-title').value = data.topic.title;
document.getElementById('edit-content').value = data.topic.content;
var sel = document.getElementById('edit-category');
sel.innerHTML = data.categories.map(function(c) {
var selected = c.value === data.topic.category ? ' selected' : '';
return '<option value="' + c.value + '"' + selected + '>' + c.label + '</option>';
}).join('');
document.getElementById('edit-form').addEventListener('submit', async function(e) {
e.preventDefault();
var fd = new FormData(this);
fd.append('csrf_token', CSRF_TOKEN);
var r = await fetch('/my/topics/' + id + '/edit/', { method: 'POST', body: fd });
var j = await r.json();
if (j.success) {
window.location.href = '/my/topics/';
} else {
var box = document.getElementById('error-box');
box.textContent = j.error || '保存失败';
box.style.display = 'block';
}
});
})();
</script>
{% endblock %}