refactor: 👽 Remove v0 CSS API and migrate client to v1 CSS API

This commit is contained in:
Jack W. 2024-03-07 21:20:05 -05:00
parent 756077148a
commit 687e083ca2
No known key found for this signature in database
5 changed files with 19 additions and 41 deletions

View file

@ -19,7 +19,7 @@
<link <link
rel="stylesheet" rel="stylesheet"
href="/auth/customCSS" href="/api/v1/account/customization/css"
> >
<link <link

View file

@ -17,7 +17,7 @@
<link <link
rel="stylesheet" rel="stylesheet"
href="/auth/customCSS" href="/api/v1/account/customization/css"
> >
<meta <meta

View file

@ -15,7 +15,7 @@
href="/static/assets/icons/icon_temp.svg" href="/static/assets/icons/icon_temp.svg"
/> />
<link rel="stylesheet" href="/auth/customCSS" /> <link rel="stylesheet" href="/api/v1/account/customization/css" />
<meta <meta
name="viewport" name="viewport"

View file

@ -164,32 +164,6 @@ export default function (files: Files) {
} }
) )
authRoutes.post(
"/customcss",
requiresAccount,
requiresPermissions("customize"),
// Used body-parser
async (ctx) => {
const body = await ctx.req.json()
let acc = ctx.get("account") as Accounts.Account
if (typeof body.fileId != "string") body.fileId = undefined
if (
!body.fileId ||
(body.fileId.match(id_check_regex) == body.fileId &&
body.fileId.length <= config.maxUploadIdLength)
) {
acc.customCSS = body.fileId || undefined
if (!body.fileId) delete acc.customCSS
Accounts.save()
return ctx.text(`custom css saved`)
} else {
return ctx.text("invalid fileid", 400)
}
}
)
authRoutes.post( authRoutes.post(
"/embedcolor", "/embedcolor",
requiresAccount, requiresAccount,
@ -626,10 +600,5 @@ export default function (files: Files) {
} }
) )
authRoutes.get("/customCSS", async (ctx) => {
let acc = ctx.get("account")
if (acc?.customCSS) return ctx.redirect(`/file/${acc.customCSS}`)
else return ctx.text("")
})
return authRoutes return authRoutes
} }

View file

@ -225,16 +225,25 @@ export function customcss(optPicker) {
} }
]).then((exp) => { ]).then((exp) => {
if (exp && exp.selected) { if (exp && exp.selected) {
fetch(`/auth/customcss`,{method:"POST", body:JSON.stringify({ fetch(`/api/v1/account/customization/css`, {
fileId:exp.fileid method: "PUT",
})}).then((response) => { body: JSON.stringify({
fileId: exp.fileid,
}),
}).then((response) => {
if (response.status != 200) { if (response.status != 200) {
optPicker.picker(`${response.status} ${response.headers.get("x-backup-status-message") || response.statusText || ""}`,[]) optPicker.picker(
`${response.status} ${
response.headers.get("x-backup-status-message") ||
response.statusText ||
""
}`,
[]
)
} }
fetchAccountData() fetchAccountData()
refreshNeeded.set(true); refreshNeeded.set(true)
}) })
} }
}) })
@ -300,4 +309,4 @@ export function embedSize(optPicker) {
}) })
} }
}) })
} }