auto log-in b2 cli
This commit is contained in:
parent
6aef7c9d22
commit
c22921662d
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "futureporn",
|
||||
"private": true,
|
||||
"version": "2.4.9",
|
||||
"version": "2.4.10",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "concurrently npm:dev:serve npm:dev:build npm:dev:worker npm:dev:compose npm:dev:sftp",
|
||||
|
@ -31,6 +31,8 @@ const EnvSchema = z.object({
|
||||
APP_DIR: z.string().default('/app'),
|
||||
WHISPER_DIR: z.string(),
|
||||
LOG_LEVEL: z.string().default('info'),
|
||||
B2_APPLICATION_KEY_ID: z.string(),
|
||||
B2_APPLICATION_KEY: z.string(),
|
||||
});
|
||||
|
||||
const parsed = EnvSchema.safeParse(process.env);
|
||||
|
@ -27,6 +27,29 @@ function isV1Url(url: string): Boolean {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* authorize if needed
|
||||
*/
|
||||
async function assertB2Account() {
|
||||
const spawn = await getNanoSpawn();
|
||||
|
||||
// see if we are logged in already
|
||||
const accountInfoRaw = await spawn('b2', ['account', 'get']);
|
||||
const accountInfo = JSON.parse(accountInfoRaw.stdout.trim());
|
||||
|
||||
if (accountInfo.accountAuthToken) {
|
||||
logger.debug(`already logged in.`);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug(`authorizing B2 account.`);
|
||||
const authInfoRaw = await spawn('b2', ['account', 'authorize', env.B2_APPLICATION_KEY_ID, env.B2_APPLICATION_KEY]);
|
||||
const authInfo = JSON.parse(authInfoRaw.stdout.trim());
|
||||
|
||||
logger.debug(`Logged in. ${JSON.stringify(authInfo)}`);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a file from V1 bucket to V2 bucket
|
||||
* @param v1Url The V1 file URL (b2://futureporn/...)
|
||||
@ -62,6 +85,7 @@ async function copyFromBucketToBucket(spawn: typeof NanoSpawn, v1Url: string, v2
|
||||
// example v2 https://fp-usc.b-cdn.net/projektmelody-chaturbate-2023-01-01.mp4
|
||||
const copyV1S3ToV2: Task = async (payload: any) => {
|
||||
|
||||
logger.info(`copyV1S3ToV2 with vodId=${payload.vodId}`);
|
||||
const spawn = await getNanoSpawn();
|
||||
|
||||
assertPayload(payload)
|
||||
@ -69,10 +93,6 @@ const copyV1S3ToV2: Task = async (payload: any) => {
|
||||
const vod = await prisma.vod.findFirstOrThrow({
|
||||
where: {
|
||||
id: vodId,
|
||||
AND: [
|
||||
{ thumbnail: { not: '' } },
|
||||
{ thumbnail: { not: null } }
|
||||
]
|
||||
},
|
||||
select: {
|
||||
thumbnail: true,
|
||||
@ -103,6 +123,9 @@ const copyV1S3ToV2: Task = async (payload: any) => {
|
||||
if (!slug) throw new Error(`vtuber ${vod.vtubers[0].id} is missing a slug`);
|
||||
|
||||
|
||||
await assertB2Account();
|
||||
|
||||
|
||||
let v2ThumbnailKey: string | undefined = undefined;
|
||||
let v2SourceVideoKey: string | undefined = undefined;
|
||||
|
||||
|
@ -35,19 +35,20 @@ const scheduleVodProcessing: Task = async (payload: unknown, helpers) => {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Schedule required jobs
|
||||
const jobs: Promise<Job>[] = [];
|
||||
|
||||
if (!vod.sourceVideo) jobs.push(helpers.addJob("getSourceVideo", { vodId }));
|
||||
if (!vod.sha256sum) jobs.push(helpers.addJob("generateVideoChecksum", { vodId }));
|
||||
if (!vod.thumbnail) jobs.push(helpers.addJob("createVideoThumbnail", { vodId }));
|
||||
if (!vod.hlsPlaylist) jobs.push(helpers.addJob("createHlsPlaylist", { vodId }));
|
||||
if (!vod.cidv1) jobs.push(helpers.addJob("createIpfsCid", { vodId }));
|
||||
if (!vod.funscript) jobs.push(helpers.addJob("createFunscript", { vodId }));
|
||||
if (!vod.asrVttKey) jobs.push(helpers.addJob("createTranscription", { vodId }));
|
||||
if (!vod.slvttVTTKey) jobs.push(helpers.addJob("createStoryboard", { vodId }));
|
||||
if (!vod.magnetLink) jobs.push(helpers.addJob("createTorrent", { vodId }));
|
||||
if (vod.thumbnail && vod.sourceVideo) jobs.push(helpers.addJob("copyV1S3ToV2", { vodId }));
|
||||
// if (!vod.sourceVideo) jobs.push(helpers.addJob("getSourceVideo", { vodId }));
|
||||
// if (!vod.sha256sum) jobs.push(helpers.addJob("generateVideoChecksum", { vodId }));
|
||||
// if (!vod.thumbnail) jobs.push(helpers.addJob("createVideoThumbnail", { vodId }));
|
||||
// if (!vod.hlsPlaylist) jobs.push(helpers.addJob("createHlsPlaylist", { vodId }));
|
||||
// if (!vod.cidv1) jobs.push(helpers.addJob("createIpfsCid", { vodId }));
|
||||
// if (!vod.funscript) jobs.push(helpers.addJob("createFunscript", { vodId }));
|
||||
// if (!vod.asrVttKey) jobs.push(helpers.addJob("createTranscription", { vodId }));
|
||||
// if (!vod.slvttVTTKey) jobs.push(helpers.addJob("createStoryboard", { vodId }));
|
||||
// if (!vod.magnetLink) jobs.push(helpers.addJob("createTorrent", { vodId }));
|
||||
if (vod.thumbnail || vod.sourceVideo) jobs.push(helpers.addJob("copyV1S3ToV2", { vodId }));
|
||||
|
||||
const changes = jobs.length;
|
||||
if (changes > 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user