mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-08 23:07:54 +00:00
Implement media resizing using Discord media cache (#470)
* Implement media resizing using Discord media cache Improve performance by offloading image scaling to Discord Only apply the resizing to images stored in the Discord CDN Set the format of the resized images to WebP for improved performance * Implemented suggestion for improved regex
This commit is contained in:
parent
7aa4d49a97
commit
adaddb579e
5 changed files with 29 additions and 6 deletions
18
dashboard/src/api/resize-media.ts
Normal file
18
dashboard/src/api/resize-media.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
const discordCDNAttachmentRegex =
|
||||
/^https:\/\/cdn\.discordapp\.com\/attachments\/([^?]+)/i
|
||||
|
||||
const resizeMedia = (
|
||||
mediaURL: string,
|
||||
dimensions?: number[],
|
||||
format?: string,
|
||||
) =>
|
||||
mediaURL.replace(
|
||||
discordCDNAttachmentRegex,
|
||||
`https://media.discordapp.net/attachments/$1?width=${
|
||||
dimensions?.[0] ?? 256
|
||||
}&height=${dimensions?.[1] ?? dimensions?.[0] ?? 256}&format=${
|
||||
format ?? 'webp'
|
||||
}`,
|
||||
)
|
||||
|
||||
export default resizeMedia
|
||||
Loading…
Add table
Add a link
Reference in a new issue