mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-13 02:42:45 +00:00
feat: download zip instead of tar
This commit is contained in:
@@ -30,7 +30,7 @@ export default class GitHubDownload extends GitHubBase implements SourceBase {
|
||||
auth?: string
|
||||
): Promise<OctokitResponse<unknown, 302>> {
|
||||
const octokit = new Octokit({ auth });
|
||||
return octokit.rest.repos.downloadTarballArchive({
|
||||
return octokit.rest.repos.downloadZipballArchive({
|
||||
owner: this.githubRepository.owner,
|
||||
repo: this.githubRepository.repo,
|
||||
ref: this.branch?.commit || "HEAD",
|
||||
@@ -97,7 +97,7 @@ export default class GitHubDownload extends GitHubBase implements SourceBase {
|
||||
try {
|
||||
const downloadStream = got.stream(response.url);
|
||||
downloadStream.addListener("downloadProgress", (p) => (progress = p));
|
||||
await storage.extractTar(originalPath, downloadStream);
|
||||
await storage.extractZip(originalPath, downloadStream);
|
||||
} catch (error) {
|
||||
await this.repository.updateStatus("error", "unable_to_download");
|
||||
throw new AnonymousError("unable_to_download", {
|
||||
|
||||
@@ -2,11 +2,10 @@ import { StorageBase, Tree } from "../types";
|
||||
import config from "../../config";
|
||||
|
||||
import * as fs from "fs";
|
||||
import * as tar from "tar-fs";
|
||||
import * as unzip from "unzip-stream";
|
||||
import * as path from "path";
|
||||
import * as express from "express";
|
||||
import * as stream from "stream";
|
||||
import * as gunzip from "gunzip-maybe";
|
||||
import * as archiver from "archiver";
|
||||
import { promisify } from "util";
|
||||
|
||||
@@ -93,15 +92,17 @@ export default class FileSystem implements StorageBase {
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async extractTar(p: string, data: stream.Readable): Promise<void> {
|
||||
async extractZip(p: string, data: stream.Readable): Promise<void> {
|
||||
const pipeline = promisify(stream.pipeline);
|
||||
return pipeline(
|
||||
data,
|
||||
gunzip(),
|
||||
tar.extract(path.join(config.FOLDER, p), {
|
||||
map: (header) => {
|
||||
header.name = header.name.substr(header.name.indexOf("/") + 1);
|
||||
return header;
|
||||
unzip.Extract({
|
||||
path: path.join(path.join(config.FOLDER, p)),
|
||||
decodeString: (buf) => {
|
||||
const name = buf.toString();
|
||||
const newName = name.substr(name.indexOf("/") + 1);
|
||||
if (newName == "") return "/dev/null";
|
||||
return newName;
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
@@ -2,18 +2,14 @@ import { StorageBase, Tree, TreeFile } from "../types";
|
||||
import { S3 } from "aws-sdk";
|
||||
import config from "../../config";
|
||||
import * as stream from "stream";
|
||||
import { ArchiveStreamToS3 } from "archive-stream-to-s3";
|
||||
import ArchiveStreamToS3 from "decompress-stream-to-s3";
|
||||
import * as express from "express";
|
||||
import * as mime from "mime-types";
|
||||
import * as flow from "xml-flow";
|
||||
import * as archiver from "archiver";
|
||||
import * as path from "path";
|
||||
import * as gunzip from "gunzip-maybe";
|
||||
import AnonymousError from "../AnonymousError";
|
||||
|
||||
const originalArchiveStreamToS3Entry: Function = (ArchiveStreamToS3 as any)
|
||||
.prototype.onEntry;
|
||||
|
||||
export default class S3Storage implements StorageBase {
|
||||
type = "AWS";
|
||||
|
||||
@@ -172,22 +168,21 @@ export default class S3Storage implements StorageBase {
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async extractTar(p: string, data: stream.Readable): Promise<void> {
|
||||
async extractZip(p: string, data: stream.Readable): Promise<void> {
|
||||
let toS3: ArchiveStreamToS3;
|
||||
|
||||
(ArchiveStreamToS3 as any).prototype.onEntry = function (
|
||||
header: any,
|
||||
stream: any,
|
||||
next: any
|
||||
) {
|
||||
header.name = header.name.substr(header.name.indexOf("/") + 1);
|
||||
originalArchiveStreamToS3Entry.call(toS3, header, stream, next);
|
||||
};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
toS3 = new ArchiveStreamToS3(config.S3_BUCKET, p, this.client);
|
||||
toS3 = new ArchiveStreamToS3({
|
||||
bucket: config.S3_BUCKET,
|
||||
prefix: p,
|
||||
s3: this.client,
|
||||
type: "zip",
|
||||
onEntry: (header) => {
|
||||
header.name = header.name.substr(header.name.indexOf("/") + 1);
|
||||
},
|
||||
});
|
||||
stream
|
||||
.pipeline(data, gunzip(), toS3, () => {})
|
||||
.pipeline(data, toS3, () => {})
|
||||
.on("finish", resolve)
|
||||
.on("error", reject);
|
||||
});
|
||||
|
||||
@@ -67,7 +67,7 @@ export interface StorageBase {
|
||||
* @param dir
|
||||
* @param tar
|
||||
*/
|
||||
extractTar(dir: string, tar: stream.Readable): Promise<void>;
|
||||
extractZip(dir: string, tar: stream.Readable): Promise<void>;
|
||||
|
||||
/**
|
||||
* Remove the path
|
||||
|
||||
Reference in New Issue
Block a user