mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-12 18:32:44 +00:00
fix: handle empty repository
This commit is contained in:
@@ -28,12 +28,14 @@
|
|||||||
>Edit</a
|
>Edit</a
|
||||||
>
|
>
|
||||||
<a
|
<a
|
||||||
|
ng-show="content != null"
|
||||||
ng-href="{{url}}"
|
ng-href="{{url}}"
|
||||||
target="__self"
|
target="__self"
|
||||||
class="btn btn-outline-primary btn-sm"
|
class="btn btn-outline-primary btn-sm"
|
||||||
>View raw</a
|
>View raw</a
|
||||||
>
|
>
|
||||||
<a
|
<a
|
||||||
|
ng-show="content != null"
|
||||||
ng-href="{{url}}&download=true"
|
ng-href="{{url}}&download=true"
|
||||||
target="__self"
|
target="__self"
|
||||||
class="btn btn-outline-primary btn-sm"
|
class="btn btn-outline-primary btn-sm"
|
||||||
|
|||||||
@@ -9,4 +9,5 @@
|
|||||||
<div ng-if="type == 'IPython'"><notebook file="url"></notebook></div>
|
<div ng-if="type == 'IPython'"><notebook file="url"></notebook></div>
|
||||||
<div ng-if="type == 'error'" class="file-error container d-flex h-100"><h1 class="display-1 m-auto" translate="ERRORS.{{content}}">Error</h1></div></div>
|
<div ng-if="type == 'error'" class="file-error container d-flex h-100"><h1 class="display-1 m-auto" translate="ERRORS.{{content}}">Error</h1></div></div>
|
||||||
<div ng-if="type == 'loading' && !error" class="file-error container d-flex h-100"><h1 class="display-1 m-auto">Loading...</h1></div></div>
|
<div ng-if="type == 'loading' && !error" class="file-error container d-flex h-100"><h1 class="display-1 m-auto">Loading...</h1></div></div>
|
||||||
<div ng-if="content == null" class="file-error container d-flex h-100"><h1 class="display-1 m-auto">Empty file!</h1></div>
|
<div ng-if="type == 'empty'" class="file-error container d-flex h-100"><h1 class="display-1 m-auto">Empty repository!</h1></div>
|
||||||
|
<div ng-if="content == null && type != 'empty'" class="file-error container d-flex h-100"><h1 class="display-1 m-auto">Empty file!</h1></div>
|
||||||
@@ -1839,10 +1839,17 @@ angular
|
|||||||
const path = i > 0 ? $scope.paths.slice(0, i).join("/") : "";
|
const path = i > 0 ? $scope.paths.slice(0, i).join("/") : "";
|
||||||
await $scope.getFiles(path);
|
await $scope.getFiles(path);
|
||||||
}
|
}
|
||||||
$scope.$apply(() => {
|
if ($scope.files.length == 1 && $scope.files[0].name == "") {
|
||||||
selectFile();
|
$scope.files = [];
|
||||||
updateContent();
|
$scope.type = "empty";
|
||||||
});
|
$scope.$apply();
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$scope.$apply(() => {
|
||||||
|
selectFile();
|
||||||
|
updateContent();
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
public/script/bundle.min.js
vendored
2
public/script/bundle.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -402,10 +402,19 @@ export default class Repository {
|
|||||||
}
|
}
|
||||||
this.model.increment();
|
this.model.increment();
|
||||||
await this.updateStatus(RepositoryStatus.DOWNLOAD);
|
await this.updateStatus(RepositoryStatus.DOWNLOAD);
|
||||||
await this.files({
|
const files = await this.files({
|
||||||
force: false,
|
force: false,
|
||||||
progress,
|
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.updateStatus(RepositoryStatus.READY);
|
||||||
await this.computeSize();
|
await this.computeSize();
|
||||||
span.end();
|
span.end();
|
||||||
|
|||||||
@@ -194,11 +194,16 @@ export default class GitHubStream extends GitHubBase {
|
|||||||
});
|
});
|
||||||
output.push(...this.tree2Tree(data.tree, parentPath));
|
output.push(...this.tree2Tree(data.tree, parentPath));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new AnonymousError("files_not_found", {
|
if ((error as any).status == 404) {
|
||||||
httpStatus: 404,
|
// empty repo
|
||||||
object: this.data,
|
data = { tree: [] };
|
||||||
cause: error as Error,
|
} 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 promises: Promise<any>[] = [];
|
||||||
const parentPaths: string[] = [];
|
const parentPaths: string[] = [];
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ router.post("/", async (req: express.Request, res: express.Response) => {
|
|||||||
commit: commit,
|
commit: commit,
|
||||||
getToken: () => token,
|
getToken: () => token,
|
||||||
});
|
});
|
||||||
|
console.log(`[FILE] ${repoId}/${filePath}`);
|
||||||
const content = await source.getFileContentCache(
|
const content = await source.getFileContentCache(
|
||||||
filePath,
|
filePath,
|
||||||
repoId,
|
repoId,
|
||||||
|
|||||||
Reference in New Issue
Block a user