|
| 1 | +import { Static, Type } from "@sinclair/typebox"; |
| 2 | +import { CloudStorage } from "../../../../constants/Config"; |
| 3 | +import { FastifyRequestTypebox, Response } from "../../../../types/Server"; |
| 4 | +import { successJSON } from "../../internal/utils/response-json"; |
| 5 | +import { CloudStorageUploadService } from "../../../services/cloud-storage/upload"; |
| 6 | +import { uploadStartReturnSchema } from "../../../services/cloud-storage/upload.schema"; |
| 7 | +import { useOnceService } from "../../../service-locator"; |
| 8 | + |
| 9 | +export const tempPhotoUploadStartSchema = { |
| 10 | + body: Type.Object( |
| 11 | + { |
| 12 | + fileName: Type.String({ |
| 13 | + minLength: 3, |
| 14 | + maxLength: 128, |
| 15 | + format: "temp-photo-suffix", |
| 16 | + }), |
| 17 | + fileSize: Type.Integer({ |
| 18 | + maximum: CloudStorage.tempPhoto.singleFileSize, |
| 19 | + minimum: 1, |
| 20 | + }), |
| 21 | + }, |
| 22 | + { |
| 23 | + additionalProperties: false, |
| 24 | + }, |
| 25 | + ), |
| 26 | +}; |
| 27 | + |
| 28 | +export const tempPhotoUploadStart = async ( |
| 29 | + req: FastifyRequestTypebox<typeof tempPhotoUploadStartSchema>, |
| 30 | +): Promise<Response<Static<typeof uploadStartReturnSchema>>> => { |
| 31 | + const complianceText = useOnceService("complianceText", req.ids); |
| 32 | + await complianceText.assertTextNormal(req.body.fileName); |
| 33 | + |
| 34 | + const cloudStorageUploadSVC = new CloudStorageUploadService( |
| 35 | + req.ids, |
| 36 | + req.DBTransaction, |
| 37 | + req.userUUID, |
| 38 | + ); |
| 39 | + |
| 40 | + const result = await cloudStorageUploadSVC.tempPhotoStart({ |
| 41 | + fileName: req.body.fileName, |
| 42 | + fileSize: req.body.fileSize, |
| 43 | + }); |
| 44 | + |
| 45 | + return successJSON(result); |
| 46 | +}; |
0 commit comments