forked from rajun/ar-test
feat: add asset media and brand helpers
This commit is contained in:
parent
04751ff97e
commit
fc875ec6ca
50
app/services/asset-media.ts
Normal file
50
app/services/asset-media.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { readArPage } from '~/schemas/projects/ar-page';
|
||||
import { pb } from '~/services/pocketbase';
|
||||
import type { ArAsset } from '~/types/asset';
|
||||
import type { ArPageLayout, BrandIdentity, ButtonStyle, Project } from '~/types/project';
|
||||
import type { AppSettings } from '~/types/settings';
|
||||
|
||||
// An uploaded file always wins over an external URL
|
||||
function resolve(asset: ArAsset, file: string, url: string): string | undefined {
|
||||
if (file) return pb.files.getURL(asset, file);
|
||||
return url || undefined;
|
||||
}
|
||||
|
||||
export const getGlbUrl = (asset: ArAsset) => resolve(asset, asset.glb_file, asset.glb_url);
|
||||
|
||||
export const getUsdzUrl = (asset: ArAsset) => resolve(asset, asset.usdz_file, asset.usdz_url);
|
||||
|
||||
export function getModelFileName(asset: ArAsset): string {
|
||||
if (asset.glb_file) return asset.glb_file;
|
||||
return asset.glb_url.split('/').pop() || asset.glb_url;
|
||||
}
|
||||
|
||||
export const getProjectLogoUrl = (project: Project, fileName: string) => pb.files.getURL(project, fileName);
|
||||
|
||||
export function toBrand(project: Project): BrandIdentity {
|
||||
return {
|
||||
name: project.name,
|
||||
logoUrl: project.logo ? getProjectLogoUrl(project, project.logo) : undefined,
|
||||
logoBg: project.logo_bg || 'light',
|
||||
logoBgColor: project.logo_bg_color || undefined,
|
||||
};
|
||||
}
|
||||
|
||||
// The client logo goes on the QR only when the asset asks for it and the project has a logo
|
||||
export const isBrandedQr = (asset: ArAsset) => asset.branded_qr && !!asset.expand?.project?.logo;
|
||||
|
||||
// The project's button customisation, applied only while the "Per-project button style" setting is on
|
||||
export function getButtonStyle(project: Project | undefined, settings: AppSettings): ButtonStyle {
|
||||
if (!settings.brand_button || !project) return {};
|
||||
const arPage = readArPage(project.ar_page);
|
||||
return {
|
||||
color: project.brand_color || undefined,
|
||||
textColor: project.button_text_color || undefined,
|
||||
label: project.button_label || undefined,
|
||||
size: arPage.buttonSize,
|
||||
custom: arPage.buttonCustom,
|
||||
};
|
||||
}
|
||||
|
||||
// What the project's AR page shows around the model; unassigned assets get thob's defaults
|
||||
export const getArPageLayout = (project: Project | undefined): ArPageLayout => readArPage(project?.ar_page);
|
||||
Loading…
x
Reference in New Issue
Block a user