Skip to content

Commit f2bb59f

Browse files
committed
feat: add file uploads
1 parent 6771eac commit f2bb59f

File tree

13 files changed

+2237
-745
lines changed

13 files changed

+2237
-745
lines changed

backend/package-lock.json

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

backend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
"tsconfig-paths": "^4.2.0",
6767
"tsx": "^4.19.2",
6868
"typescript": "^5.7.3",
69-
"typescript-eslint": "^8.20.0"
69+
"typescript-eslint": "^8.20.0",
70+
"wrangler": "^4.3.0"
7071
},
7172
"jest": {
7273
"moduleFileExtensions": [

backend/src/admin/admin.controller.spec.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

backend/src/admin/admin.controller.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

backend/src/admin/admin.guard.spec.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

backend/src/admin/admin.guard.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

backend/src/admin/admin.module.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

backend/src/admin/admin.service.spec.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

backend/src/admin/admin.service.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

backend/src/files/files.service.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,9 @@
11
import { Injectable } from '@nestjs/common';
2-
import { createClient } from '@supabase/supabase-js';
32
require ('dotenv').config();
43

54
@Injectable()
65
export class FilesUploadService {
7-
private supabase = createClient(
8-
process.env.SUPABASE_URL as string,
9-
process.env.SUPABASE_KEY as string
10-
);
11-
handlesupabase(){
12-
if(this.supabase){
13-
return 'supabase is connected'
14-
15-
}
16-
else {
17-
return 'supabase not connected'
18-
}
19-
}
206

21-
handleFileUpload(file:Express.Multer.File): string {
22-
if(!file){
23-
return 'file not uploaded'
24-
}
25-
else{
26-
return 'file uploaded successfully'
27-
}
28-
29-
//do error handling if file is not uploaded
30-
}
7+
8+
319
}

frontend/app/(pages)/dashboard/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ interface DashboardProps{
2323
export default function Dashboard(){
2424
const [upload,setUpload]=useState<boolean>(true);
2525
const [friends,setFriend]=useState<boolean>(false);
26-
2726

2827
const {user}=useUser();
2928

@@ -72,7 +71,9 @@ export default function Dashboard(){
7271

7372

7473
<div className={`flex flex-row items-center justify-center mt-[10px] gap-[10px] bg-gray-100 p-[5px] z-10 rounded-md`}>
75-
<Button className="" variant="outline" size="lg" onClick={async () => {
74+
75+
76+
<Button className="" variant="outline" size="lg" onClick={async () => {
7677
setUpload(true);
7778
setFriend(false)
7879
const result = await axios.post('http://localhost:3001/files/upload');

frontend/components/upload.tsx

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,46 @@
1-
import { Button } from "./ui/button"
2-
3-
export const Upload=()=>{
4-
return(
5-
<>
6-
<div className="flex flex-col items-center justify-center h-[200px] w-[350px] mt-[20px] border rounded-lg border-gray-300">
7-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="0.8" stroke="currentColor" className="size-12">
8-
<path stroke-linecap="round" stroke-linejoin="round" d="M9 8.25H7.5a2.25 2.25 0 0 0-2.25 2.25v9a2.25 2.25 0 0 0 2.25 2.25h9a2.25 2.25 0 0 0 2.25-2.25v-9a2.25 2.25 0 0 0-2.25-2.25H15m0-3-3-3m0 0-3 3m3-3V15" />
9-
</svg>
10-
<div className="hidden md:block text-gray-500 mt-[8px]">Drag and Drop the file</div>
11-
<Button className="mt-[8px]">Browse</Button>
12-
</div>
13-
</>
14-
)
15-
}
1+
import { Button } from "./ui/button";
2+
import { useState } from "react";
3+
import axios from "axios";
4+
5+
export const Upload = () => {
6+
const [selectedFile, setSelectedFile] = useState<File | null>(null);
7+
8+
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
9+
if (e.target.files && e.target.files.length > 0) {
10+
setSelectedFile(e.target.files[0]);
11+
}
12+
};
13+
14+
const handleFileUpload = async () => {
15+
if (!selectedFile) {
16+
alert("Please select a file first");
17+
return;
18+
}
19+
20+
const formData = new FormData();
21+
formData.append("file", selectedFile);
22+
23+
try {
24+
const response = await axios.post("http://localhost:3001/upload", formData, {
25+
headers: { "Content-Type": "multipart/form-data" },
26+
});
27+
28+
console.log("File uploaded successfully:", response.data);
29+
} catch (error) {
30+
console.error("Error uploading file:", error);
31+
}
32+
};
33+
34+
return (
35+
<div className="flex flex-col items-center justify-center h-[250px] w-[350px] mt-5 border rounded-lg border-gray-300 p-4">
36+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="size-12">
37+
<path strokeLinecap="round" strokeLinejoin="round" d="M9 8.25H7.5a2.25 2.25 0 0 0-2.25 2.25v9a2.25 2.25 0 0 0 2.25 2.25h9a2.25 2.25 0 0 0 2.25-2.25v-9a2.25 2.25 0 0 0-2.25-2.25H15m0-3-3-3m0 0-3 3m3-3V15" />
38+
</svg>
39+
<div className="text-gray-500 mt-2">Drag and Drop the file</div>
40+
<input type="file" onChange={handleFileChange} className="mt-3 mb-2" />
41+
<Button onClick={handleFileUpload} disabled={!selectedFile}>
42+
Upload
43+
</Button>
44+
</div>
45+
);
46+
};

0 commit comments

Comments
 (0)