n8n-nodes-placid
Version:
n8n node to interact with Placid API for creative generation
103 lines • 4.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTemplates = getTemplates;
exports.getTemplateLayers = getTemplateLayers;
exports.getTextLayers = getTextLayers;
exports.getPictureLayers = getPictureLayers;
exports.getPdfPageTextLayers = getPdfPageTextLayers;
exports.getPdfPagePictureLayers = getPdfPagePictureLayers;
async function getTemplates(filter, paginationToken) {
const returnData = [];
let url = paginationToken || 'https://api.placid.app/api/rest/templates';
if (!paginationToken && filter) {
url += `?search=${encodeURIComponent(filter)}`;
}
const options = {
method: 'GET',
url: url,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
};
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'placidApi', options);
if (response.data && Array.isArray(response.data)) {
for (const template of response.data) {
if (filter && !template.title.toLowerCase().includes(filter.toLowerCase())) {
continue;
}
returnData.push({
name: template.title,
value: template.uuid,
description: template.tags ? template.tags.join(', ') : '',
});
}
}
const result = {
results: returnData,
};
if (response.links && response.links.next) {
result.paginationToken = response.links.next;
}
return result;
}
async function getLayersForTemplate(loadOptionsFunctions, templateId) {
if (!templateId) {
return [{ name: 'Please Select a Template First', value: '' }];
}
const options = {
method: 'GET',
url: `https://api.placid.app/api/rest/templates/${templateId}`,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
};
const response = await loadOptionsFunctions.helpers.httpRequestWithAuthentication.call(loadOptionsFunctions, 'placidApi', options);
const layers = [];
if (response.layers && Array.isArray(response.layers)) {
for (const layer of response.layers) {
const layerType = layer.type || 'unknown';
if (layerType === 'text' || layerType === 'picture') {
const displayName = `${layer.name} (${layerType})`;
layers.push({
name: displayName,
value: `${layer.name}|${layerType}`,
description: `Layer type: ${layerType}`,
});
}
}
}
return layers;
}
async function getTemplateLayers() {
let templateId;
try {
const templateIdParam = this.getNodeParameter('template_id', 0);
templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam === null || templateIdParam === void 0 ? void 0 : templateIdParam.value;
}
catch (error) {
}
return await getLayersForTemplate(this, templateId || '');
}
async function getTextLayers() {
const allLayers = await getTemplateLayers.call(this);
return allLayers.filter(layer => String(layer.value).includes('|text'));
}
async function getPictureLayers() {
const allLayers = await getTemplateLayers.call(this);
return allLayers.filter(layer => String(layer.value).includes('|picture'));
}
async function getPdfPageTextLayers() {
return [
{ name: 'Enter Layer Name Manually', value: 'manual', description: 'Type the layer name directly' },
{ name: 'Use Advanced Mode for Complex Configurations', value: '', description: 'Switch to Advanced mode for full control' },
];
}
async function getPdfPagePictureLayers() {
return [
{ name: 'Enter Layer Name Manually', value: 'manual', description: 'Type the layer name directly' },
{ name: 'Use Advanced Mode for Complex Configurations', value: '', description: 'Switch to Advanced mode for full control' },
];
}
//# sourceMappingURL=index.js.map