11#!/usr/bin/env node
22
3+ import * as aws from "aws-sdk" ;
34import * as fs from "fs" ;
45import * as readline from "readline" ;
56import * as winston from "winston" ;
@@ -10,8 +11,9 @@ import * as plugins from "../plugins";
1011import { createApi , IOptions } from "./api/api" ;
1112import { TFullApiPost , TPost } from "./api/types" ;
1213import { GetPool } from "./getpool/getPool" ;
14+ import * as depotUpload from "./http/depot" ;
1315import { download , toCSV , toJSON } from "./http/download" ;
14- import * as upload from "./http/upload " ;
16+ import * as s3Upload from "./http/s3 " ;
1517
1618const getLogger = ( args ) => {
1719 const transports = [ ] ;
@@ -217,13 +219,6 @@ function buildParser(args, callback) {
217219 implies : "full" ,
218220 group : "Download" ,
219221 } ,
220- upload : {
221- alias : [ "u" ] ,
222- string : true ,
223- default : undefined ,
224- describe : "Upload files to a URL with a PUT request" ,
225- group : "Download" ,
226- } ,
227222 sync : {
228223 boolean : true ,
229224 default : false ,
@@ -234,7 +229,7 @@ function buildParser(args, callback) {
234229 alias : "k" ,
235230 number : true ,
236231 default : 4 ,
237- describe : "Parallel download / upload threads" ,
232+ describe : "Parallel download / depot threads" ,
238233 group : "Download" ,
239234 } ,
240235 waitDownload : {
@@ -244,6 +239,18 @@ function buildParser(args, callback) {
244239 describe : "Download media after scraping" ,
245240 group : "Download" ,
246241 } ,
242+ bucket : {
243+ string : true ,
244+ default : undefined ,
245+ describe : "Upload files to an AWS S3 bucket" ,
246+ group : "Upload" ,
247+ } ,
248+ depot : {
249+ string : true ,
250+ default : undefined ,
251+ describe : "Upload files to a URL with a PUT request (depot)" ,
252+ group : "Upload" ,
253+ } ,
247254 file : {
248255 alias : [ "o" ] ,
249256 string : true ,
@@ -351,33 +358,48 @@ async function spawn(args) {
351358 . replace ( "[id]" , args [ "id" ] )
352359 . replace ( "[endpoint]" , args [ "_" ] ) ;
353360
354- // Replace upload url
355- let uploadUrl = args [ "upload " ] ;
356- if ( uploadUrl && uploadUrl . includes ( "[uuid]" ) ) {
357- uploadUrl = uploadUrl . replace ( "[uuid]" , uuid ( ) ) ;
361+ // Replace depot url
362+ let depotUrl = args [ "depot " ] ;
363+ if ( depotUrl && depotUrl . includes ( "[uuid]" ) ) {
364+ depotUrl = depotUrl . replace ( "[uuid]" , uuid ( ) ) ;
358365 if ( ! args [ "quiet" ] ) {
359- process . stdout . write ( uploadUrl + "\n" ) ;
366+ process . stdout . write ( depotUrl + "\n" ) ;
360367 }
361368 }
362369
370+ // Get s3 bucket
371+ const s3Bucket = args [ "bucket" ] ;
372+
363373 // Check if outputting to stdout
364374 const printOutput = args [ "file" ] === "-" ;
365375
366376 // Connect to object storage
367377 let downloadUpload ;
368378 let toCSVFunc = toCSV ;
369379 let toJSONFunc = toJSON ;
370- if ( uploadUrl ) {
371- // Upload
372- const uploadConfig = {
380+ if ( depotUrl ) {
381+ // Depot
382+ const depotConfig = {
383+ directory : downdir ,
384+ url : depotUrl ,
385+ logger,
386+ } ;
387+
388+ downloadUpload = depotUpload . depot . bind ( depotConfig ) ;
389+ toCSVFunc = depotUpload . toCSV . bind ( depotConfig ) ;
390+ toJSONFunc = depotUpload . toJSON . bind ( depotConfig ) ;
391+ } else if ( s3Bucket ) {
392+ // s3
393+ const s3Config = {
394+ bucket : s3Bucket ,
373395 directory : downdir ,
374- url : uploadUrl ,
396+ s3 : new aws . S3 ( ) ,
375397 logger,
376398 } ;
377399
378- downloadUpload = upload . upload . bind ( uploadConfig ) ;
379- toCSVFunc = upload . toCSV . bind ( uploadConfig ) ;
380- toJSONFunc = upload . toJSON . bind ( uploadConfig ) ;
400+ downloadUpload = s3Upload . s3 . bind ( s3Config ) ;
401+ toCSVFunc = s3Upload . toCSV . bind ( s3Config ) ;
402+ toJSONFunc = s3Upload . toJSON . bind ( s3Config ) ;
381403 } else {
382404 // Download
383405 downloadUpload = download . bind ( {
0 commit comments