feat: integrate MarkBase Settings API (GET/POST /api/v2/settings)

- Replaced deprecated /api/v2/config with new /api/v2/settings
- loadSettings() now uses GET /api/v2/settings (structured JSON)
- saveUploadPath() now uses POST /api/v2/settings
- Removed PostgreSQL migration error handling (no longer needed)
- Settings page now works correctly with SQLite-only MarkBase
This commit is contained in:
2026-10-27 02:06:57 +08:00
parent 59bcd9a9b5
commit 4129c174ed

View File

@@ -1036,18 +1036,11 @@ async function loadSettings() {
settingsError.value = '' settingsError.value = ''
saveMessage.value = '' saveMessage.value = ''
try { try {
const resp = await fetch(`${markbaseUrl.value}/api/v2/config`) const resp = await fetch(`${markbaseUrl.value}/api/v2/settings`)
if (!resp.ok) { if (!resp.ok) throw new Error(`HTTP ${resp.status}`)
const errData = await resp.json().catch(() => null) const data = await resp.json()
const errMsg = errData?.error || resp.statusText || '' if (!data.success) throw new Error(data.error || 'Failed to load settings')
// MarkBase config may return 500 if still running old version requiring postgresql uploadPath.value = data.settings?.server?.upload_path || ''
if (errMsg.includes('postgresql')) {
throw new Error('MarkBase needs restart (PostgreSQL→SQLite migration)')
}
throw new Error(`HTTP ${resp.status}: ${errMsg}`)
}
const cfg = await resp.json()
uploadPath.value = cfg.server?.upload_path || ''
} catch (e: any) { } catch (e: any) {
settingsError.value = 'Failed to load settings: ' + (e.message || e) settingsError.value = 'Failed to load settings: ' + (e.message || e)
} }
@@ -1058,9 +1051,13 @@ async function saveUploadPath() {
saveMessage.value = '' saveMessage.value = ''
saveError.value = false saveError.value = false
try { try {
const resp = await fetch(`${markbaseUrl.value}/api/v2/config/edit?key=server.upload_path&value=${encodeURIComponent(uploadPath.value)}`, { method: 'POST' }) const resp = await fetch(`${markbaseUrl.value}/api/v2/settings`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ server: { upload_path: uploadPath.value } })
})
const data = await resp.json() const data = await resp.json()
if (data.ok) { if (data.success) {
saveMessage.value = 'Upload path saved successfully' saveMessage.value = 'Upload path saved successfully'
} else { } else {
saveError.value = true saveError.value = true