youzanyun-devtool-worker
Version:
147 lines (146 loc) • 5.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const axios_1 = tslib_1.__importDefault(require("axios"));
const spring4js_nodejs_1 = require("spring4js-nodejs");
let ActionH5EditorDiyService = class ActionH5EditorDiyService {
constructor() {
this.proxyConfig = null;
}
async start() {
const useProxy = this.configService.isUseProxy();
const host = this.configService.getProxyHost();
const port = this.configService.getProxyPort();
if (useProxy) {
this.proxyConfig = {
host,
port,
protocol: "http:",
};
}
}
async processRequest(ctx, next) {
if (ctx.path === "/v2/api/business/ui/apps/interim-implemented-pages/update") {
const { workbenchId, projectId, uuid, content } = ctx.request.body;
this.h5ExtensionPreviewEditorService.updatePreviewComps(projectId, uuid, content);
this.contentWindowService.refreshContent(workbenchId);
ctx.body = true;
return true;
}
else if (ctx.path === "/v2/api/business/ui/apps/implemented-pages/update") {
const { projectId, content, pageName, uuid, contentDesc, } = ctx.request.body;
this.h5ExtensionImplService.saveLocalPageImpl({
projectId,
pageName,
uuid,
content,
contentDesc,
});
ctx.body = true;
return true;
}
else if (ctx.path === "/v2/api/business/ui/apps/implemented-pages") {
const { uuid, projectId, nodeCode, pageName } = ctx.query;
const previewComps = await this.getCachePreviewComps({
projectId,
implId: uuid,
});
let axiosRes = await this.getRawResponse(ctx);
ctx.body = axiosRes.data;
ctx.body.data.content = JSON.stringify(previewComps);
if (previewComps && previewComps.length && previewComps[0].script) {
ctx.body.data.contentDesc = previewComps[0].script.contentDesc;
}
return true;
}
else if (ctx.path === "/v2/api/business/ui/get/getFrontPageInfo") {
const { projectId, nodeCode, pageName } = ctx.query;
const re = await this.h5ExtensionService.getPageComponentList({
projectId,
nodeCode,
pageName,
incloudCommon: true,
});
let axiosRes = await this.getRawResponse(ctx);
if (re && re.localComps) {
const components = JSON.stringify(re.localComps);
const url = re.localPageFile;
if (axiosRes.data.data) {
axiosRes.data.data.components = components;
axiosRes.data.data.url = url;
}
else {
axiosRes.data.data = {
components,
url,
};
}
}
else {
delete axiosRes.data.data;
}
ctx.body = axiosRes.data;
return true;
}
}
async getRawResponse(ctx) {
let requestHeader = JSON.parse(JSON.stringify(ctx.headers));
requestHeader["accept-encoding"] = "gzip, deflate";
const axiosConfig = {
method: ctx.method,
url: ctx.href,
headers: requestHeader,
responseType: "text",
validateStatus: function (status) {
return true;
},
maxRedirects: 0,
};
if (this.proxyConfig) {
axiosConfig.proxy = this.proxyConfig;
}
let axiosRes = await axios_1.default.request(axiosConfig);
let header = JSON.parse(JSON.stringify(axiosRes.headers));
delete header["content-length"];
ctx.set(header);
return axiosRes;
}
async getCachePreviewComps(params) {
try {
const { projectId, implId } = params;
const result = await this.h5ExtensionPreviewEditorService.getPreviewComps(projectId, implId);
return result || [];
}
catch (err) {
return [];
}
}
async getLocalPageFile(params) {
try {
const result = await this.h5ExtensionService.getLocalPageFile(params);
return result || [];
}
catch (err) {
return [];
}
}
};
tslib_1.__decorate([
(0, spring4js_nodejs_1.Resource)()
], ActionH5EditorDiyService.prototype, "contentWindowService", void 0);
tslib_1.__decorate([
(0, spring4js_nodejs_1.Resource)()
], ActionH5EditorDiyService.prototype, "h5ExtensionPreviewEditorService", void 0);
tslib_1.__decorate([
(0, spring4js_nodejs_1.Resource)()
], ActionH5EditorDiyService.prototype, "h5ExtensionImplService", void 0);
tslib_1.__decorate([
(0, spring4js_nodejs_1.Resource)()
], ActionH5EditorDiyService.prototype, "h5ExtensionService", void 0);
tslib_1.__decorate([
(0, spring4js_nodejs_1.Resource)()
], ActionH5EditorDiyService.prototype, "configService", void 0);
ActionH5EditorDiyService = tslib_1.__decorate([
(0, spring4js_nodejs_1.Service)()
], ActionH5EditorDiyService);
exports.default = ActionH5EditorDiyService;