Selaa lähdekoodia

add Void support, various cleanups

master
Milan Pässler 1 vuosi sitten
vanhempi
commit
78c76e1ad6
10 muutettua tiedostoa jossa 164 lisäystä ja 49 poistoa
  1. +32
    -28
      server/alpine.js
  2. +3
    -5
      server/archlinux.js
  3. +0
    -10
      server/error.js
  4. +3
    -2
      server/index.js
  5. +1
    -1
      server/nixpkgs.js
  6. +2
    -2
      server/openwrt.js
  7. +2
    -1
      server/package.json
  8. +36
    -0
      server/util.js
  9. +61
    -0
      server/void.js
  10. +24
    -0
      server/yarn.lock

+ 32
- 28
server/alpine.js Näytä tiedosto

@@ -2,7 +2,9 @@

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

const urls = [
"http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz",
@@ -28,38 +30,40 @@ const getPackageLists = async () => {

for (let url of urls) {
console.log(`fetching ${url}`);
const packageList = await fetch(url)
.then(resp => {
const child = spawn("tar", ["-xOzf-", "APKINDEX"]);
resp.body.pipe(child.stdin);

return new Promise((fulfill, reject) => {
let res = "";
child.stdout.on('data', chunk => res+=String(chunk));
child.stdout.on('end', () => {
fulfill(res)
});
});
});
const { body } = await fetch(url);
const child = spawn("tar", ["-xOzf-", "APKINDEX"]);
const collector = new Collector();

await Promise.all([
pipeline(
body,
child.stdin,
),
pipeline(
child.stdout,
collector,
),
]).catch(console.error);

const packageList = collector.result;
packageList.split("\n\n")
.forEach(pkg => {
const p = {
deps: getKey(pkg, "D").split(" ").map(dep => stripVersion(dep)),
name: getKey(pkg, "P") + getKey(pkg, "V"),
id: getKey(pkg, "P"),
size: getKey(pkg, "I"),
};
newPackages[getKey(pkg, "P")] = p;
for (let name of getKey(pkg, "p").split(" ")) {
newPackages[stripVersion(name)] = p;
}
});
packageList.split("\n\n").forEach(pkg => {
const p = {
deps: getKey(pkg, "D").split(" ").map(dep => stripVersion(dep)),
name: getKey(pkg, "P") + getKey(pkg, "V"),
id: getKey(pkg, "P"),
size: getKey(pkg, "I"),
};
newPackages[getKey(pkg, "P")] = p;
for (let name of getKey(pkg, "p").split(" ")) {
newPackages[stripVersion(name)] = p;
}
});
}

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

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


+ 3
- 5
server/archlinux.js Näytä tiedosto

@@ -1,8 +1,8 @@
"use strict";

const fetch = require("node-fetch");
const HTTPError = require("./error");
const { HTTPError } = require("./util");
const { stripVersion } = require("./util");
let packages = {};

const urls = [
@@ -12,8 +12,6 @@ const urls = [
"http://ftp-stud.hs-esslingen.de/pub/Mirrors/archlinux/multilib/os/x86_64/multilib.db",
];

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

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

@@ -56,7 +54,7 @@ const getPackageLists = async () => {
}

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

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


+ 0
- 10
server/error.js Näytä tiedosto

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

const HTTPError = function(code, msg) {
this.code = code;
this.msg = msg;
};

HTTPError.prototype = Error;

module.exports = HTTPError;

+ 3
- 2
server/index.js Näytä tiedosto

@@ -3,20 +3,21 @@
const http = require("http");
const url = require("url");
const fetch = require("node-fetch");
const HTTPError = require("./error");
const { HTTPError } = require("./util");

const backends = {
NixOS: require("./nixpkgs"),
OpenWRT: require("./openwrt"),
ArchLinux: require("./archlinux"),
Alpine: require("./alpine"),
Void: require("./void"),
};

const addNode = async (graph, backend, node) => {
if (!graph.nodes[node.id]) {
graph.nodes[node.id] = {
...node,
deps: undefined,
//deps: undefined,
}

graph.details.count++;


+ 1
- 1
server/nixpkgs.js Näytä tiedosto

@@ -3,7 +3,7 @@
const { promisify } = require("util");
const execFile = promisify(require("child_process").execFile);
const fetch = require("node-fetch");
const HTTPError = require("./error");
const { HTTPError } = require("./util");

let narinfoCache = {};



+ 2
- 2
server/openwrt.js Näytä tiedosto

@@ -2,7 +2,7 @@

const fetch = require("node-fetch");
const InternetMessage = require("internet-message");
const HTTPError = require("./error");
const { HTTPError } = require("./util");

let packages = {};

@@ -40,7 +40,7 @@ const getPackageLists = async () => {
}

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

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


+ 2
- 1
server/package.json Näytä tiedosto

@@ -6,6 +6,7 @@
"bin": "index.js",
"dependencies": {
"internet-message": "^1.0.0",
"node-fetch": "^2.3.0"
"node-fetch": "^2.3.0",
"plist": "^3.0.1"
}
}

+ 36
- 0
server/util.js Näytä tiedosto

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

const { Writable } = require("stream");

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

class Collector extends Writable {
constructor() {
super();
this.result = "";
}

_write(chunk, enc, next) {
this.result += String(chunk);
next();
}
}

class HTTPError extends Error {
constructor(code, msg) {
super();
this.code = code;
this.msg = msg;
}
};

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

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

+ 61
- 0
server/void.js Näytä tiedosto

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

const { createGunzip } = require("zlib");
const { HTTPError, Collector } = 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",
"https://alpha.de.repo.voidlinux.org/current/nonfree/x86_64-repodata",
"https://alpha.de.repo.voidlinux.org/current/debug/x86_64-repodata",
];

let packages = {};

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 = plist.parse(collector.result);
Object.keys(packageList).forEach(name => {
const pkg = packageList[name];
const p = {
name,
deps: (pkg["run_depends"] || []).map(stripVersion),
id: pkg["pkgver"],
size: pkg["installed_size"],
};
newPackages[name] = p;
//newPackages[pkg["pkgver"]] = p;
});
}

packages = newPackages;
console.log("Void 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;

+ 24
- 0
server/yarn.lock Näytä tiedosto

@@ -2,6 +2,11 @@
# yarn lockfile v1


base64-js@^1.2.3:
version "1.3.0"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.0.tgz#cab1e6118f051095e58b5281aea8c1cd22bfc0e3"
integrity sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==

internet-message@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/internet-message/-/internet-message-1.0.0.tgz#28f65368a22a6207994c6e21f0e3bffbf1278d2b"
@@ -11,3 +16,22 @@ node-fetch@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.3.0.tgz#1a1d940bbfb916a1d3e0219f037e89e71f8c5fa5"
integrity sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA==

plist@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.1.tgz#a9b931d17c304e8912ef0ba3bdd6182baf2e1f8c"
integrity sha512-GpgvHHocGRyQm74b6FWEZZVRroHKE1I0/BTjAmySaohK+cUn+hZpbqXkc3KWgW3gQYkqcQej35FohcT0FRlkRQ==
dependencies:
base64-js "^1.2.3"
xmlbuilder "^9.0.7"
xmldom "0.1.x"

xmlbuilder@^9.0.7:
version "9.0.7"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-9.0.7.tgz#132ee63d2ec5565c557e20f4c22df9aca686b10d"
integrity sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=

xmldom@0.1.x:
version "0.1.27"
resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.1.27.tgz#d501f97b3bdb403af8ef9ecc20573187aadac0e9"
integrity sha1-1QH5ezvbQDr4757MIFcxh6rawOk=

Ladataan…
Peruuta
Tallenna