mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-21 13:36:25 -08:00
refactor: 👽 Same but with embedSize and embedColor
This commit is contained in:
parent
687e083ca2
commit
11e0494137
|
@ -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(
|
||||
"/delete_account",
|
||||
requiresAccount,
|
||||
|
|
|
@ -266,12 +266,21 @@ export function embedColor(optPicker) {
|
|||
}
|
||||
]).then((exp) => {
|
||||
if (exp && exp.selected) {
|
||||
fetch(`/auth/embedcolor`,{method:"POST", body:JSON.stringify({
|
||||
color:exp.color
|
||||
})}).then((response) => {
|
||||
|
||||
fetch(`/api/v1/account/customization/embed/color`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
color: exp.color,
|
||||
}),
|
||||
}).then((response) => {
|
||||
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()
|
||||
|
@ -297,12 +306,21 @@ export function embedSize(optPicker) {
|
|||
}
|
||||
]).then((exp) => {
|
||||
if (exp && exp.selected !== null) {
|
||||
fetch(`/auth/embedsize`,{method:"POST", body:JSON.stringify({
|
||||
largeImage:exp.selected
|
||||
})}).then((response) => {
|
||||
|
||||
fetch(`/api/v1/account/customization/embed/size`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
largeImage: exp.selected,
|
||||
}),
|
||||
}).then((response) => {
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue