Commit 9f56ba15 authored by rockyl's avatar rockyl

init

parents
Pipeline #207964 failed with stages
in 0 seconds
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var restify = _interopDefault(require('restify'));
var imagemin = _interopDefault(require('imagemin'));
var imageminJpegtran = _interopDefault(require('imagemin-jpegtran'));
var imageminPngquant = _interopDefault(require('imagemin-pngquant'));
/**
* Created by rockyl on 2020-02-12.
*/
let [_, __, port = '8090'] = process.argv;
const acceptTypes = ['image/png', 'image/jpeg'];
const server = restify.createServer({
name: 'tiny-image',
version: '1.0.0'
});
server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.queryParser());
server.use(restify.plugins.bodyParser());
server.get('/echo/:name', function (req, res, next) {
res.send(req.params);
return next();
});
server.post('/tinify', async function (req, res, next) {
let file = req.files.file;
if(acceptTypes.includes(file.type)){
try {
const buffer = await imagemin([file.path], {
plugins: [
imageminJpegtran(),
imageminPngquant({
quality: [0.6, 0.8]
})
]
});
res.sendRaw(buffer[0].data, {
'Content-Type': file.type,
});
}catch (e) {
res.send({
code: 2,
msg: 'compress failed'
});
}
}else{
res.send({
code: 1,
msg: 'type error'
});
}
return next();
});
server.listen(parseInt(port), function () {
console.log('%s listening at %s', server.name, server.url);
});
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["/**\n * Created by rockyl on 2020-02-12.\n */\n\nimport restify from 'restify';\nimport imagemin from 'imagemin';\nimport imageminJpegtran from 'imagemin-jpegtran';\nimport imageminPngquant from 'imagemin-pngquant';\n\nlet [_, __, port = '8090'] = process.argv;\n\nconst acceptTypes = ['image/png', 'image/jpeg'];\n\nconst server = restify.createServer({\n\tname: 'tiny-image',\n\tversion: '1.0.0'\n});\n\nserver.use(restify.plugins.acceptParser(server.acceptable));\nserver.use(restify.plugins.queryParser());\nserver.use(restify.plugins.bodyParser());\n\nserver.get('/echo/:name', function (req, res, next) {\n\tres.send(req.params);\n\treturn next();\n});\n\nserver.post('/tinify', async function (req, res, next) {\n\tlet file = req.files.file;\n\n\tif(acceptTypes.includes(file.type)){\n\t\ttry {\n\t\t\tconst buffer = await imagemin([file.path], {\n\t\t\t\tplugins: [\n\t\t\t\t\timageminJpegtran(),\n\t\t\t\t\timageminPngquant({\n\t\t\t\t\t\tquality: [0.6, 0.8]\n\t\t\t\t\t})\n\t\t\t\t]\n\t\t\t});\n\n\t\t\tres.sendRaw(buffer[0].data, {\n\t\t\t\t'Content-Type': file.type,\n\t\t\t});\n\t\t}catch (e) {\n\t\t\tres.send({\n\t\t\t\tcode: 2,\n\t\t\t\tmsg: 'compress failed'\n\t\t\t});\n\t\t}\n\t}else{\n\t\tres.send({\n\t\t\tcode: 1,\n\t\t\tmsg: 'type error'\n\t\t});\n\t}\n\n\treturn next();\n});\n\nserver.listen(parseInt(port), function () {\n\tconsole.log('%s listening at %s', server.name, server.url);\n});\n"],"names":[],"mappings":";;;;;;;;;AAAA;;;AAGA,AAKA;AACA,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,GAAG,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;;AAE1C,MAAM,WAAW,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;;AAEhD,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CACnC,IAAI,EAAE,YAAY;CAClB,OAAO,EAAE,OAAO;CAChB,CAAC,CAAC;;AAEH,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;AAC5D,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;AAC1C,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;;AAEzC,MAAM,CAAC,GAAG,CAAC,aAAa,EAAE,UAAU,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE;CACnD,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CACrB,OAAO,IAAI,EAAE,CAAC;CACd,CAAC,CAAC;;AAEH,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE;CACvD,IAAI,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC;;CAE1B,GAAG,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;EAClC,IAAI;GACH,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;IAC1C,OAAO,EAAE;KACR,gBAAgB,EAAE;KAClB,gBAAgB,CAAC;MAChB,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;MACnB,CAAC;KACF;IACD,CAAC,CAAC;;GAEH,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;IAC3B,cAAc,EAAE,IAAI,CAAC,IAAI;IACzB,CAAC,CAAC;GACH,OAAO,CAAC,EAAE;GACV,GAAG,CAAC,IAAI,CAAC;IACR,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,iBAAiB;IACtB,CAAC,CAAC;GACH;EACD,IAAI;EACJ,GAAG,CAAC,IAAI,CAAC;GACR,IAAI,EAAE,CAAC;GACP,GAAG,EAAE,YAAY;GACjB,CAAC,CAAC;EACH;;CAED,OAAO,IAAI,EAAE,CAAC;CACd,CAAC,CAAC;;AAEH,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,YAAY;CACzC,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;CAC3D,CAAC,CAAC"}
\ No newline at end of file
This diff is collapsed.
{
"name": "tiny-image",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"imagemin": "^7.0.1",
"imagemin-jpegtran": "^6.0.0",
"imagemin-pngquant": "^8.0.0",
"jpegtran-bin": "^4.0.0",
"restify": "^8.5.1"
},
"scripts": {
"dev": "rollup -c -w",
"build": "rollup -c",
"start": "node dist/index.js"
},
"devDependencies": {
"rollup-plugin-progress": "^1.1.1"
}
}
/**
* Created by rockyl on 2018/11/16.
*/
const progress = require('rollup-plugin-progress');
const options = {
input: 'src/index.js',
output: [
{
file: `dist/index.js`,
format: 'cjs',
sourcemap: true,
}
],
plugins: [
progress(),
],
};
export default options;
/**
* Created by rockyl on 2020-02-12.
*/
import restify from 'restify';
import imagemin from 'imagemin';
import imageminJpegtran from 'imagemin-jpegtran';
import imageminPngquant from 'imagemin-pngquant';
let [_, __, port = '8090'] = process.argv;
const acceptTypes = ['image/png', 'image/jpeg'];
const server = restify.createServer({
name: 'tiny-image',
version: '1.0.0'
});
server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.queryParser());
server.use(restify.plugins.bodyParser());
server.get('/echo/:name', function (req, res, next) {
res.send(req.params);
return next();
});
server.post('/tinify', async function (req, res, next) {
let file = req.files.file;
if(acceptTypes.includes(file.type)){
try {
const buffer = await imagemin([file.path], {
plugins: [
imageminJpegtran(),
imageminPngquant({
quality: [0.6, 0.8]
})
]
});
res.sendRaw(buffer[0].data, {
'Content-Type': file.type,
});
}catch (e) {
res.send({
code: 2,
msg: 'compress failed'
});
}
}else{
res.send({
code: 1,
msg: 'type error'
});
}
return next();
});
server.listen(parseInt(port), function () {
console.log('%s listening at %s', server.name, server.url);
});
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment