@prezly/theme-kit-core
Version:
Data layer and utility library for developing Prezly themes with JavaScript
30 lines (29 loc) • 1.01 kB
JavaScript
import { ASSETS_SECONDARY_CDN_URL } from "./constants.mjs";
export function isEmpty(gallery) {
return gallery.images_number === 0 && gallery.videos_number === 0;
}
export function getCoverImage(gallery) {
var {
thumbnail_image,
images
} = gallery;
if (thumbnail_image) {
return JSON.parse(thumbnail_image);
}
if (images.length) {
return images[0].uploadcare_image;
}
return null;
}
/**
* This method constructs a URL to download all images in the Gallery as a single archive.
*
* @param uuid Uploadcare files group UUID
* @param title Filename for the saved archive. Usually it is the Gallery title.
* @returns URL to an archive containing all of the images in the Gallery.
*/
export function getArchiveDownloadUrl(uuid, title) {
// Uploadcare doesn't like slashes in filenames even in encoded form.
var filename = encodeURIComponent(title.replace(/\//g, '_'));
return "".concat(ASSETS_SECONDARY_CDN_URL, "/").concat(uuid, "/archive/zip/").concat(filename, ".zip");
}