完善: 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
+61
View File
@@ -0,0 +1,61 @@
{% extends "base.html" %}
{% block title %}{% if edit_id %}编辑记事本{% else %}新建记事本{% endif %}{% endblock %}
{% block content %}
<div class="page-title">
<h1>{% if edit_id %}编辑记事本{% else %}新建记事本{% endif %}</h1>
</div>
<div class="card">
<div class="card-body">
<form id="note-form">
<div class="form-group">
<label>标题</label>
<input type="text" name="title" class="form-control" id="note-title" required>
</div>
<div class="form-group">
<label>内容(支持 Markdown)</label>
<textarea name="content" class="form-control" id="note-content" style="min-height:300px;"></textarea>
</div>
<div style="display:flex;gap:8px;">
<button type="submit" class="btn btn-primary">保存</button>
<a href="/notes/" class="btn">取消</a>
</div>
</form>
</div>
</div>
<script>
{% if edit_id %}
(async function() {
var id = {{ edit_id }};
var res = await fetch('/api/notes/' + id + '/');
var data = await res.json();
if (!data.success) { window.location.href = '/notes/'; return; }
document.getElementById('note-title').value = data.note.title;
document.getElementById('note-content').value = data.note.content;
})();
{% endif %}
document.getElementById('note-form').addEventListener('submit', async function(e) {
e.preventDefault();
var fd = new FormData(this);
fd.append('csrf_token', CSRF_TOKEN);
{% if edit_id %}
var url = '/api/notes/{{ edit_id }}/edit/';
{% else %}
var url = '/api/notes/';
{% endif %}
var r = await fetch(url, { method: 'POST', body: fd });
var data = await r.json();
if (data.success) {
{% if edit_id %}
window.location.href = '/notes/{{ edit_id }}/';
{% else %}
window.location.href = '/notes/' + data.id + '/';
{% endif %}
} else {
alert(data.error || '操作失败');
}
});
</script>
{% endblock %}