Skip to content

Instantly share code, notes, and snippets.

@ceelsoin
Created July 5, 2023 01:20
Show Gist options
  • Save ceelsoin/f423d9bee033296c2419e6bef9a32958 to your computer and use it in GitHub Desktop.
Save ceelsoin/f423d9bee033296c2419e6bef9a32958 to your computer and use it in GitHub Desktop.
Bunny TUS Upload Signature Typescript
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