You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
896 B
30 lines
896 B
import {
|
|
getBlockData,
|
|
getBlockName,
|
|
getBlockVariations,
|
|
getListOfDesignPreviewFiles,
|
|
} from "../helpers.js";
|
|
import path from "path";
|
|
import fs from "fs/promises";
|
|
|
|
export default async function (req, res, next) {
|
|
let variationName = req.query.name ? req.query.name : 'default';
|
|
const block = getBlockName(req.query.block);
|
|
|
|
const blockDir = path.join('blocks', '@' + block.project, block.name);
|
|
const dataFiles = await getBlockVariations(blockDir);
|
|
const data = await getBlockData(variationName, {projectPath: blockDir});
|
|
|
|
let designPreviewFiles = [];
|
|
try {
|
|
designPreviewFiles = getListOfDesignPreviewFiles(variationName, await fs.readdir(path.join(blockDir, 'design', 'preview')), block);
|
|
} catch (err) {
|
|
console.log('Preview Design doesn\'t exist');
|
|
}
|
|
|
|
return res.json({
|
|
dataOptions: dataFiles,
|
|
designPreview: designPreviewFiles,
|
|
data,
|
|
});
|
|
}
|
|
|