mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-06 21:57:57 +02:00
always use githubStream
This commit is contained in:
+8
-1
@@ -106,7 +106,14 @@ async function main() {
|
|||||||
console.info(
|
console.info(
|
||||||
`[INFO] Downloading repository: ${repository.model.source.repositoryName} from branch ${repository.model.source.branch} and commit ${repository.model.source.commit}...`
|
`[INFO] Downloading repository: ${repository.model.source.repositoryName} from branch ${repository.model.source.branch} and commit ${repository.model.source.commit}...`
|
||||||
);
|
);
|
||||||
await (repository.source as GitHubDownload).download(inq.token);
|
const cliDownload = new GitHubDownload({
|
||||||
|
repoId: repository.repoId,
|
||||||
|
organization: ghURL.owner,
|
||||||
|
repoName: ghURL.name,
|
||||||
|
commit: branch?.commit || "HEAD",
|
||||||
|
getToken: () => inq.token,
|
||||||
|
});
|
||||||
|
await cliDownload.download(inq.token);
|
||||||
const outputFileName = join(inq.output, generateRandomFileName(8) + ".zip");
|
const outputFileName = join(inq.output, generateRandomFileName(8) + ".zip");
|
||||||
console.info("[INFO] Anonymizing repository and creation zip file...");
|
console.info("[INFO] Anonymizing repository and creation zip file...");
|
||||||
await writeFile(outputFileName, await repository.zip());
|
await writeFile(outputFileName, await repository.zip());
|
||||||
|
|||||||
+10
-31
@@ -4,7 +4,6 @@ import { Readable } from "stream";
|
|||||||
import * as sha1 from "crypto-js/sha1";
|
import * as sha1 from "crypto-js/sha1";
|
||||||
import User from "./User";
|
import User from "./User";
|
||||||
import GitHubStream from "./source/GitHubStream";
|
import GitHubStream from "./source/GitHubStream";
|
||||||
import GitHubDownload from "./source/GitHubDownload";
|
|
||||||
import Zip from "./source/Zip";
|
import Zip from "./source/Zip";
|
||||||
import { anonymizePath } from "./anonymize-utils";
|
import { anonymizePath } from "./anonymize-utils";
|
||||||
import UserModel from "./model/users/users.model";
|
import UserModel from "./model/users/users.model";
|
||||||
@@ -21,7 +20,6 @@ import {
|
|||||||
GitHubRepository,
|
GitHubRepository,
|
||||||
} from "./source/GitHubRepository";
|
} from "./source/GitHubRepository";
|
||||||
import { getToken } from "./GitHubUtils";
|
import { getToken } from "./GitHubUtils";
|
||||||
import { FILE_TYPE } from "./storage/Storage";
|
|
||||||
import config from "../config";
|
import config from "../config";
|
||||||
import FileModel from "./model/files/files.model";
|
import FileModel from "./model/files/files.model";
|
||||||
import { IFile } from "./model/files/files.types";
|
import { IFile } from "./model/files/files.types";
|
||||||
@@ -83,31 +81,16 @@ export default class Repository {
|
|||||||
const ghRepo = new GitHubRepository({
|
const ghRepo = new GitHubRepository({
|
||||||
name: this.model.source.repositoryName,
|
name: this.model.source.repositoryName,
|
||||||
});
|
});
|
||||||
switch (this.model.source.type) {
|
if (this.model.source.type === "Zip") {
|
||||||
case "GitHubDownload":
|
return new Zip(this.model.source, this.repoId);
|
||||||
return new GitHubDownload({
|
|
||||||
repoId: this.repoId,
|
|
||||||
commit: this.model.source.commit || "HEAD",
|
|
||||||
organization: ghRepo.owner,
|
|
||||||
repoName: ghRepo.repo,
|
|
||||||
getToken: () => this.getToken(),
|
|
||||||
});
|
|
||||||
case "GitHubStream":
|
|
||||||
return new GitHubStream({
|
|
||||||
repoId: this.repoId,
|
|
||||||
commit: this.model.source.commit || "HEAD",
|
|
||||||
organization: ghRepo.owner,
|
|
||||||
repoName: ghRepo.repo,
|
|
||||||
getToken: () => this.getToken(),
|
|
||||||
});
|
|
||||||
case "Zip":
|
|
||||||
return new Zip(this.model.source, this.repoId);
|
|
||||||
default:
|
|
||||||
throw new AnonymousError("unsupported_source", {
|
|
||||||
object: this,
|
|
||||||
httpStatus: 400,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
return new GitHubStream({
|
||||||
|
repoId: this.repoId,
|
||||||
|
commit: this.model.source.commit || "HEAD",
|
||||||
|
organization: ghRepo.owner,
|
||||||
|
repoName: ghRepo.repo,
|
||||||
|
getToken: () => this.getToken(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -264,11 +247,7 @@ export default class Repository {
|
|||||||
|
|
||||||
async isReady() {
|
async isReady() {
|
||||||
if (this.status !== RepositoryStatus.READY) return false;
|
if (this.status !== RepositoryStatus.READY) return false;
|
||||||
if (
|
if (!(await FileModel.exists({ repoId: this.repoId }).exec())) {
|
||||||
(this.source.type == "GitHubDownload" &&
|
|
||||||
(await storage.exists(this.repoId)) == FILE_TYPE.NOT_FOUND) ||
|
|
||||||
!(await FileModel.exists({ repoId: this.repoId }).exec())
|
|
||||||
) {
|
|
||||||
this.model.status = RepositoryStatus.PREPARING;
|
this.model.status = RepositoryStatus.PREPARING;
|
||||||
await this.updateIfNeeded({ force: true });
|
await this.updateIfNeeded({ force: true });
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -329,15 +329,7 @@ function updateRepoModel(
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
repoUpdate: any
|
repoUpdate: any
|
||||||
) {
|
) {
|
||||||
if (repoUpdate.source.type) {
|
model.source.type = "GitHubStream";
|
||||||
model.source.type = repoUpdate.source.type;
|
|
||||||
if (
|
|
||||||
model.source.type != "GitHubStream" &&
|
|
||||||
model.source.type != "GitHubDownload"
|
|
||||||
) {
|
|
||||||
model.source.type = "GitHubStream";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
model.source.commit = repoUpdate.source.commit;
|
model.source.commit = repoUpdate.source.commit;
|
||||||
model.source.branch = repoUpdate.source.branch;
|
model.source.branch = repoUpdate.source.branch;
|
||||||
model.options = {
|
model.options = {
|
||||||
|
|||||||
Reference in New Issue
Block a user