fix duplicate

This commit is contained in:
waveringana 2024-01-03 11:39:25 -05:00
parent ae2cdada07
commit 443fea0fb0
No known key found for this signature in database
2 changed files with 27 additions and 11 deletions

View file

@ -72,7 +72,7 @@ This project uses environmental variables to configure functions.
### Using Docker ### Using Docker
```bash ```bash
docker run -d -p "3000:3000" -e EBPORT=3000 -e EBPASS=changeme -e EBAPI_KEY=changeme ghcr.io/waveringana/embedder:1.10.3 docker run -d -p "3000:3000" -e EBPORT=3000 -e EBPASS=changeme -e EBAPI_KEY=changeme ghcr.io/waveringana/embedder:1.10.4
``` ```
### Docker Compose ### Docker Compose
@ -90,7 +90,7 @@ services:
volumes: volumes:
- ./db:/var/db - ./db:/var/db
- ./uploads:/uploads - ./uploads:/uploads
image: ghcr.io/waveringana/embedder:1.10.3 image: ghcr.io/waveringana/embedder:1.10.4
``` ```
## 📜 License ## 📜 License

View file

@ -8,6 +8,7 @@ export type DestinationCallback = (
error: Error | null, error: Error | null,
destination: string, destination: string,
) => void; ) => void;
export type FileNameCallback = (error: Error | null, filename: string) => void; export type FileNameCallback = (error: Error | null, filename: string) => void;
let randomizeNames = false; let randomizeNames = false;
@ -43,40 +44,55 @@ export const fileStorage = multer.diskStorage({
} }
let filenameSet = true; let filenameSet = true;
let existsBool = true; let existsBool = false;
let suffix: number;
if ( if (
request.body.title == "" || request.body.title != "" ||
request.body.title == null || request.body.title != null ||
request.body.title == undefined request.body.title != undefined
) { ) {
filenameSet = false; filenameSet = false;
} }
if (exists.length == 0) { if (exists.length != 0) {
existsBool = false; existsBool = true;
suffix = new Date().getTime() / 1000;
} }
console.log(request.body.title);
if (randomizeNames) { if (randomizeNames) {
//Random string of 8 alphanumeric characters
//Chance of collision is extremely low, not worth checking for //Chance of collision is extremely low, not worth checking for
console.log("Randomizing name");
callback(null, Math.random().toString(36).slice(2, 10) + fileExtension); callback(null, Math.random().toString(36).slice(2, 10) + fileExtension);
return; return;
} }
if (filenameSet && existsBool) { if (filenameSet && existsBool) {
callback(null, request.body.title + fileExtension); console.log(`filenameSet is ${filenameSet} and existsBool is ${existsBool}`);
callback(null, request.body.title + "-" + suffix + fileExtension);
return; return;
} }
if (!filenameSet && existsBool) { if (!filenameSet && existsBool) {
callback(null, filename + fileExtension); console.log(`filenameSet is ${filenameSet} and existsBool is ${existsBool}`);
callback(null, filename + "-" + suffix + fileExtension);
return; return;
} }
if (filenameSet && !existsBool) { if (filenameSet && !existsBool) {
console.log(`filenameSet is ${filenameSet} and existsBool is ${existsBool}`);
callback(null, request.body.title + fileExtension); callback(null, request.body.title + fileExtension);
return; return;
} }
if (!filenameSet && !existsBool) {
console.log(`filenameSet is ${filenameSet} and existsBool is ${existsBool}`);
callback(null, filename + fileExtension);
return;
}
}, },
); );
}, },