Browse Source

debian support, server cleanups

master
Milan Pässler 2 months ago
parent
commit
67866120e9
6 changed files with 72 additions and 12 deletions
  1. 1
    3
      server/alpine.js
  2. 67
    0
      server/debian.js
  3. 2
    1
      server/index.js
  4. 1
    1
      server/openwrt.js
  5. 0
    5
      server/util.js
  6. 1
    2
      server/void.js

+ 1
- 3
server/alpine.js View File

@@ -2,7 +2,7 @@
2 2
 
3 3
 const { spawn } = require("child_process");
4 4
 const fetch = require("node-fetch");
5
-const { HTTPError, Collector, streamEnd } = require("./util");
5
+const { HTTPError, Collector, stripVersion } = require("./util");
6 6
 const { promisify } = require("util");
7 7
 const pipeline = promisify(require("stream").pipeline);
8 8
 
@@ -15,8 +15,6 @@ const urls = [
15 15
 
16 16
 let packages = {};
17 17
 
18
-const stripVersion = (s) => s.split(/[<>]?=.*/)[0];
19
-
20 18
 const getKey = (text, key) => {
21 19
   let res = "";
22 20
   text.split("\n").forEach(line => {

+ 67
- 0
server/debian.js View File

@@ -0,0 +1,67 @@
1
+"use strict";
2
+
3
+const fetch = require("node-fetch");
4
+const InternetMessage = require("internet-message");
5
+const { HTTPError, Collector } = require("./util");
6
+const { createGunzip } = require("zlib");
7
+const { promisify } = require("util");
8
+const pipeline = promisify(require("stream").pipeline);
9
+
10
+let packages = {};
11
+
12
+const urls = [
13
+  "http://ftp.de.debian.org/debian/dists/testing/main/binary-amd64/Packages.gz",
14
+  "http://ftp.de.debian.org/debian/dists/testing/contrib/binary-amd64/Packages.gz",
15
+ // "http://ftp.de.debian.org/debian/dists/testing/nonfree/binary-amd64/Packages.gz",
16
+];
17
+
18
+const getPackageLists = async () => {
19
+  const newPackages = {};
20
+
21
+  for (let url of urls) {
22
+    console.log(`fetching ${url}`);
23
+
24
+    const { body } = await fetch(url);
25
+    const collector = new Collector();
26
+    await pipeline(
27
+      body,
28
+      createGunzip(),
29
+      collector,
30
+    );
31
+    const packageList = collector.result;
32
+
33
+    packageList.split("\n\n")
34
+      .forEach(pkg => {
35
+        let attrs = InternetMessage.parse(pkg + "\n")
36
+        if (attrs.package) {
37
+          attrs.depends = (attrs.depends || "").split(", ").map(dep => dep.split(" (")[0]);
38
+          attrs.provides = (attrs.provides || "").split(", ").map(dep => dep.split(" (")[0]);
39
+          const p = {
40
+            deps: attrs.depends,
41
+            name: `${attrs.package}-${attrs.version}`,
42
+            id: attrs.package,
43
+            size: Number(attrs["installed-size"]) * 1000,
44
+          };
45
+          newPackages[attrs.package] = p;
46
+          for (let name of attrs.provides) {
47
+            newPackages[name] = p;
48
+          }
49
+        }
50
+      });
51
+  }
52
+
53
+  packages = newPackages;
54
+  console.log("Debian packages loaded");
55
+}
56
+
57
+setInterval(getPackageLists, 24 * 60 * 60 * 1000); // 24 hours
58
+getPackageLists();
59
+
60
+const getNode = async (type, name) => {
61
+  if (!packages[name]) {
62
+    throw new HTTPError(404, "Failed to get package info");
63
+  }
64
+  return packages[name];
65
+};
66
+
67
+module.exports = getNode;

+ 2
- 1
server/index.js View File

@@ -11,6 +11,7 @@ const backends = {
11 11
   ArchLinux: require("./archlinux"),
12 12
   Alpine: require("./alpine"),
13 13
   Void: require("./void"),
14
+  Debian: require("./debian"),
14 15
 };
15 16
 
16 17
 const addNode = async (graph, backend, node) => {
@@ -66,7 +67,7 @@ http.createServer(async (req, stream) => {
66 67
       if (parameters.length === 2 && parameters[1] === "backends") {
67 68
         res = Object.keys(backends);
68 69
       } else {
69
-      	throw new HTTPError(404, "Invalid URI");
70
+        throw new HTTPError(404, "Invalid URI");
70 71
       }
71 72
     } else {
72 73
       const backend = backends[parameters[1]];

+ 1
- 1
server/openwrt.js View File

@@ -33,7 +33,7 @@ const getPackageLists = async () => {
33 33
             deps: attrs.depends,
34 34
             name: attrs.package,
35 35
             id: attrs.package,
36
-            size: Number(attrs["installed-size"])
36
+            size: Number(attrs["installed-size"]),
37 37
           };
38 38
         }
39 39
       });

+ 0
- 5
server/util.js View File

@@ -24,13 +24,8 @@ class HTTPError extends Error {
24 24
   }
25 25
 };
26 26
 
27
-const streamEnd = (stream) => new Promise((fulfill, reject) => {
28
-  stream.on("end", fulfill);
29
-});
30
-
31 27
 module.exports = {
32 28
   stripVersion,
33 29
   Collector,
34 30
   HTTPError,
35
-  streamEnd,
36 31
 };

+ 1
- 2
server/void.js View File

@@ -1,12 +1,11 @@
1 1
 "use strict";
2 2
 
3 3
 const { createGunzip } = require("zlib");
4
-const { HTTPError, Collector } = require("./util");
4
+const { HTTPError, Collector, stripVersion } = require("./util");
5 5
 const fetch = require("node-fetch");
6 6
 const plist = require('plist');
7 7
 const { promisify } = require("util");
8 8
 const pipeline = promisify(require("stream").pipeline);
9
-const { stripVersion } = require("./util");
10 9
 
11 10
 const urls = [
12 11
   "https://alpha.de.repo.voidlinux.org/current/x86_64-repodata",

Loading…
Cancel
Save