-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (31 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const express = require("express");
const app = express();
const getFileName = ({ os, version, arch }) => {
const ext = os === "win" ? ".exe" : "";
return "please-" + version + "-" + os + "-" + arch + ext;
};
const usage = `\
Usage: GET /:version/:os?/:arch?
Defaults: os=linux arch=x64`;
app.get("/", (req, res) => {
res.end(usage);
});
const redir = (res, version, fileName) => {
const url = `https://github.com/pleasecmd/please/releases/download/v${version}/${fileName}`;
res.redirect(url);
};
app.get("/:version/:os/:arch", (req, res) => {
const fileName = getFileName(req.params);
redir(res, req.params.version, fileName);
});
app.get("/:version/:os", (req, res) => {
const params = { ...req.params, arch: "x64" };
const fileName = getFileName(params);
redir(res, req.params.version, fileName);
});
app.get("/:version", (req, res) => {
const params = { ...req.params, os: "linux", arch: "x64" };
const fileName = getFileName(params);
redir(res, req.params.version, fileName);
});
module.exports = app;