diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-10-02 22:25:47 +1100 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-10-02 22:25:47 +1100 |
commit | 40620daa4e522a9355e7567fa47cf9dac04fb5e6 (patch) | |
tree | 0b942b3818ecde7075296a7613245550c54b09ed | |
parent | Use imagor for image resizing (diff) | |
download | server-40620daa4e522a9355e7567fa47cf9dac04fb5e6.tar.xz |
Make imagor optional
-rw-r--r-- | src/api/util/utility/EmbedHandlers.ts | 27 | ||||
-rw-r--r-- | src/util/entities/Config.ts | 2 |
2 files changed, 17 insertions, 12 deletions
diff --git a/src/api/util/utility/EmbedHandlers.ts b/src/api/util/utility/EmbedHandlers.ts index db73dcdc..65fecd4d 100644 --- a/src/api/util/utility/EmbedHandlers.ts +++ b/src/api/util/utility/EmbedHandlers.ts @@ -17,22 +17,25 @@ export const DEFAULT_FETCH_OPTIONS: any = { }; export const getProxyUrl = (url: URL, width: number, height: number) => { - const { endpointPublic, resizeWidthMax, resizeHeightMax } = Config.get().cdn; + const { endpointPublic, resizeWidthMax, resizeHeightMax, imagorServerUrl } = Config.get().cdn; const secret = Config.get().security.jwtSecret; // maybe shouldn't use this? width = Math.min(width || 500, resizeWidthMax || width); height = Math.min(height || 500, resizeHeightMax || width); - let path = `${width}x${height}/${url.host}${url.pathname}` - - const hash = crypto.createHmac('sha1', secret) - .update(path) - .digest('base64') - .replace(/\+/g, '-').replace(/\//g, '_'); - - // TODO: make configurable - return `https://media.understars.dev/${hash}/${path}`; - - // return `${endpointPublic}/external/resize/${encodeURIComponent(url.href)}?width=${width}&height=${height}`; + // Imagor + if (imagorServerUrl) { + let path = `${width}x${height}/${url.host}${url.pathname}`; + + const hash = crypto.createHmac('sha1', secret) + .update(path) + .digest('base64') + .replace(/\+/g, '-').replace(/\//g, '_'); + + return `${imagorServerUrl}/${hash}/${path}`; + } + + // Fosscord CDN resizer + return `${endpointPublic}/external/resize/${encodeURIComponent(url.href)}?width=${width}&height=${height}`; }; const getMeta = ($: cheerio.CheerioAPI, name: string): string | undefined => { diff --git a/src/util/entities/Config.ts b/src/util/entities/Config.ts index cd7a6923..42006fc9 100644 --- a/src/util/entities/Config.ts +++ b/src/util/entities/Config.ts @@ -52,6 +52,7 @@ export interface ConfigValue { endpointPrivate: string | null; resizeHeightMax: number | null; resizeWidthMax: number | null; + imagorServerUrl: string | null; }; api: { defaultVersion: string; @@ -222,6 +223,7 @@ export const DefaultConfigOptions: ConfigValue = { endpointPublic: null, resizeHeightMax: 1000, resizeWidthMax: 1000, + imagorServerUrl: null, }, api: { defaultVersion: "9", |