intlayer-editor
Version:
Integrate the Intlayer visual editor into your Intlayer projects, enabling CMS-like content management with multilingual support.
144 lines • 5.67 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var dictionary_controller_exports = {};
__export(dictionary_controller_exports, {
getDictionaries: () => getDictionaries,
writeContentDeclaration: () => writeContentDeclaration
});
module.exports = __toCommonJS(dictionary_controller_exports);
var import_chokidar = require("@intlayer/chokidar");
var import_config = require("@intlayer/config");
var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"), 1);
var import_responseData = require('./../utils/responseData.cjs');
var import_express_intlayer = require("express-intlayer");
const getDictionaries = async (_req, res, _next) => {
try {
const formattedResponse = (0, import_responseData.formatResponse)({
data: import_dictionaries_entry.default
});
res.json(formattedResponse);
return;
} catch (err) {
const errorMessage = err ?? {
message: "Internal Server Error",
status: 500
};
const formattedErrorResponse = (0, import_responseData.formatResponse)({
error: {
message: errorMessage.message ?? "Internal Server Error",
code: "INTERNAL_SERVER_ERROR",
title: "Internal Server Error"
},
status: errorMessage.status ?? 500
});
res.json(formattedErrorResponse);
return;
}
};
const writeContentDeclaration = async (req, res, _next) => {
try {
const dictionaryData = req.body.dictionary;
const config = (0, import_config.getConfiguration)();
const result = await (0, import_chokidar.writeContentDeclaration)(dictionaryData, config);
let description = "";
switch (result.status) {
case "updated": {
description = (0, import_express_intlayer.t)({
en: "Content declaration updated successfully",
fr: "D\xE9claration de contenu mise \xE0 jour avec succ\xE8s",
es: "Declaraci\xF3n de contenido actualizada con \xE9xito"
});
break;
}
case "reimported in JSON": {
description = (0, import_express_intlayer.t)({
en: "Content declaration reimported in JSON successfully",
fr: "D\xE9claration de contenu r\xE9import\xE9e en JSON avec succ\xE8s",
es: "Declaraci\xF3n de contenido reimportada en JSON con \xE9xito"
});
break;
}
case "reimported in new location": {
description = (0, import_express_intlayer.t)({
en: "Content declaration reimported in new location successfully",
fr: "D\xE9claration de contenu r\xE9import\xE9e dans un nouveau emplacement avec succ\xE8s",
es: "Declaraci\xF3n de contenido reimportada en un nuevo lugar con \xE9xito"
});
break;
}
default: {
description = (0, import_express_intlayer.t)({
en: "Content declaration written successfully",
fr: "D\xE9claration de contenu \xE9crite avec succ\xE8s",
es: "Declaraci\xF3n de contenido escrita con \xE9xito"
});
break;
}
}
const formattedResponse = (0, import_responseData.formatResponse)(
{
data: result,
message: (0, import_express_intlayer.t)({
en: "Content declaration written",
fr: "D\xE9claration de contenu \xE9crite",
es: "Declaraci\xF3n de contenido escrita"
}),
description: (0, import_express_intlayer.t)({
en: "Content declaration written successfully",
fr: "D\xE9claration de contenu \xE9crite avec succ\xE8s",
es: "Declaraci\xF3n de contenido escrita con \xE9xito"
})
}
);
res.json(formattedResponse);
return;
} catch (err) {
const errorMessage = err ?? {
message: "Internal Server Error",
status: 500
};
console.error(errorMessage);
const formattedErrorResponse = (0, import_responseData.formatResponse)({
error: {
message: errorMessage.message ?? "Internal Server Error",
code: "INTERNAL_SERVER_ERROR",
title: "Internal Server Error"
},
status: errorMessage.status ?? 500
});
res.json(formattedErrorResponse);
return;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getDictionaries,
writeContentDeclaration
});
//# sourceMappingURL=dictionary.controller.cjs.map