mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-06-03 06:08:03 +02:00
fix: fix webview on root repo
This commit is contained in:
@@ -131,7 +131,7 @@ export default class AnonymizedFile {
|
|||||||
span.setAttribute("file", this.anonymizedPath);
|
span.setAttribute("file", this.anonymizedPath);
|
||||||
try {
|
try {
|
||||||
span.setAttribute("anonymizedPath", this.anonymizedPath);
|
span.setAttribute("anonymizedPath", this.anonymizedPath);
|
||||||
if (!this.anonymizedPath) {
|
if (this.anonymizedPath == null) {
|
||||||
throw new AnonymousError("path_not_specified", {
|
throw new AnonymousError("path_not_specified", {
|
||||||
object: this,
|
object: this,
|
||||||
httpStatus: 400,
|
httpStatus: 400,
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ export default class GitHubStream extends GitHubBase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const promises: Promise<any>[] = [];
|
const promises: ReturnType<GitHubStream["getGHTree"]>[] = [];
|
||||||
const parentPaths: string[] = [];
|
const parentPaths: string[] = [];
|
||||||
for (const file of data.tree) {
|
for (const file of data.tree) {
|
||||||
if (file.type == "tree" && file.path && file.sha) {
|
if (file.type == "tree" && file.path && file.sha) {
|
||||||
@@ -224,6 +224,9 @@ export default class GitHubStream extends GitHubBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
(await Promise.all(promises)).forEach((data, i) => {
|
(await Promise.all(promises)).forEach((data, i) => {
|
||||||
|
if (data.truncated) {
|
||||||
|
// TODO: the tree is truncated
|
||||||
|
}
|
||||||
output.push(...this.tree2Tree(data.tree, parentPaths[i]));
|
output.push(...this.tree2Tree(data.tree, parentPaths[i]));
|
||||||
});
|
});
|
||||||
return output;
|
return output;
|
||||||
|
|||||||
@@ -41,25 +41,23 @@ async function webView(req: express.Request, res: express.Response) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let wRoot = repo.options.pageSource.path;
|
const wRoot = repo.options.pageSource.path;
|
||||||
if (wRoot.at(0) == "/") {
|
|
||||||
wRoot = wRoot.substring(1);
|
|
||||||
}
|
|
||||||
const filePath = req.path.split(req.params.repoId)[1];
|
const filePath = req.path.split(req.params.repoId)[1];
|
||||||
let requestPath = path.join(wRoot, filePath);
|
let requestPath = path.join(wRoot, filePath);
|
||||||
|
if (requestPath.at(0) == "/") {
|
||||||
|
requestPath = requestPath.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
let f = new AnonymizedFile({
|
let f = new AnonymizedFile({
|
||||||
repository: repo,
|
repository: repo,
|
||||||
anonymizedPath: requestPath,
|
anonymizedPath: requestPath,
|
||||||
});
|
});
|
||||||
if (
|
if (requestPath == "" && req.headers.accept?.includes("text/html")) {
|
||||||
requestPath.at(-1) == "/" &&
|
|
||||||
req.headers.accept?.includes("text/html")
|
|
||||||
) {
|
|
||||||
// look for index file
|
// look for index file
|
||||||
const candidates = await repo.files({
|
const candidates = await repo.files({
|
||||||
recursive: false,
|
recursive: false,
|
||||||
path: await f.originalPath(),
|
path: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
let bestMatch = null;
|
let bestMatch = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user