mirror of
https://github.com/ivabus/www
synced 2024-11-22 23:15:08 +03:00
convert ipfs uploader to typscript
This commit is contained in:
parent
b0623c52a6
commit
14d6f79d75
5 changed files with 992 additions and 606 deletions
|
@ -9,6 +9,9 @@
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14.15.0"
|
"node": ">=14.15.0"
|
||||||
},
|
},
|
||||||
|
"resolutions": {
|
||||||
|
"node-fetch": "2.6.7"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@middy/core": "^3.4.0",
|
"@middy/core": "^3.4.0",
|
||||||
"@middy/http-json-body-parser": "^3.4.0",
|
"@middy/http-json-body-parser": "^3.4.0",
|
||||||
|
@ -18,9 +21,9 @@
|
||||||
"aws-sdk": "^2.1239.0",
|
"aws-sdk": "^2.1239.0",
|
||||||
"axios": "^1.1.3",
|
"axios": "^1.1.3",
|
||||||
"compare-versions": "^5.0.1",
|
"compare-versions": "^5.0.1",
|
||||||
"ipfs-http-client": "^59.0.0",
|
"ipfs-http-client": "40.0.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"node-fetch": "^3.2.10"
|
"node-fetch": "2.6.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@serverless/typescript": "^3.0.0",
|
"@serverless/typescript": "^3.0.0",
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
import AWS from 'aws-sdk';
|
import AWS from 'aws-sdk';
|
||||||
import { S3CreateEvent } from 'aws-lambda';
|
import { S3CreateEvent } from 'aws-lambda';
|
||||||
import { create } from 'ipfs-http-client';
|
import ipfs from 'ipfs-http-client';
|
||||||
|
|
||||||
const s3 = new AWS.S3();
|
const s3 = new AWS.S3();
|
||||||
|
|
||||||
const ipfsUpload = async (event: S3CreateEvent) => {
|
const ipfsUpload = async (event: S3CreateEvent) => {
|
||||||
const http = create({ url: process.env.IPFS_IP4_ADDRESS });
|
const http = ipfs(process.env.IPFS_IP4_ADDRESS);
|
||||||
|
|
||||||
// S3 interaction
|
// S3 interaction
|
||||||
for (const record of event.Records){
|
for (const record of event.Records){
|
||||||
try {
|
try {
|
||||||
const isPackage = record.s3.object.key.split('/').length > 0;
|
const { key } = record.s3.object;
|
||||||
const isCid = record.s3.object.key.includes('.cid');
|
const isPackage = key.split('/').length > 1;
|
||||||
|
const isCid = key.includes('.cid');
|
||||||
if(!isPackage || isCid) continue
|
if(!isPackage || isCid) continue
|
||||||
|
|
||||||
// const objectURL = "https://" + process.env.BUCKET + ".s3.amazonaws.com/" + record.s3.object.key
|
// const objectURL = "https://" + process.env.BUCKET + ".s3.amazonaws.com/" + record.s3.object.key
|
||||||
|
|
|
@ -4,13 +4,30 @@ import { handlerPath } from '@libs/handler-resolver';
|
||||||
export default {
|
export default {
|
||||||
handler: `${handlerPath(__dirname)}/handler.main`,
|
handler: `${handlerPath(__dirname)}/handler.main`,
|
||||||
events: [
|
events: [
|
||||||
// {
|
{
|
||||||
// s3: {
|
s3: {
|
||||||
// bucket: '${ssm:AW5_S3_BUCKET}',
|
bucket: '${ssm:AW5_S3_BUCKET}',
|
||||||
// existing: true,
|
existing: true,
|
||||||
// event: 's3:ObjectCreated:*'
|
event: 's3:ObjectCreated:Post',
|
||||||
// }
|
rules: [
|
||||||
// }
|
{
|
||||||
|
suffix: '.gz'
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
s3: {
|
||||||
|
bucket: '${ssm:AW5_S3_BUCKET}',
|
||||||
|
existing: true,
|
||||||
|
event: 's3:ObjectCreated:Post',
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
suffix: '.xz'
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
environment: {
|
environment: {
|
||||||
AWS_DIST_BUCKET: '${ssm:AW5_S3_BUCKET}',
|
AWS_DIST_BUCKET: '${ssm:AW5_S3_BUCKET}',
|
||||||
|
|
25
lambdas/src/functions/ipfsUpload/mock.json
Normal file
25
lambdas/src/functions/ipfsUpload/mock.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"Records": [
|
||||||
|
{
|
||||||
|
"s3": {
|
||||||
|
"object": {
|
||||||
|
"key": "zlib.net/v1.2.12.tar.gz"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"s3": {
|
||||||
|
"object": {
|
||||||
|
"key": "test/test.cid"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"s3": {
|
||||||
|
"object": {
|
||||||
|
"key": "packages.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
1522
lambdas/yarn.lock
1522
lambdas/yarn.lock
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue