Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhicheng Chen committed Mar 25, 2019
1 parent fb86f3f commit cfaf9b9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# snatch-server
Snatch backend node server base on expressjs.

This is the backend of [Snatch](https://github.com/ZhichengChen/snatch), Snatch is a Sketch plugin that upload layer to CDN directly.

## Usage

Install the dependencies

```bash
npm install
```

Once the installation is done, you can run the server:

```bash
node index.js
```

40 changes: 40 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const sharp = require('sharp');

app.use(bodyParser.urlencoded({extended: false, limit: '50mb'}))
app.use(bodyParser.json({limit:'50mb'}))

const boostSize = {
'pic_wheel': [353, 353, 'png'],
'pic_arrow': [45, 60, 'png'],
'btn_luckydraw': [292, 77, 'png'],
'bg_blue': [360, 640, 'jpg']
}

app.post('/', function(req, res) {
const size = boostSize[req.body.name];
if (!size) {
return res.send('Name invalid!');
}
let buff = new Buffer(req.body.image, 'base64');
let resize = sharp(buff)
.resize(size[0], size[1]);
if (size[2]=='jpg') {
resize = resize.jpeg();
} else {
resize = resize.png({adaptiveFiltering: true})
}
resize.toFile(req.body.name+'.'+size[2], (err) => {
if (err) {
return res.send(err);
} else {
return res.send('Upload Success!');
}
});
});

app.listen(3000, function(){
console.log('ok.');
});
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "snatch-server",
"version": "1.0.0",
"description": "Snatch backend node server base on expressjs.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "chenzhicheng.com",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.4",
"sharp": "^0.22.0"
}
}

0 comments on commit cfaf9b9

Please sign in to comment.