Last active
October 29, 2025 23:35
-
-
Save nickjuntilla/baa523c168eff08b554b8a8875d6d633 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const Arweave = require("arweave"); | |
| const loadArweaveWallet = () => { | |
| const walletPath = path.join(__dirname, "creds", "wallet.json"); | |
| if (!fs.existsSync(walletPath)) { | |
| throw new Error("Arweave wallet file not found at: " + walletPath); | |
| } | |
| return JSON.parse(fs.readFileSync(walletPath, "utf8")); | |
| }; | |
| // Initialize Arweave | |
| const arweave = Arweave.init({ | |
| host: "arweave.net", | |
| port: 443, | |
| protocol: "https", | |
| }); | |
| // Add helper function to create video manifest | |
| async function createVideoManifest(videoId, contentType) { | |
| const paths = { | |
| "video.mp4": { | |
| id: videoId, | |
| }, | |
| }; | |
| // Create manifest object | |
| const manifest = { | |
| manifest: "arweave/paths", | |
| version: "0.1.0", | |
| paths, | |
| index: { | |
| path: "video.mp4", | |
| }, | |
| }; | |
| // Create temporary manifest file | |
| const tempFile = `/tmp/video-manifest-${Date.now()}.json`; | |
| fs.writeFileSync(tempFile, JSON.stringify(manifest, null, 2)); | |
| return { manifest, tempFile }; | |
| } | |
| const wallet = loadArweaveWallet(); | |
| const arweaveStartTime = Date.now(); | |
| const [videoBuffer] = await outputFile.download(); | |
| // Upload video to Arweave | |
| const videoTransaction = await arweave.createTransaction( | |
| { data: videoBuffer }, | |
| wallet | |
| ); | |
| videoTransaction.addTag("Content-Type", "video/mp4"); | |
| videoTransaction.addTag("App-Name", "Etch"); | |
| await arweave.transactions.sign(videoTransaction, wallet); | |
| const videoUploader = await arweave.transactions.getUploader( | |
| videoTransaction | |
| ); | |
| while (!videoUploader.isComplete) { | |
| await videoUploader.uploadChunk(); | |
| } | |
| console.log("arweaveTransaction: ", { | |
| size: | |
| (parseInt(videoTransaction.data_size) / (1024 * 1024)).toFixed(2) + | |
| "MB", | |
| arUsed: arweave.ar.winstonToAr(videoTransaction.reward), | |
| uid: uid, | |
| }); | |
| // Create and upload manifest | |
| const { manifest, tempFile } = await createVideoManifest( | |
| videoTransaction.id, | |
| "video/mp4" | |
| ); | |
| const manifestData = fs.readFileSync(tempFile); | |
| const manifestTransaction = await arweave.createTransaction( | |
| { data: manifestData }, | |
| wallet | |
| ); | |
| manifestTransaction.addTag( | |
| "Content-Type", | |
| "application/x.arweave-manifest+json" | |
| ); | |
| manifestTransaction.addTag("App-Name", "Etch"); | |
| await arweave.transactions.sign(manifestTransaction, wallet); | |
| const manifestUploader = await arweave.transactions.getUploader( | |
| manifestTransaction | |
| ); | |
| while (!manifestUploader.isComplete) { | |
| await manifestUploader.uploadChunk(); | |
| } | |
| // Clean up manifest file | |
| fs.unlinkSync(tempFile); | |
| // Clean up GCS output file | |
| await outputFile.delete(); | |
| const manifestUrl = `https://arweave.net/${manifestTransaction.id}`; | |
| arweaveUrl = `${manifestUrl}/video.mp4`; | |
| arweaveDuration = (Date.now() - arweaveStartTime) / 1000; | |
| activeJobs.delete(jobId); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment