Files
artcraft/frontend/editor3d/app/api/BucketConfig.ts
T
Brandon Thomas b31badc6d1 Editor3D - this directory is a fork of "studio gen 2" by Tanish.
We'll be using this for our image generation roadmap:

https://docs.google.com/document/d/1O9YI_iLwXkl2wAJJ23dFp3eHR-JzhlRHCBPD8psG-1E/edit

The original Studio Gen 2 is in the `frontend/studio-gen-2` directory.

The original Studio Gen 1 is in the `frontend/studio-gen-1` directory
2025-03-31 13:28:59 -04:00

61 lines
1.7 KiB
TypeScript

import environmentVariables from "~/Classes/EnvironmentVariables";
import { GetCdnOrigin } from "./GetCdnOrigin";
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
// TODO pipeline works make more robust....
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}`;
const media_api_base_url = GetCdnOrigin();
return `${media_api_base_url}/${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 };