
lib.enonic.asset.assetUrl.ts Maven / Gradle / Ivy
import {isCacheBust} from './config';
import {getFingerprint} from './runMode';
// https://developer.enonic.com/docs/xp/stable/runtime/engines/asset-service
// /_/asset/<:build-id>/
// https://developer.enonic.com/docs/xp/stable/runtime/engines/http-service
// **/_/service//
export interface AssetUrlParams {
params?: object;
path?: string;
type?: 'server' | 'absolute';
}
interface AssetUrlBuilder {
setApplication(value: string): void;
setPath(value: string): void;
setType(value: string): void;
setParams(value: ScriptValue): void;
setFingerprint(value: string): void;
createUrl(): string;
}
export function assetUrl(params: AssetUrlParams): string {
const bean: AssetUrlBuilder = __.newBean('com.enonic.lib.asset.AssetUrlBuilder');
bean.setApplication(app.name);
bean.setPath(params?.path || '');
bean.setType(params?.type || 'server');
bean.setParams(__.toScriptValue(params?.params || {}));
if (isCacheBust()) {
const fingerprint = getFingerprint(app.name);
if (fingerprint) {
bean.setFingerprint(fingerprint);
}
}
return bean.createUrl();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy