57 lines
1.9 KiB
JavaScript
57 lines
1.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.getInfoByUrl = getInfoByUrl;
|
|
exports.uploadExtraFile = uploadExtraFile;
|
|
const tslib_1 = require("tslib");
|
|
const WechatSDK_1 = tslib_1.__importDefault(require("oak-external-sdk/lib/WechatSDK"));
|
|
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
const assert_1 = require("oak-domain/lib/utils/assert");
|
|
const lodash_1 = require("oak-domain/lib/utils/lodash");
|
|
const Projection_1 = require("../types/Projection");
|
|
// 请求链接获取标题,发布时间,图片等信息
|
|
async function getInfoByUrl(params) {
|
|
const { url } = params;
|
|
return await WechatSDK_1.default.analyzePublicArticle(url);
|
|
}
|
|
async function uploadExtraFile(params, // FormData表单提交
|
|
context) {
|
|
const { applicationId, file, extraFileId, } = params;
|
|
(0, assert_1.assert)(applicationId);
|
|
const filename = file.originalFilename;
|
|
const filetype = file.mimetype;
|
|
const fileLength = file.size;
|
|
const fileStream = fs_1.default.createReadStream(file.filepath);
|
|
const [application] = await context.select('application', {
|
|
data: (0, lodash_1.cloneDeep)(Projection_1.applicationProjection),
|
|
filter: {
|
|
id: applicationId,
|
|
},
|
|
}, {
|
|
dontCollect: true,
|
|
});
|
|
const { type, config } = application;
|
|
// 保存文件
|
|
if (extraFileId) {
|
|
const closeRootMode = context.openRootMode();
|
|
try {
|
|
await context.operate('extraFile', {
|
|
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
action: 'update',
|
|
data: {},
|
|
filter: {
|
|
id: extraFileId,
|
|
},
|
|
}, {});
|
|
closeRootMode();
|
|
}
|
|
catch (err) {
|
|
closeRootMode();
|
|
throw err;
|
|
}
|
|
}
|
|
return {
|
|
success: true,
|
|
};
|
|
}
|