UNPKG

lesgo

Version:

Core framework for lesgo node.js serverless framework.

59 lines (58 loc) 1.8 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator['throw'](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { GetObjectCommand } from '@aws-sdk/client-s3'; import { getSignedUrl } from '@aws-sdk/s3-request-presigner'; import s3Config from '../../config/s3'; import { validateFields } from '../../utils'; import getClient from './getClient'; const getDownloadSignedUrl = (key, opts, signingOpts, clientOpts) => __awaiter(void 0, void 0, void 0, function* () { const input = validateFields({ key }, [ { key: 'key', type: 'string', required: true }, ]); const client = getClient(clientOpts); const commandInput = Object.assign( { Bucket: (opts === null || opts === void 0 ? void 0 : opts.Bucket) || s3Config.bucket, Key: input.key, }, opts ); const command = new GetObjectCommand(commandInput); signingOpts = Object.assign({ expiresIn: 3600 }, signingOpts); return getSignedUrl(client, command, signingOpts); }); export default getDownloadSignedUrl;