feat: only get url if object exists
This commit is contained in:
parent
68af0eb821
commit
374644a691
1 changed files with 10 additions and 6 deletions
|
|
@ -15,7 +15,7 @@ import {
|
|||
import { Prisma, Status } from "@prisma/client";
|
||||
|
||||
import prisma from "../../db";
|
||||
import minio from "../../services/minio";
|
||||
import minio, { presignedGetObjectIfExist } from "../../services/minio";
|
||||
import { RequestWithUser } from "../../interfaces/user";
|
||||
import HttpError from "../../interfaces/http-error";
|
||||
import HttpStatus from "../../interfaces/http-status";
|
||||
|
|
@ -83,7 +83,11 @@ export class ServiceController extends Controller {
|
|||
result: await Promise.all(
|
||||
result.map(async (v) => ({
|
||||
...v,
|
||||
imageUrl: await minio.presignedGetObject(MINIO_BUCKET, imageLocation(v.id), 12 * 60 * 60),
|
||||
imageUrl: await presignedGetObjectIfExist(
|
||||
MINIO_BUCKET,
|
||||
imageLocation(v.id),
|
||||
12 * 60 * 60,
|
||||
),
|
||||
})),
|
||||
),
|
||||
page,
|
||||
|
|
@ -119,7 +123,7 @@ export class ServiceController extends Controller {
|
|||
throw new HttpError(HttpStatus.NOT_FOUND, "Service cannot be found.", "data_not_found");
|
||||
|
||||
return Object.assign(record, {
|
||||
imageUrl: await minio.presignedGetObject(MINIO_BUCKET, imageLocation(record.id), 60 * 60),
|
||||
imageUrl: await presignedGetObjectIfExist(MINIO_BUCKET, imageLocation(record.id), 60 * 60),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -222,7 +226,7 @@ export class ServiceController extends Controller {
|
|||
this.setStatus(HttpStatus.CREATED);
|
||||
|
||||
return Object.assign(record, {
|
||||
imageUrl: await minio.presignedGetObject(
|
||||
imageUrl: await presignedGetObjectIfExist(
|
||||
MINIO_BUCKET,
|
||||
imageLocation(record.id),
|
||||
12 * 60 * 60,
|
||||
|
|
@ -250,12 +254,12 @@ export class ServiceController extends Controller {
|
|||
where: { id: serviceId },
|
||||
});
|
||||
return Object.assign(record, {
|
||||
profileImageUrl: await minio.presignedGetObject(
|
||||
imageUrl: await presignedGetObjectIfExist(
|
||||
MINIO_BUCKET,
|
||||
imageLocation(record.id),
|
||||
12 * 60 * 60,
|
||||
),
|
||||
profileImageUploadUrl: await minio.presignedPutObject(
|
||||
imageUploadUrl: await minio.presignedPutObject(
|
||||
MINIO_BUCKET,
|
||||
imageLocation(record.id),
|
||||
12 * 60 * 60,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue