diff --git a/Dockerfile b/Dockerfile index e662823..bf28f84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,7 @@ COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/.next ./.next COPY --from=builder /app/public ./public COPY --from=builder /app/prisma ./prisma +COPY --from=builder /app/next.config.ts ./next.config.ts RUN npm prune --omit=dev EXPOSE 80 CMD ["npm", "start", "--", "-p", "3000", "-H", "0.0.0.0"] diff --git a/lib/image.ts b/lib/image.ts index a9041ab..a94ffdd 100644 --- a/lib/image.ts +++ b/lib/image.ts @@ -2,7 +2,7 @@ import crypto from "crypto"; import sharp from "sharp"; import { AppError } from "@/lib/action-result"; -import { getMinioClient } from "@/lib/minio"; +import { getMinioClient, getMinioPublicClient } from "@/lib/minio"; const BUCKET = "uploads"; const MAX_FILE_SIZE = 5 * 1024 * 1024; @@ -51,7 +51,7 @@ export async function removeImage(key: string) { } export async function getImageUrl(key: string): Promise { - return getMinioClient().presignedGetObject( + return getMinioPublicClient().presignedGetObject( BUCKET, key, 60 * 5 diff --git a/lib/minio.ts b/lib/minio.ts index 47c416f..7766005 100644 --- a/lib/minio.ts +++ b/lib/minio.ts @@ -1,16 +1,32 @@ import { Client } from "minio"; -let _client: Client | null = null; +let _internalClient: Client | null = null; +let _publicClient: Client | null = null; export function getMinioClient(): Client { - if (!_client) { - _client = new Client({ + if (!_internalClient) { + _internalClient = new Client({ endPoint: process.env.MINIO_URL!, port: Number(process.env.MINIO_PORT), useSSL: false, accessKey: process.env.MINIO_ACCESS_KEY!, - secretKey: process.env.MINIO_SECRET_KEY! + secretKey: process.env.MINIO_SECRET_KEY!, }); } - return _client; + return _internalClient; } + +export function getMinioPublicClient(): Client { + if (!_publicClient) { + const url = new URL(process.env.MINIO_PUBLIC_URL!); + + _publicClient = new Client({ + endPoint: url.hostname, + port: url.port ? Number(url.port) : (url.protocol === "https:" ? 443 : 80), + useSSL: url.protocol === "https:", + accessKey: process.env.MINIO_ACCESS_KEY!, + secretKey: process.env.MINIO_SECRET_KEY!, + }); + } + return _publicClient; +} \ No newline at end of file