95 lines
3.7 KiB
JavaScript
95 lines
3.7 KiB
JavaScript
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); }
|
|
};
|
|
import { Body, Controller, Delete, Get, HttpCode, Module, Param, Patch, Post, Query, UploadedFile, UseInterceptors, } from "@nestjs/common";
|
|
import { FileInterceptor } from "@nestjs/platform-express";
|
|
import { mediaUpdateSchema } from "@imen/shared";
|
|
import { z } from "zod";
|
|
import { AdminAuth, CurrentUser, Roles } from "../common/auth.js";
|
|
import { IdPipe, ZodPipe } from "../common/zod.pipe.js";
|
|
import { MediaService } from "./media.service.js";
|
|
const listQuery = z.object({
|
|
page: z.coerce.number().int().min(1).default(1),
|
|
pageSize: z.coerce.number().int().min(1).max(100).default(40),
|
|
q: z.string().trim().max(100).optional(),
|
|
});
|
|
let MediaController = class MediaController {
|
|
media;
|
|
constructor(media) {
|
|
this.media = media;
|
|
}
|
|
list(q) {
|
|
return this.media.list(q.page, q.pageSize, q.q);
|
|
}
|
|
upload(file, alt, user) {
|
|
return this.media.upload(file, typeof alt === "string" ? alt : "", user.id);
|
|
}
|
|
update(id, body, user) {
|
|
return this.media.updateAlt(id, body.alt, user.id);
|
|
}
|
|
async remove(id, user) {
|
|
await this.media.remove(id, user.id);
|
|
}
|
|
};
|
|
__decorate([
|
|
Get(),
|
|
__param(0, Query(new ZodPipe(listQuery))),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object]),
|
|
__metadata("design:returntype", void 0)
|
|
], MediaController.prototype, "list", null);
|
|
__decorate([
|
|
Post(),
|
|
UseInterceptors(FileInterceptor("file", { limits: { fileSize: 15 * 1024 * 1024 } })),
|
|
__param(0, UploadedFile()),
|
|
__param(1, Body("alt")),
|
|
__param(2, CurrentUser()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
__metadata("design:returntype", void 0)
|
|
], MediaController.prototype, "upload", null);
|
|
__decorate([
|
|
Patch(":id"),
|
|
__param(0, Param("id", IdPipe)),
|
|
__param(1, Body(new ZodPipe(mediaUpdateSchema))),
|
|
__param(2, CurrentUser()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Number, Object, Object]),
|
|
__metadata("design:returntype", void 0)
|
|
], MediaController.prototype, "update", null);
|
|
__decorate([
|
|
Roles("ADMIN"),
|
|
Delete(":id"),
|
|
HttpCode(204),
|
|
__param(0, Param("id", IdPipe)),
|
|
__param(1, CurrentUser()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Number, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], MediaController.prototype, "remove", null);
|
|
MediaController = __decorate([
|
|
AdminAuth(),
|
|
Controller("admin/media"),
|
|
__metadata("design:paramtypes", [MediaService])
|
|
], MediaController);
|
|
export { MediaController };
|
|
let MediaModule = class MediaModule {
|
|
};
|
|
MediaModule = __decorate([
|
|
Module({
|
|
controllers: [MediaController],
|
|
providers: [MediaService],
|
|
exports: [MediaService],
|
|
})
|
|
], MediaModule);
|
|
export { MediaModule };
|
|
//# sourceMappingURL=media.controller.js.map
|