mirror of
https://github.com/morten-olsen/mini-loader.git
synced 2026-02-08 01:36:26 +01:00
feat: switched from worker API to fs based
This commit is contained in:
32
packages/cli/src/commands/artifacts/artifacts.pull.ts
Normal file
32
packages/cli/src/commands/artifacts/artifacts.pull.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Command } from 'commander';
|
||||
import { createClient } from '../../client/client.js';
|
||||
import { step } from '../../utils/step.js';
|
||||
import { Context } from '../../context/context.js';
|
||||
import { dirname, resolve } from 'path';
|
||||
import { mkdir, writeFile } from 'fs/promises';
|
||||
|
||||
const pull = new Command('pull');
|
||||
|
||||
pull
|
||||
.description('Download artifact')
|
||||
.argument('<artifact-id>', 'Artifact ID')
|
||||
.argument('<file>', 'File to save')
|
||||
.action(async (id, file) => {
|
||||
const context = new Context();
|
||||
const target = resolve(file);
|
||||
const client = await step('Connecting to server', async () => {
|
||||
return createClient(context);
|
||||
});
|
||||
const artifact = await step('Getting artifact', async () => {
|
||||
const result = await client.artifacts.get.query(id);
|
||||
if (!result) {
|
||||
throw new Error('Artifact not found');
|
||||
}
|
||||
return result;
|
||||
});
|
||||
await mkdir(dirname(target), { recursive: true });
|
||||
const data = Buffer.from(artifact.data, 'base64').toString('utf-8');
|
||||
await writeFile(target, data, 'utf-8');
|
||||
});
|
||||
|
||||
export { pull };
|
||||
Reference in New Issue
Block a user