Ready for 1.1.3

This commit is contained in:
charlesgauthereau
2025-11-07 22:04:10 +01:00
parent b0775e82ea
commit cf8e5b7094
6 changed files with 8 additions and 58 deletions
-2
View File
@@ -3,9 +3,7 @@ import nextVitals from 'eslint-config-next/core-web-vitals'
const eslintConfig = defineConfig([ const eslintConfig = defineConfig([
...nextVitals, ...nextVitals,
// Override default ignores of eslint-config-next.
globalIgnores([ globalIgnores([
// Default ignores of eslint-config-next:
'.next/**', '.next/**',
'out/**', 'out/**',
'build/**', 'build/**',
+1
View File
@@ -43,6 +43,7 @@ export const PORTABASE_DEFAULT_SETTINGS = {
"'self'", "'self'",
"https://api.iconify.design", "https://api.iconify.design",
"https://code.iconify.design", "https://code.iconify.design",
], ],
OBJECT_SRC: ["'none'"], OBJECT_SRC: ["'none'"],
BASE_URI: ["'self'"], BASE_URI: ["'self'"],
+1 -1
View File
@@ -37,7 +37,7 @@ export const schemas = {
export const db = drizzle({ export const db = drizzle({
client: pool, client: pool,
// logger: process.env.NODE_ENV != 'production', logger: process.env.NODE_ENV != 'production',
schema: schemas, schema: schemas,
}); });
-1
View File
@@ -4,7 +4,6 @@ import {eq} from "drizzle-orm";
import * as drizzleDb from "@/db"; import * as drizzleDb from "@/db";
import {retentionJob} from "@/lib/tasks"; import {retentionJob} from "@/lib/tasks";
import {generateRSAKeys} from "@/utils/rsa-keys"; import {generateRSAKeys} from "@/utils/rsa-keys";
import {getPublicServerKeyContent} from "@/features/keys/keys.action";
export async function init() { export async function init() {
+6 -51
View File
@@ -1,10 +1,10 @@
import * as Minio from "minio"; import * as Minio from "minio";
import {env} from "@/env.mjs"; import {env} from "@/env.mjs";
import internal from "node:stream"; import internal from "node:stream";
import {db} from "@/db";
import * as drizzleDb from "@/db";
import {eq} from "drizzle-orm";
import stream from "node:stream"; import stream from "node:stream";
import * as drizzleDb from "@/db";
import {db} from "@/db";
import {eq} from "drizzle-orm";
async function getS3Client() { async function getS3Client() {
@@ -24,32 +24,17 @@ async function getS3Client() {
secretKey: settings.s3SecretAccessKey ?? "", secretKey: settings.s3SecretAccessKey ?? "",
}; };
// const s3Client = return new Minio.Client({
// env.NODE_ENV === "production"
// ? new Minio.Client({
// ...baseConfig,
// useSSL: env.S3_USE_SSL === "true",
// })
// : new Minio.Client({
// ...baseConfig,
// port: Number(env.S3_PORT ?? 0),
// useSSL: env.S3_USE_SSL === "true",
// });
const s3Client = new Minio.Client({
...baseConfig, ...baseConfig,
port: Number(env.S3_PORT ?? 0), port: Number(env.S3_PORT ?? 0),
useSSL: env.S3_USE_SSL === "true", useSSL: env.S3_USE_SSL === "true",
}) });
return s3Client;
} }
export async function checkMinioAlive() { export async function checkMinioAlive() {
try { try {
console.log("Check MinioAlive"); console.log("Check MinioAlive");
const s3Client = await getS3Client(); const s3Client = await getS3Client();
// Try to list buckets to check connectivity
const buckets = await s3Client.listBuckets(); const buckets = await s3Client.listBuckets();
console.log("MinIO is up and running. Buckets:", buckets); console.log("MinIO is up and running. Buckets:", buckets);
return {message: true}; return {message: true};
@@ -106,9 +91,6 @@ export async function deleteFileFromBucket({
} }
/** /**
* Save file in S3 bucket * Save file in S3 bucket
* @param bucketName name of the bucket * @param bucketName name of the bucket
@@ -120,45 +102,21 @@ export async function saveFileInBucket({bucketName, fileName, file}: {
fileName: string; fileName: string;
file: Buffer | internal.Readable file: Buffer | internal.Readable
}) { }) {
// Check if Minio is Alive
await checkMinioAlive(); await checkMinioAlive();
// Create bucket if it doesn't exist
await createBucketIfNotExists(bucketName); await createBucketIfNotExists(bucketName);
// check if file exists - optional.
// Without this check, the file will be overwritten if it exists
const fileExists = await checkFileExistsInBucket({ const fileExists = await checkFileExistsInBucket({
bucketName, bucketName,
fileName, fileName,
}); });
console.log("File exists:", fileExists); console.log("File exists:", fileExists);
if (fileExists) { if (fileExists) {
throw new Error("File already exists"); throw new Error("File already exists");
} }
const s3Client = await getS3Client(); const s3Client = await getS3Client();
// Upload image to S3 bucket return await s3Client.putObject(bucketName, fileName, file);
const result = await s3Client.putObject(bucketName, fileName, file);
return result;
} }
/**
* Check if file exists in bucket
* @param bucketName name of the bucket
* @param fileName name of the file
* @returns true if file exists, false if not
*/
// export async function checkFileExistsInBucket({bucketName, fileName}: { bucketName: string; fileName: string }) {
// const s3Client = await getS3Client();
//
// try {
// await s3Client.statObject(bucketName, fileName);
// } catch (error) {
// return false;
// }
// return true;
// }
export async function getObjectFromClient({ export async function getObjectFromClient({
bucketName, bucketName,
@@ -188,8 +146,6 @@ export async function checkFileExistsInBucket({
if (error.code === 'NoSuchKey' || error.message?.includes('not found')) { if (error.code === 'NoSuchKey' || error.message?.includes('not found')) {
return false; return false;
} }
// Instead of throwing, return false to prevent crashes
// console.error("Unexpected S3 statObject error:", error);
return false; return false;
} }
} }
@@ -280,7 +236,6 @@ export async function createPresignedUrlToDownload({
} }
const presignedUrl = await s3Client.presignedGetObject(bucketName, fileName, expiry); const presignedUrl = await s3Client.presignedGetObject(bucketName, fileName, expiry);
console.debug("Generated pre signed URL:", presignedUrl); console.debug("Generated pre signed URL:", presignedUrl);
return {url: presignedUrl}; return {url: presignedUrl};
} catch (err: any) { } catch (err: any) {
console.error("Error in createPreSignedUrlToDownload:", { console.error("Error in createPreSignedUrlToDownload:", {
-3
View File
@@ -9,9 +9,6 @@ export function capitalizeFirstLetter(text: string): string {
return text ? text.charAt(0).toUpperCase() + text.slice(1) : ""; return text ? text.charAt(0).toUpperCase() + text.slice(1) : "";
} }
export function isUUID(str: string) { export function isUUID(str: string) {
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str); return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str);
} }