Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arc 10 #8

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
buckets/
node_modules/
sample-app/public/static.json
sample-app/**/package-lock.json
Expand Down
3,826 changes: 1,416 additions & 2,410 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "arc-plugin-s3-image-bucket",
"version": "1.1.2",
"description": "Architect (arc.codes) serverless framework plugin that creates an S3 bucket that users can upload to directly, with optional Lambda triggers",
"main": "index.js",
"main": "src/index.js",
"scripts": {
"lint": "eslint",
"test:unit": "jasmine --config=test/jasmine.json",
Expand All @@ -26,16 +26,15 @@
},
"homepage": "https://github.com/filmaj/arc-plugin-s3-image-bucket/issues",
"devDependencies": {
"@architect/eslint-config": "^1.0.0",
"@architect/inventory": "^1.3.3",
"@architect/package": "^6.2.1",
"eslint": "^7.19.0",
"fs-extra": "^9.1.0",
"jasmine": "^3.6.4"
"@architect/eslint-config": "^2.0.1",
"@architect/inventory": "^3.0.0-RC.7",
"eslint": "^8.8.0",
"fs-extra": "^10.0.0",
"jasmine": "^4.0.2"
},
"dependencies": {
"@architect/utils": "^2.0.5",
"s3rver": "^3.6.1"
"@architect/utils": "^3.0.4",
"s3rver": "^3.7.1"
},
"eslintConfig": {
"extends": "@architect/eslint-config",
Expand Down
1 change: 1 addition & 0 deletions sample-app/app.arc
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ LambdaOnImageCreate

@plugins
arc-plugin-s3-image-bucket
src ../
6 changes: 4 additions & 2 deletions sample-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"description": "",
"main": "index.js",
"dependencies": {
"@architect/architect": "^8.6.0"
"@architect/architect": "^10.0.0-RC.3",
"@architect/functions": "^5.0.0-RC.1",
"file-type": "^17.1.1",
"gm": "^1.23.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
5 changes: 0 additions & 5 deletions sample-app/src/http/get-index/.arc-config

This file was deleted.

4 changes: 3 additions & 1 deletion sample-app/src/http/get-index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ let form = require('./form');

async function getIndex (req) {
let services = await arc.services();
const redirect = `http${process.env.NODE_ENV === 'testing' ? '' : 's'}://${req.headers.Host || req.headers.host}/success`;
let local = process.env.ARC_ENV === 'testing';
let prot = local ? 'http' : 'https';
const redirect = `${prot}://${req.headers.Host || req.headers.host}/success`;
const { name, accessKey, secretKey } = services['arc-plugin-s3-image-bucket'];
const region = process.env.AWS_REGION;
const upload = form({ redirect, bucket: name, accessKey, secretKey, region });
Expand Down
15 changes: 0 additions & 15 deletions sample-app/src/http/get-index/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion sample-app/src/http/get-index/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const crypto = require('crypto');
// * secretKey
module.exports = function s3Credentials (config, params) {
return {
endpoint: process.env.NODE_ENV === 'testing' ? `http://localhost:4569/${config.bucket}` : `https://${config.bucket}.s3.amazonaws.com`,
endpoint: process.env.ARC_ENV === 'testing' ? `http://localhost:4569/${config.bucket}` : `https://${config.bucket}.s3.amazonaws.com`,
params: s3Params(config, params)
};
};
Expand Down
15 changes: 0 additions & 15 deletions sample-app/src/http/get-success/package.json

This file was deleted.

5 changes: 0 additions & 5 deletions sample-app/src/image-bucket/OnImageCreate/config.arc

This file was deleted.

8 changes: 0 additions & 8 deletions sample-app/src/image-bucket/OnImageCreate/package.json

This file was deleted.

42 changes: 21 additions & 21 deletions sample-app/src/image-bucket/OnImageCreate/thumbnail.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
let aws = require('aws-sdk')
let gm = require('gm')
let aws = require('aws-sdk');
let gm = require('gm');

const MAX_WIDTH = 100
const MAX_HEIGHT = 100
const MAX_WIDTH = 100;
const MAX_HEIGHT = 100;

/**
* if ext is jpg or png write thumb/filename.(png|jpg)
Expand All @@ -14,27 +14,27 @@ const MAX_HEIGHT = 100
* @param {Buffer} body
* @returns {Promise}
*/
module.exports = function thumbnail({bucket, key, mime, ext, body, s3}) {
module.exports = function thumbnail ({ bucket, key, mime, ext, body, s3 }) {

// early exit if this isn't an image
let thumb = ext === 'jpg' || ext === 'png'
let thumb = ext === 'jpg' || ext === 'png';
if (!thumb)
return Promise.resolve()
return Promise.resolve();

// if it is an image resize it
return new Promise(function argh(res, rej) {
let mg = gm.subClass({imageMagick: true})
mg(body).size(function size(err, size) {
if (err) rej(err)
return new Promise(function argh (res, rej) {
let mg = gm.subClass({ imageMagick: true });
mg(body).size(function size (err, size) {
if (err) rej(err);
else {

let scaling = Math.min(MAX_WIDTH / size.width, MAX_HEIGHT / size.height)
let width = scaling * size.width
let height = scaling * size.height
let scaling = Math.min(MAX_WIDTH / size.width, MAX_HEIGHT / size.height);
let width = scaling * size.width;
let height = scaling * size.height;

// resize the file buffer
this.resize(width, height).toBuffer(ext, function resize(err, buffer) {
if (err) rej(err)
this.resize(width, height).toBuffer(ext, function resize (err, buffer) {
if (err) rej(err);
else {

// write the buffer to s3 under thumb/
Expand All @@ -43,10 +43,10 @@ module.exports = function thumbnail({bucket, key, mime, ext, body, s3}) {
Bucket: bucket,
Key: key.replace('raw/', 'thumb/') + '.' + ext,
Body: buffer
}).promise().then(res).catch(rej)
}).promise().then(res).catch(rej);
}
})
});
}
})
})
}
});
});
};
1 change: 0 additions & 1 deletion sample-app/src/plugins/arc-plugin-s3-image-bucket/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion sample-app/src/shared/image-bucket-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const aws = require('aws-sdk');

module.exports = async function (arc) {
let config;
if (process.env.NODE_ENV === 'testing') {
if (process.env.ARC_ENV === 'testing') {
let services = await arc.services();
const { accessKey, secretKey } = services['arc-plugin-s3-image-bucket'];
config = {
Expand Down
Loading