45 lines
883 B
JavaScript
45 lines
883 B
JavaScript
import { pageContext } from '../renderer/usePageContext.js';
|
|
|
|
function getBasePath(media, options) {
|
|
if (pageContext.restriction) {
|
|
return pageContext.env.media.assetPath;
|
|
}
|
|
|
|
if (media.isS3) {
|
|
return options.s3Path;
|
|
}
|
|
|
|
if (options?.local) {
|
|
return options.assetPath;
|
|
}
|
|
|
|
return options.mediaPath;
|
|
}
|
|
|
|
function getFilename(media, type, options) {
|
|
if (pageContext.restriction && type && !options?.original) {
|
|
return media.sfw?.[type];
|
|
}
|
|
|
|
if (pageContext.restriction) {
|
|
return media.sfw?.path;
|
|
}
|
|
|
|
if (type && !options?.original) {
|
|
return media[type];
|
|
}
|
|
|
|
return media.path;
|
|
}
|
|
|
|
export default function getPath(media, type, options) {
|
|
if (!media) {
|
|
return null;
|
|
}
|
|
|
|
const path = getBasePath(media, { ...pageContext.env.media, ...options });
|
|
const filename = getFilename(media, type, { ...pageContext.env.media, ...options });
|
|
|
|
return `${path}/${filename}`;
|
|
}
|