Skip to content
This repository was archived by the owner on Jun 29, 2025. It is now read-only.

Commit d010a8a

Browse files
committed
feat: upload 3 files at same time
1 parent 9798e26 commit d010a8a

File tree

4 files changed

+76
-28
lines changed

4 files changed

+76
-28
lines changed

backend/src/prisma/prisma.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Injectable } from "@nestjs/common";
2-
import { ConfigService } from "@nestjs/config";
32
import { PrismaClient } from "@prisma/client";
43

54
@Injectable()
@@ -8,7 +7,7 @@ export class PrismaService extends PrismaClient {
87
super({
98
datasources: {
109
db: {
11-
url: "file:../data/pingvin-share.db",
10+
url: "file:../data/pingvin-share.db?connection_limit=1",
1211
},
1312
},
1413
});

frontend/package-lock.json

Lines changed: 61 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"next-cookies": "^2.0.3",
2828
"next-http-proxy-middleware": "^1.2.5",
2929
"next-pwa": "^5.6.0",
30+
"p-limit": "^4.0.0",
3031
"react": "^18.2.0",
3132
"react-dom": "^18.2.0",
3233
"react-icons": "^4.7.1",

frontend/src/pages/upload.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Button, Group } from "@mantine/core";
22
import { useModals } from "@mantine/modals";
33
import axios from "axios";
44
import { useRouter } from "next/router";
5+
import pLimit from "p-limit";
56
import { useEffect, useState } from "react";
67
import Meta from "../components/Meta";
78
import Dropzone from "../components/upload/Dropzone";
@@ -12,10 +13,11 @@ import useConfig from "../hooks/config.hook";
1213
import useUser from "../hooks/user.hook";
1314
import shareService from "../services/share.service";
1415
import { FileUpload } from "../types/File.type";
15-
import { ShareSecurity } from "../types/share.type";
16+
import { Share, ShareSecurity } from "../types/share.type";
1617
import toast from "../utils/toast.util";
1718

18-
let share: any;
19+
let share: Share;
20+
const promiseLimit = pLimit(3);
1921

2022
const Upload = () => {
2123
const router = useRouter();
@@ -41,7 +43,8 @@ const Upload = () => {
4143
})
4244
);
4345
share = await shareService.create(id, expiration, recipients, security);
44-
for (let i = 0; i < files.length; i++) {
46+
const uploadPromises = files.map((file, i) => {
47+
// Callback to indicate current upload progress
4548
const progressCallBack = (progress: number) => {
4649
setFiles((files) => {
4750
return files.map((file, callbackIndex) => {
@@ -54,11 +57,15 @@ const Upload = () => {
5457
};
5558

5659
try {
57-
await shareService.uploadFile(share.id, files[i], progressCallBack);
60+
return promiseLimit(() =>
61+
shareService.uploadFile(share.id, file, progressCallBack)
62+
);
5863
} catch {
59-
files[i].uploadingProgress = -1;
64+
file.uploadingProgress = -1;
6065
}
61-
}
66+
});
67+
68+
await Promise.all(uploadPromises);
6269
} catch (e) {
6370
if (axios.isAxiosError(e)) {
6471
toast.error(e.response?.data?.message ?? "An unkown error occured.");

0 commit comments

Comments
 (0)