UNPKG

youzanyun-devtool-worker

Version:

138 lines (137 loc) 5.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const spring4js_nodejs_1 = require("spring4js-nodejs"); const cookie = require("cookie"); const cookie2Str_1 = tslib_1.__importDefault(require("../../utils/cookie2Str")); let ProxyService = class ProxyService { async start() { this.diyAppInfoCache = {}; this.lastUsedAppInfo = {}; } async processRequest(ctx, next) { const curContentType = ctx.headers["content-type"]; const isJsonHeader = curContentType && (curContentType.indexOf("json") > -1 || curContentType.indexOf("application/csp-report") > -1); ctx.isJsonHeader = isJsonHeader; const sid = await this.userService.getSid(); const diycookie = { sid }; const yzcookie = { sid, KDTSESSIONID: sid }; let { projectId } = ctx.query; let appInfo = {}; if (projectId) { appInfo = this.diyAppInfoCache[projectId]; if (!appInfo) { const { proName } = await this.projectService.getProjectById(projectId); let result = await this.applicationService.getAppDetail(proName); appInfo = result.appDetail || {}; this.diyAppInfoCache[projectId] = appInfo; this.lastUsedAppInfo = appInfo; } } else { appInfo = this.lastUsedAppInfo; } const { appId, appName, appType } = appInfo; diycookie["appid"] = appId; diycookie["env"] = "dev"; diycookie["app_env"] = "dev"; diycookie["app_name"] = appName; diycookie["apptype"] = appType; let originCookies = cookie.parse(ctx.headers.cookie || ""); Object.assign(originCookies, diycookie); ctx.headers.cookie = (0, cookie2Str_1.default)(originCookies); Object.keys(yzcookie).forEach((item) => { ctx.cookies.set(item, yzcookie[item], { domain: ".youzan.com", httpOnly: true, }); }); let isProcessed = false; isProcessed = await this.builtInAppActionService.processRequest(ctx, next); if (isProcessed) { return; } isProcessed = await this.actionLocalFileService.processRequest(ctx, next); if (isProcessed) return; isProcessed = await this.actionStatusService.processRequest(ctx, next); if (isProcessed) return; isProcessed = await this.actionFileRequestService.processRequest(ctx, next); if (isProcessed) return; isProcessed = await this.actionToolService.processRequest(ctx, next); if (isProcessed) return; isProcessed = await this.actionDesignPlatformService.processRequest(ctx, next); if (isProcessed) return; isProcessed = await this.actionDataSaveService.processRequest(ctx, next); if (isProcessed) return; isProcessed = await this.actionH5PreviewService.processRequest(ctx, next); if (isProcessed) return; isProcessed = await this.actionH5PreviewEditorService.processRequest(ctx, next); if (isProcessed) return; isProcessed = await this.actionH5EditorDiyService.processRequest(ctx, next); if (isProcessed) return; isProcessed = await this.actionBeautyPreviewService.processRequest(ctx, next); if (isProcessed) return; await this.actionBypassService.processRequest(ctx, next); } }; tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "actionLocalFileService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "actionBypassService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "actionStatusService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "actionToolService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "actionFileRequestService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "actionDesignPlatformService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "actionDataSaveService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "actionH5PreviewService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "actionH5PreviewEditorService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "actionH5EditorDiyService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "actionBeautyPreviewService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "userService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "projectService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "applicationService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ProxyService.prototype, "builtInAppActionService", void 0); ProxyService = tslib_1.__decorate([ (0, spring4js_nodejs_1.Service)() ], ProxyService); exports.default = ProxyService;