"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addBulkMaterials = void 0;
var tslib_1 = require("tslib");
var _ = require("lodash");
exports.addBulkMaterials = {
    rest: {
        method: 'POST',
        fullPath: '/api/pepsico-content/approve/material/add'
    },
    handler: function (ctx) {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var logger, files, fileNameHasCopyright, files_1, files_1_1, item, allTrue;
            var e_1, _a;
            return tslib_1.__generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        ctx.getObject = this.getObject;
                        return [4, this.getLogger()];
                    case 1:
                        logger = _b.sent();
                        ctx.logger = logger;
                        return [4, ctx.getObject("cfs_files_filerecord").find({
                                filters: ['_id', '=', ctx.params.files]
                            })];
                    case 2:
                        files = _b.sent();
                        fileNameHasCopyright = false;
                        try {
                            for (files_1 = tslib_1.__values(files), files_1_1 = files_1.next(); !files_1_1.done; files_1_1 = files_1.next()) {
                                item = files_1_1.value;
                                if (_.includes(item.original.name, '版权')) {
                                    return [2, {
                                            status: '500',
                                            msg: '上传素材中包含“版权”文件，请删除版权文件后再次提交。',
                                            data: {}
                                        }];
                                }
                            }
                        }
                        catch (e_1_1) { e_1 = { error: e_1_1 }; }
                        finally {
                            try {
                                if (files_1_1 && !files_1_1.done && (_a = files_1.return)) _a.call(files_1);
                            }
                            finally { if (e_1) throw e_1.error; }
                        }
                        return [4, this.addBulkMaterials(ctx, ctx.params.approvalId, ctx.params.files)];
                    case 3:
                        _b.sent();
                        if (!false) return [3, 5];
                        return [4, this.uploadBulkDocToOneDrive(ctx, ctx.params.approvalId)];
                    case 4:
                        allTrue = _b.sent();
                        if (!allTrue) {
                            return [2, {
                                    status: '500',
                                    msg: '素材上传失败, 请稍后重试',
                                    data: {}
                                }];
                        }
                        _b.label = 5;
                    case 5: return [2, {}];
                }
            });
        });
    }
};
//# sourceMappingURL=addBulkMaterials.js.map