fix(banners): save relative storage paths so admin preview survives refresh

Uploads were stored as host-specific URLs and a force-reload could wipe a just-saved image, leaving a broken dark-theme preview.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-26 18:01:26 +03:30
co-authored by Cursor
parent 3d63e2cf7f
commit 464995a43e
6 changed files with 142 additions and 26 deletions
+17 -4
View File
@@ -14,8 +14,13 @@ import {
function pickConstRow(res: Const | Const[] | null | undefined): Const | null {
if (!res) return null
if (Array.isArray(res)) {
const first = (res[0] as Const) ?? null
return isMeaningfulConstRow(first) ? first : null
const rows = res.filter(isMeaningfulConstRow)
if (!rows.length) return null
return rows.reduce((best, row) => {
const a = Number(best.id ?? best.const_id ?? 0)
const b = Number(row.id ?? row.const_id ?? 0)
return b > a ? row : best
})
}
return isMeaningfulConstRow(res) ? res : null
}
@@ -159,8 +164,16 @@ export async function saveAppBannersConst(
}
let nextId = id
if (id) {
await useAxios.put<Const>(`/admin/const/${id}`, { id, ...payload })
try {
const existingRes = await useAxios.get<Const | Const[]>(`/api/const/key/${APP_BANNERS_CONST_KEY}`)
const existing = pickConstRow(existingRes)
nextId = existing?.id ?? existing?.const_id ?? id
} catch {
// create below
}
if (nextId) {
await useAxios.put<Const>(`/admin/const/${nextId}`, { id: nextId, ...payload })
} else {
const created = await useAxios.post<Const>(`/admin/const`, { id: 0, ...payload })
nextId = created?.id ?? created?.const_id ?? null