This commit is contained in:
tezlm 2022-04-14 17:26:36 -07:00
parent bfbeb55fe4
commit e45630a97d
7 changed files with 70 additions and 65 deletions

View file

@ -1,4 +1,4 @@
/assets/ resources for the site itself
/media/ wait no no no dont rsync the entire memes folde-
/public/ random things that i have made public
/git/ my git repositories, coming soon!
/git/ my git repositories

View file

@ -15,7 +15,7 @@ const comments = fs.readFileSync(path.join(__dirname, "../assets/comments"), "ut
exports.hash = (where) => {
if(indexes.has(where)) {
try {
return fs.statSync(indexes.get(where)).mtime;
return fs.statSync(path.join(where, indexes.get(where))).mtime;
} catch {
indexes.delete(where);
}

View file

@ -40,5 +40,11 @@ module.exports = (app, dir, log) => {
app.all("/upload/", authorize(process.env.SECURE_USER, process.env.SECURE_PASS));
app.get("/restrict/", authorize(process.env.RESTRICT_USER, process.env.RESTRICT_PASS));
app.get("/restrict/*", authorize(process.env.RESTRICT_USER, process.env.RESTRICT_PASS));
app.get("*/info/refs", (req, res, next) => {
if(req.query.service !== "git-receive-pack") return next();
authorize(process.env.SECURE_USER, process.env.SECURE_PASS)(req, res, next);
});
app.all("*/git-receive-pack", authorize(process.env.SECURE_USER, process.env.SECURE_PASS));
}

View file

@ -1,39 +1,35 @@
const fs = require("fs");
const path = require("path");
const gen = require("../static.js");
const { spawn } = require("child_process");
const backend = require("git-http-backend");
const gitdirs = new Map();
module.exports = (app, dir, log) => {
const isgit = (name) => {
if(gitdirs.has(name)) return gitdirs.get(name);
const exists = fs.existsSync(path.join(dir, "overlay", name, ".git"));
gitdirs.set(name, exists);
return exists;
};
function handle(repo, req, res) {
const reqStream = req.headers["content-encoding"] === "gzip" ? req.pipe(zlib.createGunzip())
: req.headers["content-encoding"] === "deflate" ? req.pipe(zlib.createDeflate())
: req;
const mapgit = (dir) => (req, res, next) => {
const name = path.normalize(req.params[0]);
if(!isgit(name)) return next();
gen(path.join(req.params[0], ".git", dir, req.params[1] || ""), true)(req, res);
};
reqStream.pipe(backend(req.url, (err, service) => {
if(err) return res.end(err + "\n");
res.contentType(service.type);
const ps = spawn(service.cmd, service.args.concat(repo));
ps.stdout.pipe(service.createStream()).pipe(ps.stdin);
})).pipe(res);
}
const services = ["git-upload-pack", "git-receive-pack"];
app.get("*/info/refs", (req, res, next) => {
if(!services.includes(req.query.service)) return next();
const repo = path.join(dir, "overlay", path.normalize(req.params[0]));
if(!fs.existsSync(repo)) return next();
if(!fs.existsSync(path.join(repo, ".git"))) return res.sendStatus(400);
log.info(`git ${req.query.service === "git-upload-pack" ? "pulling" : "pushing"} ${req.params[0]}`);
let refs = "";
for(let dir of fs.readdirSync(path.join(repo, ".git/refs"))) {
for(let file of fs.readdirSync(path.join(repo, `.git/refs/${dir}`))) {
refs += `${fs.readFileSync(path.join(repo, `.git/refs/${dir}`, file), "utf8").trim()}\trefs/${dir}/${file}\n`;
}
}
res.end(refs);
if(!["git-upload-pack", "git-receive-pack"].includes(req.query.service)) return next();
handle(path.join(dir, "overlay", path.normalize(req.params[0])), req, res);
});
app.get("*/objects/*", mapgit("objects"));
app.get("*/HEAD", mapgit("HEAD"));
// app.propfind("*", console.log)
app.post("*/git-upload-pack", (req, res, next) => {
handle(path.join(dir, "overlay", path.normalize(req.params[0])), req, res);
});
app.post("*/git-receive-pack", (req, res, next) => {
handle(path.join(dir, "overlay", path.normalize(req.params[0])), req, res);
});
}

View file

@ -13,10 +13,11 @@
"dotenv": "^16.0.0",
"express": "^4.17.3",
"express-ws": "^5.0.2",
"highlight.js": "^11.5.0",
"lru-cache": "^7.7.1",
"git-http-backend": "^1.0.2",
"highlight.js": "^11.5.1",
"lru-cache": "^7.8.1",
"markdown-it": "^12.3.2",
"markdown-it-image-figures": "^2.0.0",
"markdown-it-image-figures": "^2.1.0",
"multer": "^1.4.4",
"mustache": "^4.2.0",
"mustache-express": "^1.3.2",

View file

@ -5,10 +5,11 @@ specifiers:
dotenv: ^16.0.0
express: ^4.17.3
express-ws: ^5.0.2
highlight.js: ^11.5.0
lru-cache: ^7.7.1
git-http-backend: ^1.0.2
highlight.js: ^11.5.1
lru-cache: ^7.8.1
markdown-it: ^12.3.2
markdown-it-image-figures: ^2.0.0
markdown-it-image-figures: ^2.1.0
multer: ^1.4.4
mustache: ^4.2.0
mustache-express: ^1.3.2
@ -22,10 +23,11 @@ dependencies:
dotenv: 16.0.0
express: 4.17.3
express-ws: 5.0.2_express@4.17.3
highlight.js: 11.5.0
lru-cache: 7.7.1
git-http-backend: 1.0.2
highlight.js: 11.5.1
lru-cache: 7.8.1
markdown-it: 12.3.2
markdown-it-image-figures: 2.0.0_markdown-it@12.3.2
markdown-it-image-figures: 2.1.0_markdown-it@12.3.2
multer: 1.4.4
mustache: 4.2.0
mustache-express: 1.3.2
@ -252,13 +254,6 @@ packages:
vary: 1.1.2
dev: false
/fast-xml-parser/3.21.1:
resolution: {integrity: sha512-FTFVjYoBOZTJekiUsawGsSYV9QL0A+zDYCRj7y34IO6Jg+2IMYEtQa+bbictpdpV8dHxXywqU7C0gRDEOFtBFg==}
hasBin: true
dependencies:
strnum: 1.0.5
dev: false
/finalhandler/1.1.2:
resolution: {integrity: sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==}
engines: {node: '>= 0.8'}
@ -282,8 +277,19 @@ packages:
engines: {node: '>= 0.6'}
dev: false
/highlight.js/11.5.0:
resolution: {integrity: sha512-SM6WDj5/C+VfIY8pZ6yW6Xa0Fm1tniYVYWYW1Q/DcMnISZFrC3aQAZZZFAAZtybKNrGId3p/DNbFTtcTXXgYBw==}
/git-http-backend/1.0.2:
resolution: {integrity: sha1-3AHkKEIJNTBkRTpw+S+J3gg06xA=}
dependencies:
git-side-band-message: 0.0.3
inherits: 2.0.4
dev: false
/git-side-band-message/0.0.3:
resolution: {integrity: sha1-uKU0jC3L8ZSf0pXFBgFOJsPyakY=}
dev: false
/highlight.js/11.5.1:
resolution: {integrity: sha512-LKzHqnxr4CrD2YsNoIf/o5nJ09j4yi/GcH5BnYz9UnVpZdS4ucMgvP61TDty5xJcFGRjnH4DpujkS9bHT3hq0Q==}
engines: {node: '>=12.0.0'}
dev: false
@ -314,13 +320,6 @@ packages:
engines: {node: '>= 0.10'}
dev: false
/is-svg/4.3.2:
resolution: {integrity: sha512-mM90duy00JGMyjqIVHu9gNTjywdZV+8qNasX8cm/EEYZ53PHDgajvbBwNVvty5dwSAxLUD3p3bdo+7sR/UMrpw==}
engines: {node: '>=6'}
dependencies:
fast-xml-parser: 3.21.1
dev: false
/isarray/0.0.1:
resolution: {integrity: sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=}
dev: false
@ -341,18 +340,17 @@ packages:
yallist: 3.1.1
dev: false
/lru-cache/7.7.1:
resolution: {integrity: sha512-cRffBiTW8s73eH4aTXqBcTLU0xQnwGV3/imttRHGWCrbergmnK4D6JXQd8qin5z43HnDwRI+o7mVW0LEB+tpAw==}
/lru-cache/7.8.1:
resolution: {integrity: sha512-E1v547OCgJvbvevfjgK9sNKIVXO96NnsTsFPBlg4ZxjhsJSODoH9lk8Bm0OxvHNm6Vm5Yqkl/1fErDxhYL8Skg==}
engines: {node: '>=12'}
dev: false
/markdown-it-image-figures/2.0.0_markdown-it@12.3.2:
resolution: {integrity: sha512-gZDwvQ+SDA2KYwoEbs42BRDv57j2HEe7a1fUO8aKO6ku1GIvu5nBbxoJ7eBUTZOQYOQ0J78ZaZn0sdflEMjzXw==}
/markdown-it-image-figures/2.1.0_markdown-it@12.3.2:
resolution: {integrity: sha512-a5FIzzUlK65iGfQlNWH94cyxKpV+Qj8a+4Q3+wVseryHMCOfGaX0aCNtdEkCeb19uGDzVw3Az5tst2hXWAdJ1Q==}
engines: {node: '>=12.0.0'}
peerDependencies:
markdown-it: '*'
dependencies:
is-svg: 4.3.2
markdown-it: 12.3.2
dev: false
@ -431,7 +429,7 @@ packages:
concat-stream: 1.6.2
mkdirp: 0.5.6
object-assign: 4.1.1
on-finished: 2.3.0
on-finished: 2.4.1
type-is: 1.6.18
xtend: 4.0.2
dev: false
@ -482,6 +480,13 @@ packages:
ee-first: 1.1.1
dev: false
/on-finished/2.4.1:
resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==}
engines: {node: '>= 0.8'}
dependencies:
ee-first: 1.1.1
dev: false
/on-headers/1.0.2:
resolution: {integrity: sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==}
engines: {node: '>= 0.8'}
@ -614,10 +619,6 @@ packages:
safe-buffer: 5.1.2
dev: false
/strnum/1.0.5:
resolution: {integrity: sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA==}
dev: false
/toidentifier/1.0.1:
resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==}
engines: {node: '>=0.6'}

View file

@ -11,6 +11,7 @@ types.set("jpeg", "image/jpeg");
types.set("gif", "image/gif");
types.set("apng", "image/png");
types.set("svg", "image/svg");
types.set("webp", "image/webp");
types.set("ogg", "audio/ogg");
types.set("opus", "audio/ogg");
types.set("mp3", "audio/mp3");