UNPKG

balena-cli

Version:

The official balena Command Line Interface

87 lines (86 loc) 3.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const lazy_1 = require("../../utils/lazy"); const release_1 = require("../release"); const fs = require("fs/promises"); const path = require("path"); class ReleaseAssetUploadCmd extends core_1.Command { async run() { const { args, flags } = await this.parse(ReleaseAssetUploadCmd); const balena = (0, lazy_1.getBalenaSdk)(); try { await fs.access(args.filePath); } catch (error) { console.error(error); throw new Error(`File not found: ${args.filePath}`); } const { getRelease } = await Promise.resolve().then(() => require('../../utils/sdk')); const release = await getRelease(args.commitOrId, { $select: ['id'], }); const absolutePath = path.resolve(args.filePath); const visuals = (0, lazy_1.getVisuals)(); const bar = new visuals.Progress(`Uploading release asset '${flags.key}'`); const releaseAsset = await balena.models.release.asset.upload({ release: release.id, asset_key: flags.key, asset: absolutePath, }, { chunkSize: flags['chunk-size'], parallelUploads: flags['parallel-chunks'], overwrite: flags.overwrite, onUploadProgress: (progress) => { if (progress.total > 0) { const percentage = (progress.uploaded / progress.total) * 100; bar.update({ percentage, eta: null }); } }, }); console.log(`Release asset '${flags.key}' uploaded successfully`); console.log(`Release Asset ID: ${releaseAsset.id}`); } } ReleaseAssetUploadCmd.description = (0, lazy_1.stripIndent) ` Upload a release asset. Upload a file as a release asset with the specified key. If the asset already exists, you can use the --overwrite flag to replace it. You can customize the upload behavior with --chunk-size and --parallel-chunks options for larger files. `; ReleaseAssetUploadCmd.examples = [ '$ balena release-asset upload 1234567 ./path/to/config.json --key config.json', '$ balena release-asset upload a777f7345fe3d655c1c981aa642e5555 ./app.tar.gz --key app.tar.gz --overwrite', '$ balena release-asset upload 1234567 ./file.bin --key large-file.bin --chunk-size 10485760 --parallel-chunks 10', ]; ReleaseAssetUploadCmd.args = { commitOrId: (0, release_1.commitOrIdArg)({ description: 'the commit or ID of the release', required: true, }), filePath: core_1.Args.string({ description: 'path to the file to upload', required: true, }), }; ReleaseAssetUploadCmd.flags = { key: core_1.Flags.string({ description: 'the key for the release asset', required: true, }), overwrite: core_1.Flags.boolean({ description: 'overwrite the asset if it already exists', default: false, }), 'chunk-size': core_1.Flags.integer({ description: 'chunk size in bytes for multipart upload (minimum 5MB)', default: 5 * 1024 * 1024, }), 'parallel-chunks': core_1.Flags.integer({ description: 'number of chunks to upload in parallel', default: 5, }), }; ReleaseAssetUploadCmd.authenticated = true; exports.default = ReleaseAssetUploadCmd; //# sourceMappingURL=upload.js.map