-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : allow user to download their contributions
- Loading branch information
Showing
8 changed files
with
127 additions
and
14 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
"mcversion", | ||
"modid", | ||
"Mojangstudios", | ||
"nodebuffer", | ||
"prisma", | ||
"serversocket", | ||
"stylelint", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,43 @@ | ||
|
||
import { createReadStream } from 'fs'; | ||
|
||
import { UserRole } from '@prisma/client'; | ||
import JSZip from 'jszip'; | ||
|
||
import { canAccess } from '~/lib/auth'; | ||
import { FILE_PATH } from '~/lib/constants'; | ||
import { db } from '~/lib/db'; | ||
|
||
interface Params { | ||
params: { | ||
ownerId: string; | ||
}; | ||
} | ||
|
||
export async function GET(req: Request, { params: { ownerId } }: Params) { | ||
await canAccess(UserRole.ADMIN, ownerId); | ||
|
||
const contributions = await db.contribution.findMany({ | ||
where: { ownerId }, | ||
select: { file: true, filename: true, status: true, hash: true }, | ||
}); | ||
|
||
const zip = new JSZip(); | ||
|
||
for (const contribution of contributions) { | ||
zip.file<'stream'>( | ||
`${contribution.status}/${contribution.hash}_${contribution.filename}`, | ||
createReadStream(`${FILE_PATH}/${contribution.file.replace('/files', '/')}`) | ||
); | ||
} | ||
|
||
const zipFile = await zip.generateAsync({ type: 'nodebuffer' }); | ||
|
||
return new Response(zipFile, { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/zip', | ||
}, | ||
}); | ||
|
||
} |
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
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