mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-02 16:38:14 +00:00
- delete the env var signal at root in favor for the env var class - this prevents the app from making unnecessary rerender, especially on load - fixed some eslint issues while treading through these files --------- Co-authored-by: wil <wil@storyteller.ai>
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import environmentVariables from "~/Classes/EnvironmentVariables";
|
|
|
|
class BucketConfig {
|
|
isLocalDev: boolean;
|
|
|
|
constructor() {
|
|
this.isLocalDev =
|
|
document.location.host.includes("localhost") ||
|
|
document.location.host.includes("jungle.horse") ||
|
|
document.location.host.startsWith("dev.");
|
|
}
|
|
|
|
// TODO: Prevent callers with undefined/null paths
|
|
getGcsUrl(bucketRelativePath: string | undefined | null): string {
|
|
const bucket = this.getBucket();
|
|
let path = bucketRelativePath;
|
|
if (path !== undefined && path !== null && !path.startsWith("/")) {
|
|
path = "/" + path;
|
|
}
|
|
const media_api_base_url = environmentVariables.values.GOOGLE_API;
|
|
return `${media_api_base_url}/${bucket}${path}`;
|
|
}
|
|
|
|
private getBucket(): string {
|
|
return this.isLocalDev ? "dev-vocodes-public" : "vocodes-public";
|
|
}
|
|
|
|
getCdnUrl(
|
|
bucketRelativePath: string,
|
|
width?: number,
|
|
quality?: number,
|
|
): string {
|
|
const cndBasePath = environmentVariables.values.CDN_API;
|
|
const path = bucketRelativePath?.startsWith("/")
|
|
? bucketRelativePath
|
|
: "/" + bucketRelativePath;
|
|
let resizeParams = "";
|
|
if (width || quality) {
|
|
resizeParams = "cdn-cgi/image/";
|
|
if (width) {
|
|
resizeParams += `width=${width},`;
|
|
}
|
|
if (quality) {
|
|
resizeParams += `quality=${quality},`;
|
|
}
|
|
resizeParams = resizeParams.slice(0, -1);
|
|
}
|
|
if (resizeParams) {
|
|
return `${cndBasePath}/${resizeParams}${path}`;
|
|
} else {
|
|
return `${cndBasePath}${path}`;
|
|
}
|
|
}
|
|
}
|
|
|
|
export { BucketConfig };
|