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 = ''
saveMessage.value = ''
try {
const resp = await fetch(`${markbaseUrl.value}/api/v2/config`)
if (!resp.ok) {
const errData = await resp.json().catch(() => null)
const errMsg = errData?.error || resp.statusText || ''
// MarkBase config may return 500 if still running old version requiring postgresql
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 || ''
const resp = await fetch(`${markbaseUrl.value}/api/v2/settings`)
if (!resp.ok) throw new Error(`HTTP ${resp.status}`)
const data = await resp.json()
if (!data.success) throw new Error(data.error || 'Failed to load settings')
uploadPath.value = data.settings?.server?.upload_path || ''
} catch (e: any) {
settingsError.value = 'Failed to load settings: ' + (e.message || e)
}
@@ -1058,9 +1051,13 @@ async function saveUploadPath() {
saveMessage.value = ''
saveError.value = false
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()
if (data.ok) {
if (data.success) {
saveMessage.value = 'Upload path saved successfully'
} else {
saveError.value = true