mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-13 19:02:45 +00:00
chore: replace bull by bullmq
This commit is contained in:
@@ -2,10 +2,10 @@ import { StorageBase, Tree } from "../types";
|
||||
import config from "../../config";
|
||||
|
||||
import * as fs from "fs";
|
||||
import * as unzip from "unzip-stream";
|
||||
import * as path from "path";
|
||||
import * as express from "express";
|
||||
import * as stream from "stream";
|
||||
import { Extract } from "unzip-stream";
|
||||
import { join, basename, dirname } from "path";
|
||||
import { Response } from "express";
|
||||
import { Readable, pipeline } from "stream";
|
||||
import * as archiver from "archiver";
|
||||
import { promisify } from "util";
|
||||
|
||||
@@ -16,32 +16,32 @@ export default class FileSystem implements StorageBase {
|
||||
|
||||
/** @override */
|
||||
async exists(p: string): Promise<boolean> {
|
||||
return fs.existsSync(path.join(config.FOLDER, p));
|
||||
return fs.existsSync(join(config.FOLDER, p));
|
||||
}
|
||||
|
||||
/** @override */
|
||||
send(p: string, res: express.Response) {
|
||||
res.sendFile(path.join(config.FOLDER, p), { dotfiles: "allow" });
|
||||
send(p: string, res: Response) {
|
||||
res.sendFile(join(config.FOLDER, p), { dotfiles: "allow" });
|
||||
}
|
||||
|
||||
/** @override */
|
||||
read(p: string): stream.Readable {
|
||||
return fs.createReadStream(path.join(config.FOLDER, p));
|
||||
read(p: string): Readable {
|
||||
return fs.createReadStream(join(config.FOLDER, p));
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async write(p: string, data: Buffer): Promise<void> {
|
||||
if (!(await this.exists(path.dirname(p)))) {
|
||||
await fs.promises.mkdir(path.dirname(path.join(config.FOLDER, p)), {
|
||||
if (!(await this.exists(dirname(p)))) {
|
||||
await fs.promises.mkdir(dirname(join(config.FOLDER, p)), {
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
return fs.promises.writeFile(path.join(config.FOLDER, p), data);
|
||||
return fs.promises.writeFile(join(config.FOLDER, p), data);
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async rm(dir: string): Promise<void> {
|
||||
await fs.promises.rm(path.join(config.FOLDER, dir), {
|
||||
await fs.promises.rm(join(config.FOLDER, dir), {
|
||||
force: true,
|
||||
recursive: true,
|
||||
});
|
||||
@@ -50,7 +50,7 @@ export default class FileSystem implements StorageBase {
|
||||
/** @override */
|
||||
async mk(dir: string): Promise<void> {
|
||||
if (!(await this.exists(dir)))
|
||||
fs.promises.mkdir(path.join(config.FOLDER, dir), { recursive: true });
|
||||
fs.promises.mkdir(join(config.FOLDER, dir), { recursive: true });
|
||||
}
|
||||
|
||||
/** @override */
|
||||
@@ -64,12 +64,12 @@ export default class FileSystem implements StorageBase {
|
||||
if (opt.root == null) {
|
||||
opt.root = config.FOLDER;
|
||||
}
|
||||
let files = await fs.promises.readdir(path.join(opt.root, dir));
|
||||
let files = await fs.promises.readdir(join(opt.root, dir));
|
||||
const output: Tree = {};
|
||||
for (let file of files) {
|
||||
let filePath = path.join(dir, file);
|
||||
let filePath = join(dir, file);
|
||||
try {
|
||||
const stats = await fs.promises.stat(path.join(opt.root, filePath));
|
||||
const stats = await fs.promises.stat(join(opt.root, filePath));
|
||||
if (file[0] == "$") {
|
||||
file = "\\" + file;
|
||||
}
|
||||
@@ -92,12 +92,12 @@ export default class FileSystem implements StorageBase {
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async extractZip(p: string, data: stream.Readable): Promise<void> {
|
||||
const pipeline = promisify(stream.pipeline);
|
||||
return pipeline(
|
||||
async extractZip(p: string, data: Readable): Promise<void> {
|
||||
const pipe = promisify(pipeline);
|
||||
return pipe(
|
||||
data,
|
||||
unzip.Extract({
|
||||
path: path.join(path.join(config.FOLDER, p)),
|
||||
Extract({
|
||||
path: join(join(config.FOLDER, p)),
|
||||
decodeString: (buf) => {
|
||||
const name = buf.toString();
|
||||
const newName = name.substr(name.indexOf("/") + 1);
|
||||
@@ -127,8 +127,8 @@ export default class FileSystem implements StorageBase {
|
||||
}
|
||||
const f = file.path.replace(dir, "");
|
||||
archive.append(rs, {
|
||||
name: path.basename(f),
|
||||
prefix: path.dirname(f),
|
||||
name: basename(f),
|
||||
prefix: dirname(f),
|
||||
});
|
||||
},
|
||||
}).then(() => {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { StorageBase, Tree, TreeFile } from "../types";
|
||||
import { S3 } from "aws-sdk";
|
||||
import config from "../../config";
|
||||
import * as stream from "stream";
|
||||
import { pipeline, Readable } from "stream";
|
||||
import ArchiveStreamToS3 from "decompress-stream-to-s3";
|
||||
import * as express from "express";
|
||||
import * as mime from "mime-types";
|
||||
import { Response } from "express";
|
||||
import { lookup } from "mime-types";
|
||||
import * as flow from "xml-flow";
|
||||
import * as archiver from "archiver";
|
||||
import * as path from "path";
|
||||
import { dirname, basename } from "path";
|
||||
import AnonymousError from "../AnonymousError";
|
||||
|
||||
export default class S3Storage implements StorageBase {
|
||||
@@ -83,7 +83,7 @@ export default class S3Storage implements StorageBase {
|
||||
}
|
||||
|
||||
/** @override */
|
||||
send(p: string, res: express.Response) {
|
||||
send(p: string, res: Response) {
|
||||
const s = this.client
|
||||
.getObject({
|
||||
Bucket: config.S3_BUCKET,
|
||||
@@ -102,8 +102,8 @@ export default class S3Storage implements StorageBase {
|
||||
res.set("Content-Length", headers["content-length"]);
|
||||
res.set("Content-Type", headers["content-type"]);
|
||||
}
|
||||
stream.pipeline(
|
||||
response.httpResponse.createUnbufferedStream() as stream.Readable,
|
||||
pipeline(
|
||||
response.httpResponse.createUnbufferedStream() as Readable,
|
||||
res
|
||||
);
|
||||
});
|
||||
@@ -112,7 +112,7 @@ export default class S3Storage implements StorageBase {
|
||||
}
|
||||
|
||||
/** @override */
|
||||
read(path: string): stream.Readable {
|
||||
read(path: string): Readable {
|
||||
return this.client
|
||||
.getObject({
|
||||
Bucket: config.S3_BUCKET,
|
||||
@@ -128,7 +128,7 @@ export default class S3Storage implements StorageBase {
|
||||
Bucket: config.S3_BUCKET,
|
||||
Key: path,
|
||||
Body: data,
|
||||
ContentType: mime.lookup(path).toString(),
|
||||
ContentType: lookup(path).toString(),
|
||||
})
|
||||
.promise();
|
||||
return;
|
||||
@@ -168,7 +168,7 @@ export default class S3Storage implements StorageBase {
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async extractZip(p: string, data: stream.Readable): Promise<void> {
|
||||
async extractZip(p: string, data: Readable): Promise<void> {
|
||||
let toS3: ArchiveStreamToS3;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -181,8 +181,7 @@ export default class S3Storage implements StorageBase {
|
||||
header.name = header.name.substr(header.name.indexOf("/") + 1);
|
||||
},
|
||||
});
|
||||
stream
|
||||
.pipeline(data, toS3, () => {})
|
||||
pipeline(data, toS3, () => {})
|
||||
.on("finish", resolve)
|
||||
.on("error", reject);
|
||||
});
|
||||
@@ -210,14 +209,14 @@ export default class S3Storage implements StorageBase {
|
||||
xmlStream.on("tag:contents", function (file) {
|
||||
let rs = that.read(file.key);
|
||||
file.key = file.key.replace(dir, "");
|
||||
const filename = path.basename(file.key);
|
||||
const filename = basename(file.key);
|
||||
if (filename == "") return;
|
||||
if (opt?.fileTransformer) {
|
||||
rs = rs.pipe(opt.fileTransformer(filename));
|
||||
}
|
||||
archive.append(rs, {
|
||||
name: filename,
|
||||
prefix: path.dirname(file.key),
|
||||
prefix: dirname(file.key),
|
||||
});
|
||||
});
|
||||
xmlStream.on("end", () => {
|
||||
|
||||
Reference in New Issue
Block a user