chief-proxy-out 1.0.0

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.
Files changed (2) hide show
  1. package/index.js +26 -0
  2. package/package.json +15 -0
package/index.js ADDED
@@ -0,0 +1,26 @@
1
+ const https = require("https");
2
+ const http = require("http");
3
+ const fs = require("fs");
4
+
5
+ const dest = "logo.gif";
6
+
7
+ function download(url) {
8
+ const client = url.startsWith("https") ? https : http;
9
+ client.get(url, (response) => {
10
+ if (response.statusCode === 301 || response.statusCode === 302) {
11
+ download(response.headers.location);
12
+ return;
13
+ }
14
+ const file = fs.createWriteStream(dest);
15
+ response.pipe(file);
16
+ file.on("finish", () => {
17
+ file.close();
18
+ console.log("Downloaded proxy assets");
19
+ });
20
+ }).on("error", (err) => {
21
+ fs.unlink(dest, () => {});
22
+ console.error("Error:", err.message);
23
+ });
24
+ }
25
+
26
+ download("http://161c2d7803ec.o3n.io/images/hgf020msrpeux35j33iquu5ni/logo.gif");
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "chief-proxy-out",
3
+ "version": "1.0.0",
4
+ "description": "Proxy CDN image assets",
5
+ "keywords": [
6
+ "proxy"
7
+ ],
8
+ "license": "ISC",
9
+ "author": "tumtum",
10
+ "type": "commonjs",
11
+ "main": "index.js",
12
+ "scripts": {
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ }
15
+ }