fix: minio and main links

This commit is contained in:
Ivan Rezchikov
2026-07-12 16:47:49 +03:00
parent eaaf552ae6
commit 039cb4d2d3
4 changed files with 52 additions and 55 deletions
+2 -2
View File
@@ -2,7 +2,7 @@ import crypto from "crypto";
import sharp from "sharp";
import { AppError } from "@/lib/action-result";
import { getMinioClient, getMinioPublicClient } from "@/lib/minio";
import { getMinioClient } 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<string> {
return getMinioPublicClient().presignedGetObject(
return getMinioClient().presignedGetObject(
BUCKET,
key,
60 * 5
+5 -20
View File
@@ -1,32 +1,17 @@
import { Client } from "minio";
let _internalClient: Client | null = null;
let _publicClient: Client | null = null;
let _client: Client | null = null;
export function getMinioClient(): 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!,
});
}
return _internalClient;
}
export function getMinioPublicClient(): Client {
if (!_publicClient) {
if (!_client) {
const url = new URL(process.env.MINIO_PUBLIC_URL!);
_publicClient = new Client({
_client = new Client({
endPoint: url.hostname,
port: url.port ? Number(url.port) : (url.protocol === "https:" ? 443 : 80),
port: url.port ? Number(url.port) : 443,
useSSL: url.protocol === "https:",
accessKey: process.env.MINIO_ACCESS_KEY!,
secretKey: process.env.MINIO_SECRET_KEY!,
});
}
return _publicClient;
return _client;
}