-
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.
feat: fixing video preview for cloudflare r2
- Loading branch information
Showing
6 changed files
with
61 additions
and
6 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,32 @@ | ||
import Post from '#models/post' | ||
import User from '#models/user' | ||
import env from '#start/env' | ||
import { DateTime } from 'luxon' | ||
import { createHmac } from 'node:crypto' | ||
|
||
type Params = { | ||
user: User | ||
post: Post | ||
} | ||
|
||
export default class GetHlsSignature { | ||
static async handle({ user, post }: Params) { | ||
const version = 'v1' | ||
const userId = user.id ?? 'NA' | ||
const videoId = post.videoR2Id | ||
const expiration = DateTime.now().plus({ hours: 48 }).toISO() | ||
const payload = [version, userId, videoId, expiration].join('|') | ||
const signature = createHmac('sha256', env.get('R2_SIGNING_KEY')) | ||
.update(payload) | ||
.setEncoding('base64') | ||
.digest('hex') | ||
|
||
return { | ||
signature, | ||
version, | ||
userId, | ||
videoId, | ||
expiration, | ||
} | ||
} | ||
} |
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