-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b359725
commit 3511193
Showing
14 changed files
with
1,264 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface IStorageManager { | ||
setTest(value: boolean): any; | ||
add(data: string | Buffer, cid: string): Promise<string>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Config } from "../common/Config"; | ||
import { IStorageManager } from "./IStorageManager"; | ||
|
||
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3"; | ||
|
||
/** | ||
* Store data in IPFS. | ||
*/ | ||
export class S3Manager implements IStorageManager { | ||
private test: boolean; | ||
private config: Config; | ||
private s3_client: S3Client; | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
constructor(config: Config) { | ||
this.config = config; | ||
this.s3_client = new S3Client({ | ||
region: this.config.node.s3_region, | ||
credentials: { | ||
accessKeyId: this.config.node.s3_access_key, | ||
secretAccessKey: this.config.node.s3_secret_key, | ||
}, | ||
}); | ||
this.test = false; | ||
} | ||
|
||
/** | ||
* Specifies whether to use it for testing. | ||
* @param value | ||
*/ | ||
public setTest(value: boolean) { | ||
this.test = value; | ||
} | ||
|
||
/** | ||
* Store data in IPFS. | ||
* @param data Data to be stored. | ||
* @param cid | ||
*/ | ||
public add(data: string | Buffer, cid: string): Promise<string> { | ||
return new Promise<string>((resolve, reject) => { | ||
const params = { | ||
Body: data, | ||
Bucket: this.config.node.s3_bucket, | ||
Key: cid, | ||
}; | ||
const command = new PutObjectCommand(params); | ||
this.s3_client | ||
.send(command) | ||
.then(() => { | ||
return resolve(cid); | ||
}) | ||
.catch((reason) => { | ||
console.error(reason); | ||
return reject(new Error(reason)); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.