Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

img-dl

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

img-dl - npm Package Compare versions

Comparing version 0.7.2 to 0.7.3

10

dist/cli.js
#!/usr/bin/env node
import{a as r,b,c as w}from"./chunk-HVSPWQG2.js";import x from"cli-progress";import y from"meow";import $ from"fs";import v from"path";import p from"chalk";var d=y(`
import{a as i,b,c as w}from"./chunk-HVSPWQG2.js";import x from"cli-progress";import y from"meow";import $ from"fs";import v from"path";import p from"chalk";var d=y(`
USAGE

@@ -34,8 +34,8 @@ $ imgdl <url> ... [OPTIONS]

$ imgdl https://example.com/image.jpg --header="User-Agent: Mozilla/5.0" --header="Cookie: foo=bar"
`,{importMeta:import.meta,booleanDefault:void 0,flags:{dir:{shortFlag:"d",type:"string"},ext:{shortFlag:"e",type:"string"},header:{shortFlag:"H",type:"string",isMultiple:!0},increment:{shortFlag:"i",type:"boolean"},interval:{type:"number"},start:{type:"number"},end:{type:"number"},name:{shortFlag:"n",type:"string"},maxRetry:{type:"number"},silent:{type:"boolean"},step:{type:"number"},timeout:{shortFlag:"t",type:"number"},version:{shortFlag:"v",type:"boolean"}}}),S=p.bold.green,c=p.bold.red,T=p.yellow,m=p.dim;async function D(){let t=d.input,{flags:e}=d;if(e.version&&d.showVersion(),t.length||d.showHelp(0),e.increment){if(t.length>1)throw new r("Only one URL is allowed in increment mode");let l=t[0];if(!l.includes("{i}"))throw new r("The URL must contain {i} placeholder for the index");if(!e.end)throw new r("The end index is required in increment mode");if(e.start&&e.start>e.end)throw new r("The start index cannot be greater than the end index");let{start:a=0,end:n}=e;t=[];for(let o=a;o<=n;o+=1)t.push(l.replace("{i}",o.toString()))}e.silent||console.log(`
`,{importMeta:import.meta,booleanDefault:void 0,flags:{dir:{shortFlag:"d",type:"string"},ext:{shortFlag:"e",type:"string"},header:{shortFlag:"H",type:"string",isMultiple:!0},increment:{shortFlag:"i",type:"boolean"},interval:{type:"number"},start:{type:"number"},end:{type:"number"},name:{shortFlag:"n",type:"string"},maxRetry:{type:"number"},silent:{type:"boolean"},step:{type:"number"},timeout:{shortFlag:"t",type:"number"},version:{shortFlag:"v",type:"boolean"}}}),S=p.bold.green,c=p.bold.red,T=p.yellow,m=p.dim;async function D(){let t=d.input,{flags:e}=d;if(e.version&&d.showVersion(),t.length||d.showHelp(0),e.increment){if(t.length>1)throw new i("Only one URL is allowed in increment mode");let s=t[0];if(!s.includes("{i}"))throw new i("The URL must contain {i} placeholder for the index");if(!e.end)throw new i("The end index is required in increment mode");if(e.start&&e.start>e.end)throw new i("The start index cannot be greater than the end index");let{start:o=0,end:n}=e;t=[];for(let r=o;r<=n;r+=1)t.push(s.replace("{i}",r.toString()))}e.silent||console.log(`
${m("Downloading...")}
${T("Press Ctrl+C to abort")}`);let h=m("|"),s=new x.SingleBar({format:`{percentage}% [{bar}] {value}/{total} ${h} ${S("\u2705 {success}")} ${h} ${c("\u274C {errorCount}")} ${h} ETA: {eta_formatted} ${m("/ {duration_formatted}")}`,hideCursor:null,barsize:24}),g=0,i=0;!e.silent&&t.length>1&&s.start(t.length,0,{success:g,errorCount:i});let u={};e.header&&e.header.forEach(l=>{let[a,n]=l.split(":").map(o=>o.trim());if(!a||!n)throw new r("Invalid header format");u[a]=n});let f=new AbortController;process.on("SIGINT",()=>{s.stop(),console.log(m(`
Aborting...`)),f.abort()}),await new Promise((l,a)=>{w(t,{directory:e.dir,name:e.name,extension:e.ext,headers:u,interval:e.interval,onSuccess:()=>{g+=1,e.silent||s.increment({success:g})},onError:(n,o)=>{if(i+=1,e.silent||s.increment({errorCount:i}),n instanceof r||n instanceof b)return a(n);$.appendFileSync(v.resolve(e.dir||process.cwd(),"error.log"),`${new Date().toISOString()} failed download from ${o}, ${n.name}: ${n.message}
`)},maxRetry:e.maxRetry,step:e.step,timeout:e.timeout,signal:f.signal})}),e.silent||(s.stop(),console.log(m("Done!")),i&&console.log(c(`${i} image${i>1?"s":""} failed to download. See error.log for details.`)))}D().catch(t=>{console.error(c(`
${T("Press Ctrl+C to abort")}`);let h=m("|"),l=new x.SingleBar({format:`{percentage}% [{bar}] {value}/{total} ${h} ${S("\u2705 {success}")} ${h} ${c("\u274C {errorCount}")} ${h} ETA: {eta_formatted} ${m("/ {duration_formatted}")}`,hideCursor:null,barsize:24}),g=0,a=0;!e.silent&&t.length>1&&l.start(t.length,0,{success:g,errorCount:a});let u={};e.header&&e.header.forEach(s=>{let[o,n]=s.split(":").map(r=>r.trim());if(!o||!n)throw new i("Invalid header format");u[o]=n});let f=new AbortController;process.on("SIGINT",()=>{l.stop(),console.log(m(`
Aborting...`)),f.abort()}),await new Promise((s,o)=>{w(t,{directory:e.dir,name:e.name,extension:e.ext,headers:u,interval:e.interval,onSuccess:()=>{g+=1,e.silent||l.increment({success:g})},onError:(n,r)=>{if(a+=1,e.silent||l.increment({errorCount:a}),n instanceof i||n instanceof b)return o(n);$.appendFileSync(v.resolve(e.dir||process.cwd(),"error.log"),`${new Date().toISOString()} failed download from ${r}, ${n.name}: ${n.message}
`)},maxRetry:e.maxRetry,step:e.step,timeout:e.timeout,signal:f.signal}).then(s,o)}),e.silent||(l.stop(),console.log(m("Done!")),a&&console.log(c(`${a} image${a>1?"s":""} failed to download. See error.log for details.`)))}D().catch(t=>{console.error(c(`
${t.name}: ${t.message}`))});
//# sourceMappingURL=cli.js.map
{
"name": "img-dl",
"version": "0.7.2",
"version": "0.7.3",
"description": "Download image(s), by command or programmatically",

@@ -5,0 +5,0 @@ "type": "module",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc