-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate backend question service with frontend
- Loading branch information
Showing
13 changed files
with
1,832 additions
and
1,014 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,4 @@ dist-ssr | |
|
||
# Environment files | ||
.env | ||
firebase.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import admin from "firebase-admin"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
import serviceAccount from "../firebase.json"; | ||
|
||
admin.initializeApp({ | ||
credential: admin.credential.cert(serviceAccount as admin.ServiceAccount), | ||
storageBucket: "gs://peerprep-c3bd1.appspot.com", | ||
}); | ||
|
||
const bucket = admin.storage().bucket(); | ||
|
||
const uploadFileToFirebase = async ( | ||
file: Express.Multer.File, | ||
): Promise<string> => { | ||
return new Promise((resolve, reject) => { | ||
const fileName = uuidv4(); | ||
const ref = bucket.file(fileName); | ||
|
||
const blobStream = ref.createWriteStream({ | ||
metadata: { | ||
contentType: file.mimetype, | ||
}, | ||
}); | ||
|
||
blobStream.on("error", (error) => { | ||
reject(error); | ||
}); | ||
|
||
blobStream.on("finish", async () => { | ||
try { | ||
await ref.makePublic(); | ||
resolve(`https://storage.googleapis.com/${bucket.name}/${fileName}`); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
|
||
blobStream.end(file.buffer); | ||
}); | ||
}; | ||
|
||
export { bucket, uploadFileToFirebase }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import multer from "multer"; | ||
|
||
const storage = multer.memoryStorage(); | ||
const upload = multer({ storage }).array("images[]"); | ||
|
||
export { upload }; |
Oops, something went wrong.