@secret-momo/utils 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/download/index.js +1 -1
- package/package.json +1 -1
package/lib/download/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{mkdirSync as i,createWriteStream as
|
|
1
|
+
import{mkdirSync as i,createWriteStream as m}from"node:fs";import{join as a}from"node:path";import{Readable as s}from"node:stream";import{pipeline as c}from"node:stream/promises";import d from"consola";import{fetch as p}from"../fetch.js";import{dateTimeToNow as f}from"../date-time.js";import{pickImageExtension as y,pickVideoExtension as u}from"./extension.js";async function w({url:r,dir:e}){try{i(e,{recursive:!0});const o=await p(r);if(!o.body)throw new Error("Response has no body");const n=u(r,o.headers.get("content-type")),t=a(e,`${f("YYYYMMDD_HHmmss")}.${n}`);return await c(s.fromWeb(o.body),m(t)),t}catch(o){return d.error(o),null}}async function l({url:r,dir:e}){try{i(e,{recursive:!0});const o=await p(r);if(!o.body)throw new Error("Response has no body");const n=y(r,o.headers.get("content-type")),t=a(e,`${f("YYYYMMDD_HHmmss")}.${n}`);return await c(s.fromWeb(o.body),m(t)),t}catch(o){return d.error(o),null}}export{l as downloadImage,w as downloadVideo};
|