n8n-nodes-placid
Version:
n8n node to interact with Placid API for creative generation
104 lines • 4.37 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;
const config_1 = require("../utils/config");
async function getTemplates(filter, paginationToken) {
const returnData = [];
let url = paginationToken || config_1.PlacidConfig.getRestUrl(config_1.PlacidConfig.ENDPOINTS.TEMPLATES);
if (!paginationToken && filter) {
url += `?search=${encodeURIComponent(filter)}`;
}
const options = {
method: 'GET',
url: url,
headers: {
'Accept': config_1.PlacidConfig.HTTP.HEADERS.ACCEPT,
'Content-Type': config_1.PlacidConfig.HTTP.HEADERS.CONTENT_TYPE,
'x-placid-integration': config_1.PlacidConfig.HTTP.HEADERS.PLACID_INTEGRATION,
},
};
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: `${config_1.PlacidConfig.getRestUrl(config_1.PlacidConfig.ENDPOINTS.TEMPLATES)}/${templateId}`,
headers: {
'Accept': config_1.PlacidConfig.HTTP.HEADERS.ACCEPT,
'Content-Type': config_1.PlacidConfig.HTTP.HEADERS.CONTENT_TYPE,
'x-placid-integration': config_1.PlacidConfig.HTTP.HEADERS.PLACID_INTEGRATION,
},
};
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';
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