Make imagor optional
This commit is contained in:
parent
5bbe2666d0
commit
5b463ee156
@ -17,22 +17,25 @@ export const DEFAULT_FETCH_OPTIONS: any = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getProxyUrl = (url: URL, width: number, height: number) => {
|
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?
|
const secret = Config.get().security.jwtSecret; // maybe shouldn't use this?
|
||||||
width = Math.min(width || 500, resizeWidthMax || width);
|
width = Math.min(width || 500, resizeWidthMax || width);
|
||||||
height = Math.min(height || 500, resizeHeightMax || width);
|
height = Math.min(height || 500, resizeHeightMax || width);
|
||||||
|
|
||||||
let path = `${width}x${height}/${url.host}${url.pathname}`
|
// Imagor
|
||||||
|
if (imagorServerUrl) {
|
||||||
const hash = crypto.createHmac('sha1', secret)
|
let path = `${width}x${height}/${url.host}${url.pathname}`;
|
||||||
.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}`;
|
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 => {
|
const getMeta = ($: cheerio.CheerioAPI, name: string): string | undefined => {
|
||||||
|
@ -52,6 +52,7 @@ export interface ConfigValue {
|
|||||||
endpointPrivate: string | null;
|
endpointPrivate: string | null;
|
||||||
resizeHeightMax: number | null;
|
resizeHeightMax: number | null;
|
||||||
resizeWidthMax: number | null;
|
resizeWidthMax: number | null;
|
||||||
|
imagorServerUrl: string | null;
|
||||||
};
|
};
|
||||||
api: {
|
api: {
|
||||||
defaultVersion: string;
|
defaultVersion: string;
|
||||||
@ -222,6 +223,7 @@ export const DefaultConfigOptions: ConfigValue = {
|
|||||||
endpointPublic: null,
|
endpointPublic: null,
|
||||||
resizeHeightMax: 1000,
|
resizeHeightMax: 1000,
|
||||||
resizeWidthMax: 1000,
|
resizeWidthMax: 1000,
|
||||||
|
imagorServerUrl: null,
|
||||||
},
|
},
|
||||||
api: {
|
api: {
|
||||||
defaultVersion: "9",
|
defaultVersion: "9",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user