routerAdd('POST', '/api/attachment/upload', function (e) {
    const guards = require(`${__hooks}/bai_api_pb_hooks/bai_api_shared/middlewares/requestGuards.js`)
    const documentService = require(`${__hooks}/bai_api_pb_hooks/bai_api_shared/services/documentService.js`)
    const logger = require(`${__hooks}/bai_api_pb_hooks/bai_api_shared/utils/logger.js`)
    const { success, fail } = require(`${__hooks}/bai_api_pb_hooks/bai_api_shared/utils/response.js`)

    try {
        const authState = guards.requireManagePlatformUser(e)
        const payload = guards.validateAttachmentUploadBody(e)
        const files = e.findUploadedFiles('attachments_link') || []
        const file = files.length ? files[0] : null
        const data = documentService.uploadAttachment(authState.openid, payload, file)

        return success(e, '上传附件成功', data)
    } catch (err) {
        const status = (err && err.statusCode) || (err && err.status) || 400
        logger.error('上传附件失败', {
            status: status,
            errMsg: (err && err.message) || '未知错误',
            data: (err && err.data) || {},
        })
        return fail(e, (err && err.message) || '操作失败', (err && err.data) || {}, status)
    }
}, $apis.bodyLimit(536870912))





