-
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.
arweave instead of ipfs for image uploads
- Loading branch information
1 parent
d0ee51f
commit f368aa8
Showing
29 changed files
with
1,000 additions
and
1,229 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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
ARWEAVE_ADDRESS= | ||
ARWEAVE_KTY= | ||
ARWEAVE_N= | ||
ARWEAVE_E= | ||
ARWEAVE_D= | ||
ARWEAVE_P= | ||
ARWEAVE_Q= | ||
ARWEAVE_DP= | ||
ARWEAVE_DQ= | ||
ARWEAVE_QI= | ||
FILE_UPLOAD_SERVICE= | ||
IMAGEKIT_ENDPOINT= | ||
IMAGEKIT_PUBLIC_KEY= | ||
IMAGEKIT_PRIVATE_KEY= | ||
LINK_PREVIEW_SERVICE= | ||
RPC_CUSTOM= | ||
TENOR_KEY= | ||
THIRDWEB_CLIENT_ID= | ||
TENOR_KEY= |
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,61 @@ | ||
import Arweave from 'arweave'; | ||
import { Buffer } from 'buffer'; | ||
|
||
export default async function handler(req, res) { | ||
// Check if the request method is POST | ||
if (req.method !== 'POST') { | ||
return res.status(405).json({ message: 'Method Not Allowed' }); | ||
} | ||
|
||
try { | ||
const { fileData, fileName, fileType } = req.body; | ||
|
||
// Initialize Arweave | ||
const arweave = Arweave.init({ | ||
host: 'arweave.net', | ||
port: 443, | ||
protocol: 'https' | ||
}); | ||
|
||
// Construct the key file object from environment variables | ||
const keyFile = { | ||
kty: process.env.ARWEAVE_KTY, | ||
n: process.env.ARWEAVE_N, | ||
e: process.env.ARWEAVE_E, | ||
d: process.env.ARWEAVE_D, | ||
p: process.env.ARWEAVE_P, | ||
q: process.env.ARWEAVE_Q, | ||
dp: process.env.ARWEAVE_DP, | ||
dq: process.env.ARWEAVE_DQ, | ||
qi: process.env.ARWEAVE_QI | ||
}; | ||
|
||
// Convert base64 file data to buffer | ||
const fileBuffer = Buffer.from(fileData, 'base64'); | ||
|
||
// Create a transaction | ||
const transaction = await arweave.createTransaction({ data: fileBuffer }, keyFile); | ||
|
||
// Add tags to the transaction | ||
transaction.addTag('Content-Type', fileType); | ||
transaction.addTag('File-Name', fileName); | ||
|
||
// Sign the transaction | ||
await arweave.transactions.sign(transaction, keyFile); | ||
|
||
// Submit the transaction | ||
const response = await arweave.transactions.post(transaction); | ||
|
||
if (response.status === 200) { | ||
return res.status(200).json({ | ||
message: 'File uploaded successfully', | ||
transactionId: transaction.id | ||
}); | ||
} else { | ||
throw new Error('Failed to upload file to Arweave'); | ||
} | ||
} catch (error) { | ||
console.error('Error:', error); | ||
return res.status(500).json({ message: 'Internal server error' }); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
const ImageKit = require("imagekit"); | ||
const ImageKit = require('imagekit') | ||
|
||
export default async function handler(request, response) { | ||
try { | ||
const imagekit = new ImageKit({ | ||
urlEndpoint: process.env.IMAGEKIT_ENDPOINT, | ||
publicKey: process.env.IMAGEKIT_PUBLIC_KEY, | ||
privateKey: process.env.IMAGEKIT_PRIVATE_KEY | ||
privateKey: process.env.IMAGEKIT_PRIVATE_KEY, | ||
}) | ||
|
||
return response.status(200).json({ | ||
data: imagekit.getAuthenticationParameters() | ||
}); | ||
data: imagekit.getAuthenticationParameters(), | ||
}) | ||
} catch (error) { | ||
console.error(error); | ||
next(error); | ||
console.error(error) | ||
next(error) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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.