-
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.
Add: Redirect to origin url feature after user has been told to sign-…
…in using query params, route protection for admin, icons for customer face dropdown, responsives for admin pages and route for free products download.
- Loading branch information
1 parent
8115941
commit b9488ca
Showing
17 changed files
with
190 additions
and
82 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
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 was deleted.
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
29 changes: 29 additions & 0 deletions
29
src/app/(customerFacing)/products/download/free/[productId]/route.ts
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,29 @@ | ||
import db from "@/db/db"; | ||
import fs from "fs/promises"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export async function GET( | ||
req: NextRequest, | ||
{ params: { productId } }: { params: { productId: string } } | ||
) { | ||
const product = await db.product.findUnique({ | ||
where: { id: productId }, | ||
select: { filePath: true, name: true }, | ||
}); | ||
|
||
if (product == null) | ||
return NextResponse.redirect(new URL("/products/download/expired", req.url)); | ||
|
||
// TODO: create an order or something to track number of downloads | ||
|
||
const { size } = await fs.stat(product.filePath); | ||
const file = await fs.readFile(product.filePath); | ||
const extension = product.filePath.split(".").pop(); | ||
|
||
return new NextResponse(file, { | ||
headers: { | ||
"Content-Disposition": `attachment; filename="${product.name}.${extension}"`, | ||
"Content-Length": size.toString(), | ||
}, | ||
}); | ||
} |
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
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
Oops, something went wrong.