CJ_Clippy 9a708fce1d
Some checks failed
fp/our CI/CD / build (push) Successful in 53s
ci / test (push) Failing after 2m41s
add vibeui player
2025-12-03 03:59:28 -08:00

29 lines
1.1 KiB
TypeScript

import spawn from 'nano-spawn';
import env from '../../.config/env';
import { basename } from 'node:path';
export async function b2Download(fromS3Key: string, tmpFilePath: string): Promise<string> {
await spawn('b2', ['file', 'download', `b2://${env.AWS_BUCKET}/${fromS3Key}`, tmpFilePath]);
return fromS3Key;
}
/**
* We put the hls package under `/:collection/:id/hls/` so we can use Bunny CDN's token singing
* to allow token access to all the files within that folder
* @see https://support.bunny.net/hc/en-us/articles/360016055099-How-to-sign-URLs-for-BunnyCDN-Token-Authentication
*/
export function getS3KeyTarget(collectionId: string, vodId: string, filename: string, subFolder: string | null) {
if (!filename) throw new Error('third param filename was missing');
if (!vodId) throw new Error('second param vodId was missing');
if (!collectionId) throw new Error('first param collectionId was missing');
let s3KeyTarget: string;
let name = basename(filename);
if (subFolder) {
s3KeyTarget = `${collectionId}/${vodId}/${subFolder}/${name}`;
} else {
s3KeyTarget = `${collectionId}/${vodId}/${name}`;
}
return s3KeyTarget
}