refactor: 👽 Same but with embedSize and embedColor

This commit is contained in:
Jack W. 2024-03-07 21:24:14 -05:00
parent 687e083ca2
commit 11e0494137
No known key found for this signature in database
2 changed files with 28 additions and 55 deletions

View file

@ -164,51 +164,6 @@ export default function (files: Files) {
} }
) )
authRoutes.post(
"/embedcolor",
requiresAccount,
requiresPermissions("customize"),
// Used body-parser
async (ctx) => {
let acc = ctx.get("account") as Accounts.Account
const body = await ctx.req.json()
if (typeof body.color != "string") body.color = undefined
if (
!body.color ||
(body.color.toLowerCase().match(/[a-f0-9]+/) ==
body.color.toLowerCase() &&
body.color.length == 6)
) {
if (!acc.embed) acc.embed = {}
acc.embed.color = body.color || undefined
if (!body.color) delete acc.embed.color
Accounts.save()
return ctx.text(`custom embed color saved`)
} else {
return ctx.text("invalid hex code", 400)
}
}
)
authRoutes.post(
"/embedsize",
requiresAccount,
requiresPermissions("customize"),
// Used body-parser
async (ctx) => {
let acc = ctx.get("account") as Accounts.Account
const body = await ctx.req.json()
if (typeof body.largeImage != "boolean") body.color = false
if (!acc.embed) acc.embed = {}
acc.embed.largeImage = body.largeImage
if (!body.largeImage) delete acc.embed.largeImage
Accounts.save()
return ctx.text(`custom embed image size saved`)
}
)
authRoutes.post( authRoutes.post(
"/delete_account", "/delete_account",
requiresAccount, requiresAccount,

View file

@ -266,12 +266,21 @@ export function embedColor(optPicker) {
} }
]).then((exp) => { ]).then((exp) => {
if (exp && exp.selected) { if (exp && exp.selected) {
fetch(`/auth/embedcolor`,{method:"POST", body:JSON.stringify({ fetch(`/api/v1/account/customization/embed/color`, {
color:exp.color method: "POST",
})}).then((response) => { body: JSON.stringify({
color: exp.color,
}),
}).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()
@ -297,12 +306,21 @@ export function embedSize(optPicker) {
} }
]).then((exp) => { ]).then((exp) => {
if (exp && exp.selected !== null) { if (exp && exp.selected !== null) {
fetch(`/auth/embedsize`,{method:"POST", body:JSON.stringify({ fetch(`/api/v1/account/customization/embed/size`, {
largeImage:exp.selected method: "POST",
})}).then((response) => { body: JSON.stringify({
largeImage: exp.selected,
}),
}).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()