fixed file naming

This commit is contained in:
slawk0
2024-11-21 22:44:15 +01:00
parent cd24b1c49f
commit 33fca2564e
4 changed files with 7 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
import { File } from 'lucide-react'; import { File } from 'lucide-react';
const FileBox = ({ url }: { url: string }) => { const FileBox = ({ url }: { url: string }) => {
const fileNameWithSuffix = url.split('/').pop(); // 'attachment.pdf-321321321312312' const fileNameWithSuffix = url.split('/').pop();
const fullFileName = fileNameWithSuffix?.replace(/-\d+$/, ''); const fullFileName = fileNameWithSuffix?.replace(/-\d+$/, '');
const filename = fullFileName?.slice(0, 25) + '...'; const filename = fullFileName?.slice(0, 25) + '...';

View File

@@ -5,7 +5,7 @@ SERVER_PORT=3000 #DO NOT CHANGE
JWT_SECRET=fdsfsdfds@ JWT_SECRET=fdsfsdfds@
ORIGIN=http://localhost:5173 ORIGIN=http://localhost:5173
PG_HOST=192.168.0.47
PG_USER=postgres PG_USER=postgres
PG_PASSWORD=haslo PG_PASSWORD=haslo
PG_DATABASE=relay PG_DATABASE=relay
PG_HOST=192.168.0.47

View File

@@ -6,7 +6,7 @@ const client = new Client({
password: process.env.PG_PASSWORD, password: process.env.PG_PASSWORD,
database: process.env.PG_DATABASE, database: process.env.PG_DATABASE,
host: process.env.PG_HOST, host: process.env.PG_HOST,
port: 5432, port: 5433,
}); });
client client

View File

@@ -55,9 +55,11 @@ const storage = multer.diskStorage({
}, },
filename: function (req, file, cb) { filename: function (req, file, cb) {
const uniqueSuffix = Date.now() + "-" + Math.round(Math.random() * 1e9); const uniqueSuffix = Date.now() + "-" + Math.round(Math.random() * 1e9);
const extension = extname(file.originalname); const extension = extname(file.originalname).toString();
const originalName = file.originalname;
const filename = originalName?.substring(0, originalName.lastIndexOf("."));
//const finalName = uniqueSuffix + extension; //const finalName = uniqueSuffix + extension;
const finalName = `${file.originalname}-${Math.round(Math.random() * 1e9)}`; const finalName = `${filename}-${Math.round(Math.random() * 1e9)}${extension}`;
file.finalName = finalName; file.finalName = finalName;
cb(null, finalName); cb(null, finalName);
}, },