mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-20 00:14:43 +02:00
fix: auth issue & profile save issue
This commit is contained in:
@@ -1115,7 +1115,7 @@ angular
|
|||||||
if (data.terms) {
|
if (data.terms) {
|
||||||
$scope.terms = data.terms.join("\n");
|
$scope.terms = data.terms.join("\n");
|
||||||
}
|
}
|
||||||
$scope.option = Object.assign({}, $scope.option, data.options);
|
$scope.options = Object.assign({}, $scope.options, data.options);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getDefault();
|
getDefault();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { RestEndpointMethodTypes } from "@octokit/rest";
|
|||||||
|
|
||||||
import AnonymousError from "../AnonymousError";
|
import AnonymousError from "../AnonymousError";
|
||||||
import { isConnected } from "../../server/database";
|
import { isConnected } from "../../server/database";
|
||||||
import { octokit } from "../GitHubUtils";
|
import { checkToken, octokit } from "../GitHubUtils";
|
||||||
import { IRepositoryDocument } from "../model/repositories/repositories.types";
|
import { IRepositoryDocument } from "../model/repositories/repositories.types";
|
||||||
import RepositoryModel from "../model/repositories/repositories.model";
|
import RepositoryModel from "../model/repositories/repositories.model";
|
||||||
|
|
||||||
@@ -306,13 +306,36 @@ export async function getRepositoryFromGitHub(opt: {
|
|||||||
})
|
})
|
||||||
).data as RestEndpointMethodTypes["repos"]["get"]["response"]["data"];
|
).data as RestEndpointMethodTypes["repos"]["get"]["response"]["data"];
|
||||||
} catch (idError) {
|
} catch (idError) {
|
||||||
|
const idStatus = (idError as { status?: number }).status;
|
||||||
|
if (
|
||||||
|
idStatus === 401 ||
|
||||||
|
idStatus === 403 ||
|
||||||
|
!(await checkToken(opt.accessToken))
|
||||||
|
) {
|
||||||
|
throw new AnonymousError("token_expired", {
|
||||||
|
httpStatus: 401,
|
||||||
|
object: { owner: opt.owner, repo: opt.repo },
|
||||||
|
cause: idError as Error,
|
||||||
|
});
|
||||||
|
}
|
||||||
throw new AnonymousError("repo_not_found", {
|
throw new AnonymousError("repo_not_found", {
|
||||||
httpStatus: (idError as { status?: number }).status || 404,
|
httpStatus: idStatus || 404,
|
||||||
object: { owner: opt.owner, repo: opt.repo },
|
object: { owner: opt.owner, repo: opt.repo },
|
||||||
cause: idError as Error,
|
cause: idError as Error,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (
|
||||||
|
status === 401 ||
|
||||||
|
status === 403 ||
|
||||||
|
!(await checkToken(opt.accessToken))
|
||||||
|
) {
|
||||||
|
throw new AnonymousError("token_expired", {
|
||||||
|
httpStatus: 401,
|
||||||
|
object: { owner: opt.owner, repo: opt.repo },
|
||||||
|
cause: error as Error,
|
||||||
|
});
|
||||||
|
}
|
||||||
throw new AnonymousError("repo_not_found", {
|
throw new AnonymousError("repo_not_found", {
|
||||||
httpStatus: status,
|
httpStatus: status,
|
||||||
object: {
|
object: {
|
||||||
|
|||||||
+23
-1
@@ -3,6 +3,8 @@ import { Parse } from "unzip-stream";
|
|||||||
import archiver = require("archiver");
|
import archiver = require("archiver");
|
||||||
|
|
||||||
import GitHubDownload from "./source/GitHubDownload";
|
import GitHubDownload from "./source/GitHubDownload";
|
||||||
|
import { classifyGitHubMissError } from "./source/GitHubBase";
|
||||||
|
import AnonymousError from "./AnonymousError";
|
||||||
import {
|
import {
|
||||||
AnonymizeTransformer,
|
AnonymizeTransformer,
|
||||||
anonymizePathCompiled,
|
anonymizePathCompiled,
|
||||||
@@ -81,7 +83,27 @@ export async function streamAnonymizedZip(
|
|||||||
getToken: opt.getToken,
|
getToken: opt.getToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await source.getZipUrl();
|
let response;
|
||||||
|
try {
|
||||||
|
response = await source.getZipUrl();
|
||||||
|
} catch (error) {
|
||||||
|
const code = await classifyGitHubMissError(error, {
|
||||||
|
organization: opt.organization,
|
||||||
|
repoName: opt.repoName,
|
||||||
|
repoId: opt.repoId,
|
||||||
|
commit: opt.commit,
|
||||||
|
getToken: opt.getToken,
|
||||||
|
});
|
||||||
|
const status = (error as { status?: number }).status;
|
||||||
|
throw new AnonymousError(code, {
|
||||||
|
httpStatus: status && status >= 500 ? 502 : status || 502,
|
||||||
|
cause: error as Error,
|
||||||
|
object: {
|
||||||
|
repoId: opt.repoId,
|
||||||
|
fullName: `${opt.organization}/${opt.repoName}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
const downloadStream = got.stream(response.url);
|
const downloadStream = got.stream(response.url);
|
||||||
|
|
||||||
res.on("error", (error) => {
|
res.on("error", (error) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user