m
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
"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");
|
||||
class UploadVo {
|
||||
url;
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ description: '图片完整地址' }),
|
||||
__metadata("design:type", String)
|
||||
], UploadVo.prototype, "url", void 0);
|
||||
class CommonUploadController {
|
||||
image(file, request) {
|
||||
const host1 = request.headers['x-forwarded-host'] || request.headers.host;
|
||||
const host2 = request.get('host');
|
||||
const url = `${request.protocol}://${host1 || host2}/${file.path}`;
|
||||
return api_1.Api.success({
|
||||
url,
|
||||
});
|
||||
}
|
||||
video(file, request) {
|
||||
const host1 = request.headers['x-forwarded-host'] || request.headers.host;
|
||||
const host2 = request.get('host');
|
||||
const url = `${request.protocol}://${host1 || host2}/${file.path}`;
|
||||
return api_1.Api.success({
|
||||
url,
|
||||
});
|
||||
}
|
||||
}
|
||||
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 }),
|
||||
__param(0, (0, common_1.UploadedFile)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], 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 }),
|
||||
__param(0, (0, common_1.UploadedFile)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CommonUploadController.prototype, "video", null);
|
||||
//# sourceMappingURL=common_upload.controller.js.map
|
||||
Reference in New Issue
Block a user