fix: 统一 CSRF token 获取方式,修复 token 刷新后缓存失效
- utils.js getCSRFToken() 改为从 cookie 优先读取,meta 标签作为后备
- show.html 5处移除 csrfToken 缓存变量,改用 getCSRFToken() 动态获取
- studio/posts.html/drafts.html 移除 {{ .CSRFToken }} 模板硬编码
- studio-editor.js 移除本地 getCsrfToken(),改用共享 getCSRFToken()
- settings/index.html messages/index.html 改用 getCSRFToken()
- admin posts.js/comments.js 移除本地/死代码 CSRF 获取,统一用共享方法
This commit is contained in:
@ -1,17 +1,13 @@
|
||||
/**
|
||||
* Studio Editor — 创作中心 Vditor 编辑器
|
||||
* 基于 editor.js,使用 /api/studio/posts 端点
|
||||
* CSRF token 由 shared/utils.js 的 getCSRFToken() 统一提供
|
||||
*/
|
||||
|
||||
let vditor = null
|
||||
let draftTimer = null
|
||||
let submitting = false
|
||||
|
||||
function getCsrfToken() {
|
||||
var match = document.cookie.match(/(?:^|;\s*)mlb_csrf=([^;]*)/)
|
||||
return match ? match[1] : ''
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const container = document.getElementById('vditor')
|
||||
if (!container) return
|
||||
@ -186,7 +182,7 @@ async function handleSubmit(e) {
|
||||
method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': getCsrfToken(),
|
||||
'X-CSRF-Token': getCSRFToken(),
|
||||
},
|
||||
body: JSON.stringify({ title, body }),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user