-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #475 from ourzora/iain/switch-ipfs-to-pinata
Fix media upload server -> move to pinata.cloud backend
- Loading branch information
Showing
6 changed files
with
14,178 additions
and
12,232 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { NextRequest, NextResponse } from 'next/server' | ||
|
||
const PINATA_API_KEY = process.env.PINATA_API_KEY | ||
|
||
const keyRestrictions = { | ||
keyName: 'Signed Upload JWT', | ||
maxUses: 1, | ||
permissions: { | ||
endpoints: { | ||
data: { | ||
pinList: false, | ||
userPinnedDataTotal: false, | ||
}, | ||
pinning: { | ||
pinFileToIPFS: true, | ||
pinJSONToIPFS: false, | ||
pinJobs: false, | ||
unpin: false, | ||
userPinPolicy: false, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export async function POST(request: NextRequest): Promise<NextResponse> { | ||
try { | ||
const options = { | ||
method: 'POST', | ||
headers: { | ||
accept: 'application/json', | ||
'content-type': 'application/json', | ||
authorization: `Bearer ${PINATA_API_KEY}`, | ||
}, | ||
body: JSON.stringify(keyRestrictions), | ||
} | ||
|
||
const jwtRepsonse = await fetch( | ||
'https://api.pinata.cloud/users/generateApiKey', | ||
options | ||
) | ||
const json = await jwtRepsonse.json() | ||
const { JWT } = json | ||
return NextResponse.json({ JWT }, { status: 200 }) | ||
} catch (e) { | ||
console.log(e) | ||
return NextResponse.json({ error: 'Server Error' }, { status: 500 }) | ||
} | ||
} |
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.