UNPKG

@onboardbase/cli

Version:

[![Version](https://img.shields.io/npm/v/@onboardbase/cli.svg)](https://www.npmjs.com/package/@onboardbase/cli) [![Downloads/week](https://img.shields.io/npm/dw/@onboardbase/cli.svg)](https://www.npmjs.com/package/@onboardbase/cli) [![License](https://img

122 lines (121 loc) 4.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getObbPublicKey = exports.createQuickShare = exports.getFileDownloadPresignedURL = exports.uploadFileToPresignedURL = exports.getPresignedURL = void 0; const chalk = require("chalk"); const axios_1 = require("axios"); const config_1 = require("../configuration/config"); const getPresignedURL = async ({ fileName, fileType, expiresIn, bucket, endpoint, region, }) => { var _a, _b; const instance = config_1.default.getHttpInstance(); const query = ` mutation { generatePresignedURL(uploadInput: {key: "${fileName}", endpoint: "${endpoint}", region: "${region}", fileType: "${fileType}", bucket: "${bucket}", expiresIn: ${expiresIn}}) } `; try { const { data } = await instance.post("", { query }); if (data.errors) { console.log(chalk.bold.red(data === null || data === void 0 ? void 0 : data.errors[0].message)); process.exit(0); } return data.data.generatePresignedURL; } catch (error) { console.log(chalk.bold.red((_b = (_a = error.response.data) === null || _a === void 0 ? void 0 : _a.errors) === null || _b === void 0 ? void 0 : _b[0].message)); process.exit(1); } }; exports.getPresignedURL = getPresignedURL; const uploadFileToPresignedURL = async ({ file, fileType, url, }) => { try { const res = await axios_1.default.put(url, file, { headers: { // ...formHeaders "Content-Type": fileType, }, }); } catch (err) { console.log(err.response.data); process.exit(1); } }; exports.uploadFileToPresignedURL = uploadFileToPresignedURL; const getFileDownloadPresignedURL = async ({ fileName, fileType, expiresIn, bucket, endpoint, region, }) => { var _a, _b; const instance = config_1.default.getHttpInstance(); const query = ` query { getFilePresignedURL(uploadInput: {key: "${fileName}", endpoint: "${endpoint}", region: "${region}", fileType: "${fileType}", bucket: "${bucket}", expiresIn: ${expiresIn}}) } `; try { const { data } = await instance.post("", { query }); if (data === null || data === void 0 ? void 0 : data.errors) { console.log(chalk.bold.red(data === null || data === void 0 ? void 0 : data.errors[0].message)); process.exit(0); } return data.data.getFilePresignedURL; } catch (error) { console.log(chalk.bold.red((_b = (_a = error.response.data) === null || _a === void 0 ? void 0 : _a.errors) === null || _b === void 0 ? void 0 : _b[0].message)); process.exit(1); } }; exports.getFileDownloadPresignedURL = getFileDownloadPresignedURL; const createQuickShare = async (input) => { var _a, _b; const instance = config_1.default.getHttpInstance(); const query = ` mutation createQuickShare($quickShareInput: QuickShareInput!) { createQuickShare(quickShareInput: $quickShareInput) { id publicKey message filePath expiredDate } } `; try { const { data } = await instance.post("", { query, variables: { quickShareInput: input }, }); if (data.errors) { console.log(chalk.bold.red(data === null || data === void 0 ? void 0 : data.errors[0].message)); process.exit(0); } return data.data.createQuickShare; } catch (error) { console.log(chalk.bold.red((_b = (_a = error.response.data) === null || _a === void 0 ? void 0 : _a.errors) === null || _b === void 0 ? void 0 : _b[0].message)); process.exit(1); } }; exports.createQuickShare = createQuickShare; const getObbPublicKey = async () => { var _a, _b; const instance = config_1.default.getHttpInstance(); const query = ` mutation getPublicKey { getPublicKey { id publicKey } } `; try { const { data } = await instance.post("", { query }); if (data === null || data === void 0 ? void 0 : data.errors) { console.log(chalk.bold.red(data.errors[0].message)); process.exit(0); } return data.data.getPublicKey; } catch (error) { console.log(chalk.bold.red((_b = (_a = error.response.data) === null || _a === void 0 ? void 0 : _a.errors) === null || _b === void 0 ? void 0 : _b[0].message)); process.exit(1); } }; exports.getObbPublicKey = getObbPublicKey;