Skip to content

Commit

Permalink
Fix content-disposition types
Browse files Browse the repository at this point in the history
  • Loading branch information
backjonas committed Sep 8, 2023
1 parent b58d6f9 commit 10b2318
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.9",
"@types/content-disposition": "^0.5.6",
"@types/gapi": "^0.0.44",
"@types/marked": "^5.0.0",
"@types/node": "20.3.1",
Expand Down
4 changes: 3 additions & 1 deletion pages/api/drive/private/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const drive = getDriveInstance(process.env.GOOGLE_PRIVATE_CREDS)

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
try {
const { fileId, fileName } = req.query
let { fileId, fileName } = req.query
if (fileId instanceof Array) fileId = fileId[0]
if (fileName instanceof Array) fileName = fileName[0]
const stream = await getDriveFile(fileId, drive)

res.setHeader('content-disposition', contentDisposition(fileName || fileId))
Expand Down
6 changes: 4 additions & 2 deletions pages/api/drive/public/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ const drive = getDriveInstance()

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
try {
const { fileId, fileName } = req.query
let { fileId, fileName } = req.query
if (fileId instanceof Array) fileId = fileId[0]
if (fileName instanceof Array) fileName = fileName[0]
const stream = await getDriveFile(fileId, drive)
console.log(contentDisposition(fileName))

res.setHeader('content-disposition', contentDisposition(fileName || fileId))
stream.pipe(res)
} catch (error) {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@
lodash.merge "^4.6.2"
postcss-selector-parser "6.0.10"

"@types/content-disposition@^0.5.6":
version "0.5.6"
resolved "https://registry.yarnpkg.com/@types/content-disposition/-/content-disposition-0.5.6.tgz#0f5fa03609f308a7a1a57e0b0afe4b95f1d19740"
integrity sha512-GmShTb4qA9+HMPPaV2+Up8tJafgi38geFi7vL4qAM7k8BwjoelgHZqEUKJZLvughUw22h6vD/wvwN4IUCaWpDA==

"@types/gapi@^0.0.44":
version "0.0.44"
resolved "https://registry.yarnpkg.com/@types/gapi/-/gapi-0.0.44.tgz#f097f7a0f59d63a59098a08a62a560ca168426fb"
Expand Down

0 comments on commit 10b2318

Please sign in to comment.