Created
July 5, 2023 01:20
-
-
Save ceelsoin/f423d9bee033296c2419e6bef9a32958 to your computer and use it in GitHub Desktop.
Bunny TUS Upload Signature Typescript
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
require("dotenv").config(); | |
const crypto = require("crypto"); | |
private getAPIKey(): string { | |
return process.env.BUNNY_STREAM_API_KEY | |
} | |
private getSignature(library_id, video_id, expiration_time = 86400) { | |
//https://docs.bunny.net/reference/tus-resumable-uploads | |
const expires = Math.floor(new Date() as any / 1000) + expiration_time; | |
const hashableBase = library_id + this.getAPIKey() + expires + video_id | |
const signature = crypto.createHash("sha256").update(hashableBase).digest('hex') | |
return {signature, expires, library_id} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment