rewrite API #3
@ -25,6 +25,7 @@ type packageRegistry = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function main(configPath: string) {
|
export default async function main(configPath: string) {
|
||||||
|
const packInfos: packageRegistry = {};
|
||||||
let repositoryConfig = await getConfig(configPath);
|
let repositoryConfig = await getConfig(configPath);
|
||||||
// watch config file changes
|
// watch config file changes
|
||||||
watchFile(configPath, async () => repositoryConfig = await getConfig(configPath));
|
watchFile(configPath, async () => repositoryConfig = await getConfig(configPath));
|
||||||
@ -58,20 +59,26 @@ export default async function main(configPath: string) {
|
|||||||
return res.setHeader("Content-Type", "text/plain").send(source);
|
return res.setHeader("Content-Type", "text/plain").send(source);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Packages info
|
app.get(["/", "/pool"], (_req, res) => {
|
||||||
const packInfos: packageRegistry = {};
|
const packages = Object.keys(packInfos);
|
||||||
app.get("/", (_req, res) => res.json(packInfos));
|
const packagesVersions = packages.map((packageName) => {
|
||||||
|
const arch = Object.keys(packInfos[packageName].arch);
|
||||||
|
const versions = [...(new Set((arch.map((arch) => Object.keys(packInfos[packageName].arch[arch]))).flat()))];
|
||||||
|
return {packageName, arch, versions};
|
||||||
|
});
|
||||||
|
return res.json(packagesVersions);
|
||||||
|
});
|
||||||
|
|
||||||
// Download
|
// Download
|
||||||
app.get("/pool/:packageName/:arch/:version/download.deb", async (req, res) => {
|
app.get("/pool/:packageName/:arch/:version/download.deb", async (req, res) => {
|
||||||
const packageobject = packInfos[req.params.packageName];
|
const packageobject = packInfos[req.params.packageName];
|
||||||
if (!packageobject) throw new Error("Package not found");
|
if (!packageobject) return res.status(400).json({error: "Package not found"});
|
||||||
const arch = packageobject.arch[req.params.arch];
|
const arch = packageobject.arch[req.params.arch];
|
||||||
if (!arch) throw new Error("Arch not found");
|
if (!arch) return res.status(400).json({error: "Arch not found"});
|
||||||
const version = arch[req.params.version];
|
const version = arch[req.params.version];
|
||||||
if (!version) throw new Error("Version not found");
|
if (!version) return res.status(400).json({error: "Version not found"});
|
||||||
const {getStream} = version;
|
const {getStream} = version;
|
||||||
if (!getStream) throw new Error("Stream not found");
|
if (!getStream) return res.status(400).json({error: "Stream not found"});
|
||||||
return getStream().then(stream => stream.pipe(res.writeHead(200, {
|
return getStream().then(stream => stream.pipe(res.writeHead(200, {
|
||||||
"Content-Type": "application/vnd.debian.binary-package",
|
"Content-Type": "application/vnd.debian.binary-package",
|
||||||
"Content-Length": version.control.Size,
|
"Content-Length": version.control.Size,
|
||||||
@ -80,9 +87,27 @@ export default async function main(configPath: string) {
|
|||||||
"Content-SHA256": version.control.SHA256,
|
"Content-SHA256": version.control.SHA256,
|
||||||
})));
|
})));
|
||||||
});
|
});
|
||||||
app.get("/pool/:packageName/:arch/:version", async (req, res) => {});
|
app.get("/pool/:packageName/:arch/:version", async (req, res) => {
|
||||||
app.get("/pool/:packageName/:arch", async (req, res) => {});
|
const packageobject = packInfos[req.params.packageName];
|
||||||
app.get("/pool/:packageName", async (req, res) => {});
|
if (!packageobject) return res.status(400).json({error: "Package not found"});
|
||||||
|
const arch = packageobject.arch[req.params.arch];
|
||||||
|
if (!arch) return res.status(400).json({error: "Arch not found"});
|
||||||
|
const version = arch[req.params.version];
|
||||||
|
if (!version) return res.status(400).json({error: "Version not found"});
|
||||||
|
return res.json(version);
|
||||||
|
});
|
||||||
|
app.get("/pool/:packageName/:arch", async (req, res) => {
|
||||||
|
const packageobject = packInfos[req.params.packageName];
|
||||||
|
if (!packageobject) return res.status(400).json({error: "Package not found"});
|
||||||
|
const arch = packageobject.arch[req.params.arch];
|
||||||
|
if (!arch) return res.status(400).json({error: "Arch not found"});
|
||||||
|
return res.json(arch);
|
||||||
|
});
|
||||||
|
app.get("/pool/:packageName", async (req, res) => {
|
||||||
|
const packageobject = packInfos[req.params.packageName];
|
||||||
|
if (!packageobject) return res.status(400).json({error: "Package not found"});
|
||||||
|
return res.json(packageobject.arch);
|
||||||
|
});
|
||||||
|
|
||||||
async function createPackages(compress?: "gzip" | "xz", options?: {writeStream?: Writable, package?: string, arch?: string, suite?: string}) {
|
async function createPackages(compress?: "gzip" | "xz", options?: {writeStream?: Writable, package?: string, arch?: string, suite?: string}) {
|
||||||
const rawWrite = new Readable({read(){}});
|
const rawWrite = new Readable({read(){}});
|
||||||
@ -254,28 +279,30 @@ export default async function main(configPath: string) {
|
|||||||
return ReleaseLines.join("\n");
|
return ReleaseLines.join("\n");
|
||||||
}
|
}
|
||||||
app.get("/dists/:dist/Release", (req, res, next) => createReleaseV1(req.params.dist).then((data) => res.setHeader("Content-Type", "text/plain").send(data)).catch(next));
|
app.get("/dists/:dist/Release", (req, res, next) => createReleaseV1(req.params.dist).then((data) => res.setHeader("Content-Type", "text/plain").send(data)).catch(next));
|
||||||
app.get("/dists/:dist/InRelease", async (req, res) => {
|
app.get("/dists/:dist/InRelease", (req, res, next) => {
|
||||||
const Key = repositoryConfig["apt-config"]?.pgpKey;
|
const Key = repositoryConfig["apt-config"]?.pgpKey;
|
||||||
if (!Key) return res.status(404).json({error: "No PGP key found"});
|
if (!Key) return res.status(404).json({error: "No PGP key found"});
|
||||||
// const publicKey = await openpgp.readKey({ armoredKey: Key.public });
|
return Promise.resolve().then(async () => {
|
||||||
const privateKey = Key.passphrase ? await openpgp.decryptKey({privateKey: await openpgp.readPrivateKey({ armoredKey: Key.private }), passphrase: Key.passphrase}) : await openpgp.readPrivateKey({ armoredKey: Key.private });
|
const privateKey = Key.passphrase ? await openpgp.decryptKey({privateKey: await openpgp.readPrivateKey({ armoredKey: Key.private }), passphrase: Key.passphrase}) : await openpgp.readPrivateKey({ armoredKey: Key.private });
|
||||||
const Release = await createReleaseV1(req.params.dist);
|
const Release = await createReleaseV1(req.params.dist);
|
||||||
return res.setHeader("Content-Type", "text/plain").send(await openpgp.sign({
|
return res.setHeader("Content-Type", "text/plain").send(await openpgp.sign({
|
||||||
signingKeys: privateKey,
|
signingKeys: privateKey,
|
||||||
format: "armored",
|
format: "armored",
|
||||||
message: await openpgp.createCleartextMessage({text: Release}),
|
message: await openpgp.createCleartextMessage({text: Release}),
|
||||||
}));
|
}));
|
||||||
|
}).catch(next);
|
||||||
});
|
});
|
||||||
app.get("/dists/:dist/Release.gpg", async (req, res) => {
|
app.get("/dists/:dist/Release.gpg", (req, res, next) => {
|
||||||
const Key = repositoryConfig["apt-config"]?.pgpKey;
|
const Key = repositoryConfig["apt-config"]?.pgpKey;
|
||||||
if (!Key) return res.status(404).json({error: "No PGP key found"});
|
if (!Key) return res.status(404).json({error: "No PGP key found"});
|
||||||
// const publicKey = await openpgp.readKey({ armoredKey: Key.public });
|
return Promise.resolve().then(async () => {
|
||||||
const privateKey = Key.passphrase ? await openpgp.decryptKey({privateKey: await openpgp.readPrivateKey({ armoredKey: Key.private }), passphrase: Key.passphrase}) : await openpgp.readPrivateKey({ armoredKey: Key.private });
|
const privateKey = Key.passphrase ? await openpgp.decryptKey({privateKey: await openpgp.readPrivateKey({ armoredKey: Key.private }), passphrase: Key.passphrase}) : await openpgp.readPrivateKey({ armoredKey: Key.private });
|
||||||
const Release = await createReleaseV1(req.params.dist);
|
const Release = await createReleaseV1(req.params.dist);
|
||||||
return res.setHeader("Content-Type", "text/plain").send(await openpgp.sign({
|
return res.setHeader("Content-Type", "text/plain").send(await openpgp.sign({
|
||||||
signingKeys: privateKey,
|
signingKeys: privateKey,
|
||||||
message: await openpgp.createMessage({text: Release}),
|
message: await openpgp.createMessage({text: Release}),
|
||||||
}));
|
}));
|
||||||
|
}).catch(next);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Error handler
|
// Error handler
|
||||||
|
Reference in New Issue
Block a user