sb-mig
Version:
CLI to rule the world. (and handle stuff related to Storyblok CMS)
26 lines (25 loc) • 803 B
JavaScript
export async function getAllAssets(client, args) {
const { spaceId, search } = args;
return client.sbApi
.get(`spaces/${spaceId}/assets/`, {
// @ts-ignore storyblok-js-client mismatch: documentation uses `search`
search: search ?? "",
per_page: 100,
})
.then(({ data }) => data);
}
export async function getAssetById(client, args) {
const { spaceId, assetId } = args;
return client.sbApi
.get(`spaces/${spaceId}/assets/${assetId}`)
.then(({ data }) => data);
}
export async function getAssetByName(client, args) {
const result = await getAllAssets(client, {
spaceId: args.spaceId,
search: args.fileName,
});
if (result?.assets?.length === 1)
return result.assets[0];
return undefined;
}