mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-13 02:42:45 +00:00
fix: handle empty repository
This commit is contained in:
@@ -402,10 +402,19 @@ export default class Repository {
|
||||
}
|
||||
this.model.increment();
|
||||
await this.updateStatus(RepositoryStatus.DOWNLOAD);
|
||||
await this.files({
|
||||
const files = await this.files({
|
||||
force: false,
|
||||
progress,
|
||||
});
|
||||
if (files.length === 0) {
|
||||
// create a dummy file when the repo is empty to avoid errors
|
||||
await new FileModel({
|
||||
repoId: this.repoId,
|
||||
path: "",
|
||||
name: "",
|
||||
size: 0,
|
||||
}).save();
|
||||
}
|
||||
await this.updateStatus(RepositoryStatus.READY);
|
||||
await this.computeSize();
|
||||
span.end();
|
||||
|
||||
@@ -194,11 +194,16 @@ export default class GitHubStream extends GitHubBase {
|
||||
});
|
||||
output.push(...this.tree2Tree(data.tree, parentPath));
|
||||
} catch (error) {
|
||||
throw new AnonymousError("files_not_found", {
|
||||
httpStatus: 404,
|
||||
object: this.data,
|
||||
cause: error as Error,
|
||||
});
|
||||
if ((error as any).status == 404) {
|
||||
// empty repo
|
||||
data = { tree: [] };
|
||||
} else {
|
||||
throw new AnonymousError("repo_not_found", {
|
||||
httpStatus: (error as any).status || 404,
|
||||
object: this.data,
|
||||
cause: error as Error,
|
||||
});
|
||||
}
|
||||
}
|
||||
const promises: Promise<any>[] = [];
|
||||
const parentPaths: string[] = [];
|
||||
|
||||
@@ -25,6 +25,7 @@ router.post("/", async (req: express.Request, res: express.Response) => {
|
||||
commit: commit,
|
||||
getToken: () => token,
|
||||
});
|
||||
console.log(`[FILE] ${repoId}/${filePath}`);
|
||||
const content = await source.getFileContentCache(
|
||||
filePath,
|
||||
repoId,
|
||||
|
||||
Reference in New Issue
Block a user