mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-16 14:59:07 +02:00
feat: improve download anonymized repository
This commit is contained in:
+13
-12
@@ -289,14 +289,9 @@ export default class AnonymizedFile {
|
||||
this.sha(),
|
||||
this.repository.getToken(),
|
||||
]);
|
||||
// const hostName = new URL(config.STREAMER_ENTRYPOINT).hostname;
|
||||
// const ipHost = await this.cacheableLookup.lookupAsync(hostName);
|
||||
got
|
||||
const resStream = got
|
||||
.stream(join(config.STREAMER_ENTRYPOINT, "api"), {
|
||||
method: "POST",
|
||||
// lookup: this.cacheableLookup.lookup,
|
||||
// host: ipHost.address,
|
||||
// dnsCache: this.cacheableLookup,
|
||||
json: {
|
||||
sha,
|
||||
token,
|
||||
@@ -308,7 +303,8 @@ export default class AnonymizedFile {
|
||||
anonymizerOptions: anonymizer.opt,
|
||||
},
|
||||
})
|
||||
.on("error", () => {
|
||||
.on("error", (err) => {
|
||||
span.recordException(err);
|
||||
handleError(
|
||||
new AnonymousError("file_not_found", {
|
||||
object: this,
|
||||
@@ -316,12 +312,17 @@ export default class AnonymizedFile {
|
||||
}),
|
||||
res
|
||||
);
|
||||
})
|
||||
.pipe(res)
|
||||
.on("close", () => {
|
||||
span.end();
|
||||
resolve();
|
||||
});
|
||||
resStream.pipe(res);
|
||||
res.on("close", () => {
|
||||
span.end();
|
||||
resolve();
|
||||
});
|
||||
res.on("error", (err) => {
|
||||
reject(err);
|
||||
span.recordException(err);
|
||||
span.end();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ export default class GitHubDownload extends GitHubBase {
|
||||
super(data);
|
||||
}
|
||||
|
||||
private async _getZipUrl(): Promise<OctokitResponse<unknown, 302>> {
|
||||
public async getZipUrl(): Promise<OctokitResponse<unknown, 302>> {
|
||||
const oct = octokit(await this.data.getToken());
|
||||
return oct.rest.repos.downloadZipballArchive({
|
||||
owner: this.data.organization,
|
||||
@@ -32,11 +32,11 @@ export default class GitHubDownload extends GitHubBase {
|
||||
try {
|
||||
let response: OctokitResponse<unknown, number>;
|
||||
try {
|
||||
response = await this._getZipUrl();
|
||||
response = await this.getZipUrl();
|
||||
} catch (error) {
|
||||
span.recordException(error as Error);
|
||||
throw new AnonymousError("repo_not_accessible", {
|
||||
httpStatus: 404,
|
||||
throw new AnonymousError("repo_not_found", {
|
||||
httpStatus: (error as any).status || 404,
|
||||
object: this.data,
|
||||
cause: error as Error,
|
||||
});
|
||||
|
||||
@@ -194,7 +194,8 @@ export default class GitHubStream extends GitHubBase {
|
||||
});
|
||||
output.push(...this.tree2Tree(data.tree, parentPath));
|
||||
} catch (error) {
|
||||
if ((error as any).status == 404) {
|
||||
console.log(error);
|
||||
if ((error as any).status == 409 || (error as any).status == 404) {
|
||||
// empty repo
|
||||
data = { tree: [] };
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user