Browse Source

debian support, server cleanups

master
Milan Pässler 6 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 @@

const { spawn } = require("child_process");
const fetch = require("node-fetch");
const { HTTPError, Collector, streamEnd } = require("./util");
const { HTTPError, Collector, stripVersion } = require("./util");
const { promisify } = require("util");
const pipeline = promisify(require("stream").pipeline);

@@ -15,8 +15,6 @@ const urls = [

let packages = {};

const stripVersion = (s) => s.split(/[<>]?=.*/)[0];

const getKey = (text, key) => {
let res = "";
text.split("\n").forEach(line => {

+ 67
- 0
server/debian.js View File

@@ -0,0 +1,67 @@
"use strict";

const fetch = require("node-fetch");
const InternetMessage = require("internet-message");
const { HTTPError, Collector } = require("./util");
const { createGunzip } = require("zlib");
const { promisify } = require("util");
const pipeline = promisify(require("stream").pipeline);

let packages = {};

const urls = [
"http://ftp.de.debian.org/debian/dists/testing/main/binary-amd64/Packages.gz",
"http://ftp.de.debian.org/debian/dists/testing/contrib/binary-amd64/Packages.gz",
// "http://ftp.de.debian.org/debian/dists/testing/nonfree/binary-amd64/Packages.gz",
];

const getPackageLists = async () => {
const newPackages = {};

for (let url of urls) {
console.log(`fetching ${url}`);

const { body } = await fetch(url);
const collector = new Collector();
await pipeline(
body,
createGunzip(),
collector,
);
const packageList = collector.result;

packageList.split("\n\n")
.forEach(pkg => {
let attrs = InternetMessage.parse(pkg + "\n")
if (attrs.package) {
attrs.depends = (attrs.depends || "").split(", ").map(dep => dep.split(" (")[0]);
attrs.provides = (attrs.provides || "").split(", ").map(dep => dep.split(" (")[0]);
const p = {
deps: attrs.depends,
name: `${attrs.package}-${attrs.version}`,
id: attrs.package,
size: Number(attrs["installed-size"]) * 1000,
};
newPackages[attrs.package] = p;
for (let name of attrs.provides) {
newPackages[name] = p;
}
}
});
}

packages = newPackages;
console.log("Debian packages loaded");
}

setInterval(getPackageLists, 24 * 60 * 60 * 1000); // 24 hours
getPackageLists();

const getNode = async (type, name) => {
if (!packages[name]) {
throw new HTTPError(404, "Failed to get package info");
}
return packages[name];
};

module.exports = getNode;

+ 2
- 1
server/index.js View File

@@ -11,6 +11,7 @@ const backends = {
ArchLinux: require("./archlinux"),
Alpine: require("./alpine"),
Void: require("./void"),
Debian: require("./debian"),
};

const addNode = async (graph, backend, node) => {
@@ -66,7 +67,7 @@ http.createServer(async (req, stream) => {
if (parameters.length === 2 && parameters[1] === "backends") {
res = Object.keys(backends);
} else {
throw new HTTPError(404, "Invalid URI");
throw new HTTPError(404, "Invalid URI");
}
} else {
const backend = backends[parameters[1]];

+ 1
- 1
server/openwrt.js View File

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

+ 0
- 5
server/util.js View File

@@ -24,13 +24,8 @@ class HTTPError extends Error {
}
};

const streamEnd = (stream) => new Promise((fulfill, reject) => {
stream.on("end", fulfill);
});

module.exports = {
stripVersion,
Collector,
HTTPError,
streamEnd,
};

+ 1
- 2
server/void.js View File

@@ -1,12 +1,11 @@
"use strict";

const { createGunzip } = require("zlib");
const { HTTPError, Collector } = require("./util");
const { HTTPError, Collector, stripVersion } = require("./util");
const fetch = require("node-fetch");
const plist = require('plist');
const { promisify } = require("util");
const pipeline = promisify(require("stream").pipeline);
const { stripVersion } = require("./util");

const urls = [
"https://alpha.de.repo.voidlinux.org/current/x86_64-repodata",

Loading…
Cancel
Save