Files
energy_dist/dist/app/common/controller/common_upload.controller.js
T
2026-04-21 23:58:03 +08:00

124 lines
4.5 KiB
JavaScript

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommonUploadController = void 0;
const openapi = require("@nestjs/swagger");
const common_1 = require("@nestjs/common");
const platform_express_1 = require("@nestjs/platform-express");
const api_1 = require("../api");
const swagger_1 = require("@nestjs/swagger");
const cos_help_1 = require("../util/cos_help");
class UploadVo {
url;
}
__decorate([
(0, swagger_1.ApiProperty)({ description: '图片完整地址' }),
__metadata("design:type", String)
], UploadVo.prototype, "url", void 0);
class CommonUploadController {
async image(file) {
try {
const result = await cos_help_1.COSHelp.upload(file);
return api_1.Api.success({
url: 'https://' + result.Location,
});
}
catch {
return api_1.Api.error('uoload error');
}
}
async video(file) {
try {
const result = await cos_help_1.COSHelp.upload(file);
return api_1.Api.success({
url: 'https://' + result.Location,
});
}
catch {
return api_1.Api.error('uoload error');
}
}
}
exports.CommonUploadController = CommonUploadController;
__decorate([
(0, common_1.Post)('image'),
(0, swagger_1.ApiOperation)({ summary: '上传图片,最大20M' }),
api_1.Api.ApiResponse({
model: UploadVo,
}),
(0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)('image', {
limits: { fileSize: 1024 * 1024 * 20 },
fileFilter(req, file, callback) {
if (!file.mimetype.includes('image')) {
callback(new common_1.HttpException('只能上传图片', 400), false);
}
else {
callback(null, true);
}
},
})),
(0, swagger_1.ApiConsumes)('multipart/form-data'),
(0, swagger_1.ApiBody)({
schema: {
type: 'object',
properties: {
image: {
type: 'string',
format: 'binary',
},
},
},
}),
openapi.ApiResponse({ status: 201, type: Object }),
__param(0, (0, common_1.UploadedFile)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], CommonUploadController.prototype, "image", null);
__decorate([
(0, common_1.Post)('video'),
(0, swagger_1.ApiOperation)({ summary: '上传视频,最大200M' }),
api_1.Api.ApiResponse({
model: UploadVo,
}),
(0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)('video', {
limits: { fileSize: 1024 * 1024 * 200 },
fileFilter(req, file, callback) {
if (!file.mimetype.includes('video')) {
callback(new common_1.HttpException('只能上传视频', 400), false);
}
else {
callback(null, true);
}
},
})),
(0, swagger_1.ApiConsumes)('multipart/form-data'),
(0, swagger_1.ApiBody)({
schema: {
type: 'object',
properties: {
video: {
type: 'string',
format: 'binary',
},
},
},
}),
openapi.ApiResponse({ status: 201, type: Object }),
__param(0, (0, common_1.UploadedFile)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], CommonUploadController.prototype, "video", null);
//# sourceMappingURL=common_upload.controller.js.map