Add setting for d->m URL previews

This commit is contained in:
Cadence Ember
2025-02-18 01:11:26 +13:00
parent efd7cb3fd4
commit 6b919d2a82
6 changed files with 51 additions and 2 deletions

View File

@@ -102,13 +102,24 @@ block body
#autocreate-loading
if space_id
h3.mt32.fs-category URL preview
.s-card
form.d-flex.ai-center.g8
label.s-label.fl-grow1(for="url-preview")
| Show Discord's URL previews on Matrix
p.s-description Shows info about links posted to chat. Discord's previews are generally better quality than Synapse's, especially for social media and videos.
- let value = !!select("guild_space", "url_preview", {guild_id}).pluck().get()
input(type="hidden" name="guild_id" value=guild_id)
input.s-toggle-switch.order-last#autocreate(name="url_preview" type="checkbox" hx-post="/api/url-preview" hx-indicator="#url-preview-loading" hx-disabled-elt="this" checked=value autocomplete="off")
#url-preview-loading
h3.mt32.fs-category Presence
.s-card
form.d-flex.ai-center.g8
label.s-label.fl-grow1(for="presence")
| Show online statuses on Matrix
p.s-description This might cause lag on really big Discord servers.
- let value = !!select("guild_space", "presence", {guild_id}).pluck().get()
- value = !!select("guild_space", "presence", {guild_id}).pluck().get()
input(type="hidden" name="guild_id" value=guild_id)
input.s-toggle-switch.order-last#autocreate(name="presence" type="checkbox" hx-post="/api/presence" hx-indicator="#presence-loading" hx-disabled-elt="this" checked=value autocomplete="off")
#presence-loading

View File

@@ -27,6 +27,10 @@ const schema = {
guild_id: z.string(),
autocreate: z.string().optional()
}),
urlPreview: z.object({
guild_id: z.string(),
url_preview: z.string().optional()
}),
presence: z.object({
guild_id: z.string(),
presence: z.string().optional()
@@ -57,6 +61,16 @@ as.router.post("/api/autocreate", defineEventHandler(async event => {
return null // 204
}))
as.router.post("/api/url-preview", defineEventHandler(async event => {
const parsedBody = await readValidatedBody(event, schema.urlPreview.parse)
const managed = await auth.getManagedGuilds(event)
if (!managed.has(parsedBody.guild_id)) throw createError({status: 403, message: "Forbidden", data: "Can't change settings for a guild you don't have Manage Server permissions in"})
db.prepare("UPDATE guild_space SET url_preview = ? WHERE guild_id = ?").run(+!!parsedBody.url_preview, parsedBody.guild_id)
return null // 204
}))
as.router.post("/api/presence", defineEventHandler(async event => {
const parsedBody = await readValidatedBody(event, schema.presence.parse)
const managed = await auth.getManagedGuilds(event)