mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-05 05:08:07 +02:00
try to resolve unassessible website
This commit is contained in:
+13
-12
@@ -21,14 +21,14 @@ export default class S3Storage implements StorageBase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get client() {
|
private client(timeout = 5000) {
|
||||||
return new S3({
|
return new S3({
|
||||||
region: config.S3_REGION,
|
region: config.S3_REGION,
|
||||||
endpoint: config.S3_ENDPOINT,
|
endpoint: config.S3_ENDPOINT,
|
||||||
accessKeyId: config.S3_CLIENT_ID,
|
accessKeyId: config.S3_CLIENT_ID,
|
||||||
secretAccessKey: config.S3_CLIENT_SECRET,
|
secretAccessKey: config.S3_CLIENT_SECRET,
|
||||||
httpOptions: {
|
httpOptions: {
|
||||||
timeout: 1000 * 60 * 60 * 2, // 2 hour
|
timeout,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ export default class S3Storage implements StorageBase {
|
|||||||
async exists(path: string): Promise<boolean> {
|
async exists(path: string): Promise<boolean> {
|
||||||
if (!config.S3_BUCKET) throw new Error("S3_BUCKET not set");
|
if (!config.S3_BUCKET) throw new Error("S3_BUCKET not set");
|
||||||
try {
|
try {
|
||||||
await this.client
|
await this.client()
|
||||||
.headObject({
|
.headObject({
|
||||||
Bucket: config.S3_BUCKET,
|
Bucket: config.S3_BUCKET,
|
||||||
Key: path,
|
Key: path,
|
||||||
@@ -46,7 +46,7 @@ export default class S3Storage implements StorageBase {
|
|||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// check if it is a directory
|
// check if it is a directory
|
||||||
const data = await this.client
|
const data = await this.client()
|
||||||
.listObjectsV2({
|
.listObjectsV2({
|
||||||
Bucket: config.S3_BUCKET,
|
Bucket: config.S3_BUCKET,
|
||||||
Prefix: path,
|
Prefix: path,
|
||||||
@@ -65,7 +65,7 @@ export default class S3Storage implements StorageBase {
|
|||||||
/** @override */
|
/** @override */
|
||||||
async rm(dir: string): Promise<void> {
|
async rm(dir: string): Promise<void> {
|
||||||
if (!config.S3_BUCKET) throw new Error("S3_BUCKET not set");
|
if (!config.S3_BUCKET) throw new Error("S3_BUCKET not set");
|
||||||
const data = await this.client
|
const data = await this.client()
|
||||||
.listObjectsV2({
|
.listObjectsV2({
|
||||||
Bucket: config.S3_BUCKET,
|
Bucket: config.S3_BUCKET,
|
||||||
Prefix: dir,
|
Prefix: dir,
|
||||||
@@ -88,7 +88,7 @@ export default class S3Storage implements StorageBase {
|
|||||||
// nothing to remove
|
// nothing to remove
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.client.deleteObjects(params).promise();
|
await this.client().deleteObjects(params).promise();
|
||||||
|
|
||||||
if (data.IsTruncated) {
|
if (data.IsTruncated) {
|
||||||
await this.rm(dir);
|
await this.rm(dir);
|
||||||
@@ -98,7 +98,7 @@ export default class S3Storage implements StorageBase {
|
|||||||
/** @override */
|
/** @override */
|
||||||
send(p: string, res: Response) {
|
send(p: string, res: Response) {
|
||||||
if (!config.S3_BUCKET) throw new Error("S3_BUCKET not set");
|
if (!config.S3_BUCKET) throw new Error("S3_BUCKET not set");
|
||||||
const s = this.client
|
const s = this.client()
|
||||||
.getObject({
|
.getObject({
|
||||||
Bucket: config.S3_BUCKET,
|
Bucket: config.S3_BUCKET,
|
||||||
Key: p,
|
Key: p,
|
||||||
@@ -125,7 +125,7 @@ export default class S3Storage implements StorageBase {
|
|||||||
/** @override */
|
/** @override */
|
||||||
read(path: string): Readable {
|
read(path: string): Readable {
|
||||||
if (!config.S3_BUCKET) throw new Error("S3_BUCKET not set");
|
if (!config.S3_BUCKET) throw new Error("S3_BUCKET not set");
|
||||||
return this.client
|
return this.client(3000)
|
||||||
.getObject({
|
.getObject({
|
||||||
Bucket: config.S3_BUCKET,
|
Bucket: config.S3_BUCKET,
|
||||||
Key: path,
|
Key: path,
|
||||||
@@ -150,7 +150,8 @@ export default class S3Storage implements StorageBase {
|
|||||||
if (source) {
|
if (source) {
|
||||||
params.Tagging = `source=${source.type}`;
|
params.Tagging = `source=${source.type}`;
|
||||||
}
|
}
|
||||||
await this.client.putObject(params).promise();
|
// 30s timeout
|
||||||
|
await this.client(30000).putObject(params).promise();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,7 +160,7 @@ export default class S3Storage implements StorageBase {
|
|||||||
if (!config.S3_BUCKET) throw new Error("S3_BUCKET not set");
|
if (!config.S3_BUCKET) throw new Error("S3_BUCKET not set");
|
||||||
if (dir && dir[dir.length - 1] != "/") dir = dir + "/";
|
if (dir && dir[dir.length - 1] != "/") dir = dir + "/";
|
||||||
const out: Tree = {};
|
const out: Tree = {};
|
||||||
const req = await this.client
|
const req = await this.client(30000)
|
||||||
.listObjectsV2({
|
.listObjectsV2({
|
||||||
Bucket: config.S3_BUCKET,
|
Bucket: config.S3_BUCKET,
|
||||||
Prefix: dir,
|
Prefix: dir,
|
||||||
@@ -205,7 +206,7 @@ export default class S3Storage implements StorageBase {
|
|||||||
toS3 = new ArchiveStreamToS3({
|
toS3 = new ArchiveStreamToS3({
|
||||||
bucket: config.S3_BUCKET,
|
bucket: config.S3_BUCKET,
|
||||||
prefix: p,
|
prefix: p,
|
||||||
s3: this.client,
|
s3: this.client(2 * 60 * 60 * 1000), // 2h timeout
|
||||||
type: "zip",
|
type: "zip",
|
||||||
onEntry: (header) => {
|
onEntry: (header) => {
|
||||||
header.name = header.name.substr(header.name.indexOf("/") + 1);
|
header.name = header.name.substr(header.name.indexOf("/") + 1);
|
||||||
@@ -231,7 +232,7 @@ export default class S3Storage implements StorageBase {
|
|||||||
if (!config.S3_BUCKET) throw new Error("S3_BUCKET not set");
|
if (!config.S3_BUCKET) throw new Error("S3_BUCKET not set");
|
||||||
const archive = archiver(opt?.format || "zip", {});
|
const archive = archiver(opt?.format || "zip", {});
|
||||||
if (dir && dir[dir.length - 1] != "/") dir = dir + "/";
|
if (dir && dir[dir.length - 1] != "/") dir = dir + "/";
|
||||||
const req = this.client.listObjectsV2({
|
const req = this.client(30000).listObjectsV2({
|
||||||
Bucket: config.S3_BUCKET,
|
Bucket: config.S3_BUCKET,
|
||||||
Prefix: dir,
|
Prefix: dir,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user