UNPKG

infinity-forge

Version:
156 lines • 13.4 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPost = getPost; var ui_1 = require("../../../../../../../ui/index.js"); function getPostV1(_a) { return __awaiter(this, arguments, void 0, function (_b) { var page, error_1; var url = _b.url, apiUrl = _b.apiUrl, ctx = _b.ctx; return __generator(this, function (_c) { switch (_c.label) { case 0: _c.trys.push([0, 2, , 3]); return [4 /*yield*/, (0, ui_1.api)({ url: "blog/detail/".concat(url), serverContext: ctx, method: 'get' }, apiUrl)]; case 1: page = _c.sent(); return [2 /*return*/, page]; case 2: error_1 = _c.sent(); return [2 /*return*/, null]; case 3: return [2 /*return*/]; } }); }); } function getPostV2(_a) { return __awaiter(this, arguments, void 0, function (_b) { var item, response, locale_1, jsonContentData, i18Top, i18Inside, mainI18n, error_2; var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x; var url = _b.url, apiUrl = _b.apiUrl, ctx = _b.ctx, entityKey = _b.entityKey; return __generator(this, function (_y) { switch (_y.label) { case 0: _y.trys.push([0, 3, , 4]); return [4 /*yield*/, (0, ui_1.api)({ url: "admin/contents/blog/url/".concat(url), serverContext: ctx, debugMode: true, method: 'get' }, apiUrl)]; case 1: item = (_y.sent()).item; return [4 /*yield*/, (0, ui_1.api)({ url: 'admin/contents/blog/paginated', serverContext: ctx, method: 'get', body: { page: 1, EntityKey: entityKey }, }, apiUrl)]; case 2: response = _y.sent(); locale_1 = ((_c = ctx === null || ctx === void 0 ? void 0 : ctx.query) === null || _c === void 0 ? void 0 : _c.locale) || (ctx === null || ctx === void 0 ? void 0 : ctx.locale) || 'pt-BR'; jsonContentData = (0, ui_1.parseJSON)(item.jsonContent); i18Top = ((_d = item === null || item === void 0 ? void 0 : item.i18n) === null || _d === void 0 ? void 0 : _d[locale_1]) || ((_e = item === null || item === void 0 ? void 0 : item.i18n) === null || _e === void 0 ? void 0 : _e['pt-BR']) || null; i18Inside = ((_f = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.i18n) === null || _f === void 0 ? void 0 : _f[locale_1]) || ((_g = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.i18n) === null || _g === void 0 ? void 0 : _g['pt-BR']) || null; mainI18n = i18Top || i18Inside || {}; return [2 /*return*/, { page: { id: item === null || item === void 0 ? void 0 : item.id, ordem: (_h = item === null || item === void 0 ? void 0 : item.ordem) !== null && _h !== void 0 ? _h : null, titulo: (_j = ((mainI18n === null || mainI18n === void 0 ? void 0 : mainI18n.titulo) || (item === null || item === void 0 ? void 0 : item.titulo))) !== null && _j !== void 0 ? _j : '', thumbnail: (_m = (_l = (_k = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.thumbnail) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.url) !== null && _m !== void 0 ? _m : '', imagem: (_s = (((_p = (_o = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.images) === null || _o === void 0 ? void 0 : _o[0]) === null || _p === void 0 ? void 0 : _p.url) || ((_r = (_q = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.thumbnail) === null || _q === void 0 ? void 0 : _q[0]) === null || _r === void 0 ? void 0 : _r.url))) !== null && _s !== void 0 ? _s : '', url: (_t = ((mainI18n === null || mainI18n === void 0 ? void 0 : mainI18n.url) || (item === null || item === void 0 ? void 0 : item.url))) !== null && _t !== void 0 ? _t : '', tags: (_u = ((mainI18n === null || mainI18n === void 0 ? void 0 : mainI18n.tags) || (item === null || item === void 0 ? void 0 : item.tags))) !== null && _u !== void 0 ? _u : '', destaque: true, descricao: (_v = ((mainI18n === null || mainI18n === void 0 ? void 0 : mainI18n.descricao) || (item === null || item === void 0 ? void 0 : item.descricao))) !== null && _v !== void 0 ? _v : '', dataCriacao: item === null || item === void 0 ? void 0 : item.dataCriacao, imagens: (_w = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.images) !== null && _w !== void 0 ? _w : [], fields: { CategoriaId: item === null || item === void 0 ? void 0 : item.categoriaId, }, }, categorias: [], posts: (_x = response === null || response === void 0 ? void 0 : response.items) === null || _x === void 0 ? void 0 : _x.map(function (item) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w; var jsonContentData = (0, ui_1.parseJSON)(item.jsonContent); var i18Top = ((_a = item === null || item === void 0 ? void 0 : item.i18n) === null || _a === void 0 ? void 0 : _a[locale_1]) || ((_b = item === null || item === void 0 ? void 0 : item.i18n) === null || _b === void 0 ? void 0 : _b['pt-BR']) || null; var i18Inside = ((_c = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.i18n) === null || _c === void 0 ? void 0 : _c[locale_1]) || ((_d = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.i18n) === null || _d === void 0 ? void 0 : _d['pt-BR']) || null; var i18 = i18Top || i18Inside || {}; var data = { pageTitle: (_f = (_e = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.metaTitle) !== null && _e !== void 0 ? _e : ((i18 === null || i18 === void 0 ? void 0 : i18.titulo) || (item === null || item === void 0 ? void 0 : item.titulo))) !== null && _f !== void 0 ? _f : '', metaDescription: (_g = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.metaDescription) !== null && _g !== void 0 ? _g : ((i18 === null || i18 === void 0 ? void 0 : i18.descricao) || ''), id: item === null || item === void 0 ? void 0 : item.id, ordem: (_h = item === null || item === void 0 ? void 0 : item.ordem) !== null && _h !== void 0 ? _h : null, titulo: (_j = ((i18 === null || i18 === void 0 ? void 0 : i18.titulo) || (item === null || item === void 0 ? void 0 : item.titulo))) !== null && _j !== void 0 ? _j : '', thumbnail: (_m = (_l = (_k = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.thumbnail) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.url) !== null && _m !== void 0 ? _m : '', imagem: (_s = (((_p = (_o = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.images) === null || _o === void 0 ? void 0 : _o[0]) === null || _p === void 0 ? void 0 : _p.url) || ((_r = (_q = jsonContentData === null || jsonContentData === void 0 ? void 0 : jsonContentData.thumbnail) === null || _q === void 0 ? void 0 : _q[0]) === null || _r === void 0 ? void 0 : _r.url))) !== null && _s !== void 0 ? _s : '', url: (_t = ((i18 === null || i18 === void 0 ? void 0 : i18.url) || (item === null || item === void 0 ? void 0 : item.url))) !== null && _t !== void 0 ? _t : '', tags: (_u = ((i18 === null || i18 === void 0 ? void 0 : i18.tags) || (item === null || item === void 0 ? void 0 : item.tags))) !== null && _u !== void 0 ? _u : '', destaque: (_v = item === null || item === void 0 ? void 0 : item.destaque) !== null && _v !== void 0 ? _v : false, dataCriacao: item === null || item === void 0 ? void 0 : item.dataCriacao, descricao: (_w = ((i18 === null || i18 === void 0 ? void 0 : i18.descricao) || (item === null || item === void 0 ? void 0 : item.descricao))) !== null && _w !== void 0 ? _w : '', fields: { CategoriaId: item === null || item === void 0 ? void 0 : item.categoriaId, }, }; return data; }), }]; case 3: error_2 = _y.sent(); return [2 /*return*/, null]; case 4: return [2 /*return*/]; } }); }); } function getPost(_a) { return __awaiter(this, arguments, void 0, function (_b) { var url; var _c; var ctx = _b.ctx, apiUrl = _b.apiUrl, entityKey = _b.entityKey; return __generator(this, function (_d) { switch (_d.label) { case 0: url = (_c = ctx === null || ctx === void 0 ? void 0 : ctx.query) === null || _c === void 0 ? void 0 : _c.slug; if (!process.env.tenant) return [3 /*break*/, 2]; return [4 /*yield*/, getPostV2({ url: url, apiUrl: apiUrl, ctx: ctx, entityKey: entityKey })]; case 1: return [2 /*return*/, _d.sent()]; case 2: return [4 /*yield*/, getPostV1({ url: url, apiUrl: apiUrl, ctx: ctx })]; case 3: return [2 /*return*/, _d.sent()]; } }); }); } //# sourceMappingURL=index.js.map