Commit c2ea47a4 authored by rockyl's avatar rockyl

rewrite by ts

parent 29483f95
"use strict";
/**
* Created by rockyl on 2020-02-13.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = require("./logger");
const imagemin_1 = require("imagemin");
const imagemin_jpegtran_1 = require("imagemin-jpegtran");
const imagemin_pngquant_1 = require("imagemin-pngquant");
const acceptTypes = ['image/png', 'image/jpeg'];
function applyApi(server) {
server.get('/info', function (req, res, next) {
res.sendRaw('Tiny image serve is running.');
return next();
});
server.get('/monitor/check', function (req, res, next) {
res.sendRaw('ok');
return next();
});
server.post('/tinify', async function (req, res, next) {
let file = req.files.file;
if (file) {
if (acceptTypes.includes(file.type)) {
try {
const buffer = await imagemin_1.default([file.path], {
plugins: [
imagemin_jpegtran_1.default(),
imagemin_pngquant_1.default({
quality: [0.6, 0.8]
})
]
});
res.sendRaw(buffer[0].data, {
'Content-Type': file.type,
});
}
catch (e) {
logger_1.default.error('/tinify', 'compress failed', e.message);
res.send({
code: 3,
msg: 'compress failed'
});
}
}
else {
logger_1.default.error('/tinify', 'type error');
res.send({
code: 2,
msg: 'type error'
});
}
}
else {
res.send({
code: 1,
msg: 'file not exists'
});
}
return next();
});
}
exports.default = applyApi;
//# sourceMappingURL=api.js.map
\ No newline at end of file
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,qCAA8B;AAC9B,uCAAgC;AAChC,yDAAiD;AACjD,yDAAiD;AAEjD,MAAM,WAAW,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;AAEhD,SAAwB,QAAQ,CAAC,MAAM;IACtC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,EAAE,GAAG,EAAE,IAAI;QAC3C,GAAG,CAAC,OAAO,CAAC,8BAA8B,CAAC,CAAC;QAC5C,OAAO,IAAI,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,GAAG,CAAC,gB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P,GAAG,EAAE,iBAAiB;aACtB,CAAC,CAAC;SACH;QAED,OAAO,IAAI,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;AACJ,CAAC;AApDD,2BAoDC"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const eureka_client_ts_1 = require("eureka-client-ts");
const logger_1 = require("./logger");
const eurekaConfig = {
appName: 'duiba-tiny-image-node',
services: ['duiba-tiny-image-node'],
};
async function getEurekaClient(port) {
eurekaConfig.port = port;
let eureka;
try {
eureka = new eureka_client_ts_1.default(eurekaConfig);
await eureka.start();
}
catch (e) {
logger_1.default.error(e);
}
return eureka;
}
exports.getEurekaClient = getEurekaClient;
//# sourceMappingURL=eureka.js.map
\ No newline at end of file
{"version":3,"file":"eureka.js","sourceRoot":"","sources":["../src/eureka.ts"],"names":[],"mappings":";;AAAA,uDAA4C;AAC5C,qCAA8B;AAE9B,MAAM,YAAY,GAAO;IACvB,OAAO,EAAE,uBAAuB;IAChC,QAAQ,EAAE,CAAC,uBAAuB,CAAC;CACpC,CAAC;AAEK,KAAK,UAAU,eAAe,CAAC,IAAI;IACxC,YAAY,CAAC,IAAI,GAAG,IAAI,CAAC;IACzB,IAAI,MAAM,CAAC;IACX,IAAI;QACF,MAAM,GAAG,IAAI,0BAAY,CAAC,YAAY,CAAC,CAAC;QACxC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;KACtB;IAAC,OAAO,CAAC,EAAE;QACV,gBAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACjB;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAXD,0CAWC"}
\ No newline at end of file
'use strict'; "use strict";
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var restify = _interopDefault(require('restify'));
var Eurekaclient = _interopDefault(require('eureka-client-ts'));
var log4js = require('log4js');
var path = _interopDefault(require('path'));
var fs = _interopDefault(require('fs-extra'));
var imagemin = _interopDefault(require('imagemin'));
var imageminJpegtran = _interopDefault(require('imagemin-jpegtran'));
var imageminPngquant = _interopDefault(require('imagemin-pngquant'));
/**
* Created by rockyl on 2020-02-13.
*/
const logPath = path.join(process.env.HOME || process.env.USERPROFILE, 'logs', 'tiny-image');
fs.ensureDir(logPath);
log4js.configure({
appenders: {
out: {type: 'console'},
allLog: {
type: 'dateFile',
filename: path.join(logPath, 'log.log'),
},
},
categories: {
default: {appenders: ['out', 'allLog'], level: 'debug'},
}
});
const logger = log4js.getLogger();
const eurekaConfig = {
appName: 'duiba-tiny-image-node',
services: ['duiba-tiny-image-node'],
};
async function getEurekaClient(port) {
eurekaConfig.port = port;
let eureka;
try {
eureka = new Eurekaclient(eurekaConfig);
await eureka.start();
} catch (e) {
logger.error(e);
}
return eureka;
}
/**
* Created by rockyl on 2020-02-13.
*/
const acceptTypes = ['image/png', 'image/jpeg'];
function applyApi(server){
server.get('/info', function (req, res, next) {
res.sendRaw('Tiny image serve is running.');
return next();
});
server.get('/monitor/check', function (req, res, next) {
res.sendRaw('ok');
return next();
});
server.post('/tinify', async function (req, res, next) {
let file = req.files.file;
if(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) {
logger.error('/tinify', 'compress failed', e.message);
res.send({
code: 3,
msg: 'compress failed'
});
}
}else{
logger.error('/tinify', 'type error');
res.send({
code: 2,
msg: 'type error'
});
}
}else{
res.send({
code: 1,
msg: 'file not exists'
});
}
return next();
});
}
/** /**
* Created by rockyl on 2020-02-12. * Created by rockyl on 2020-02-12.
*/ */
Object.defineProperty(exports, "__esModule", { value: true });
let [_, __, port = '8090'] = process.argv; const restify_1 = require("restify");
const eureka_1 = require("./eureka");
const logger_1 = require("./logger");
const api_1 = require("./api");
let [_, __, portStr = '8090'] = process.argv;
let eureka; let eureka;
port = parseInt(port); let port = parseInt(portStr);
const server = restify_1.default.createServer({
const server = restify.createServer({
name: 'tiny-image', name: 'tiny-image',
version: '1.0.0' version: '1.0.0'
}); });
const ignoreUrlLogger = ['/monitor/check']; const ignoreUrlLogger = ['/monitor/check'];
server.use(restify_1.default.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.acceptParser(server.acceptable)); server.use(restify_1.default.plugins.queryParser());
server.use(restify.plugins.queryParser()); server.use(restify_1.default.plugins.bodyParser());
server.use(restify.plugins.bodyParser());
server.use(function (req, res, next) { server.use(function (req, res, next) {
if (!ignoreUrlLogger.includes(req.url)) { if (!ignoreUrlLogger.includes(req.url)) {
logger.info(req.url); logger_1.default.info(req.url);
} }
return next(); return next();
}); });
api_1.default(server);
applyApi(server);
process.on('uncaughtException', (err) => { process.on('uncaughtException', (err) => {
logger.error(err); logger_1.default.error(err);
}); });
process.on("SIGTERM", () => { process.on("SIGTERM", () => {
eureka.stop(); eureka.stop();
setTimeout(() => { setTimeout(() => {
process.exit(1); process.exit(1);
}, 6000); }, 6000);
}); });
server.listen(port, async function () { server.listen(port, async function () {
try { try {
eureka = await getEurekaClient(port); eureka = await eureka_1.getEurekaClient(port);
logger.info('eureka register success'); logger_1.default.info('eureka register success');
} catch (e) { }
logger.error(e.name); catch (e) {
logger_1.default.error(e.name);
} }
logger.info('%s listening at %s', server.name, server.url); logger_1.default.info('%s listening at %s', server.name, server.url);
}); });
//# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map
\ No newline at end of file
{"version":3,"file":"index.js","sources":["../src/logger.js","../src/eureka.js","../src/api.js","../src/index.js"],"sourcesContent":["/**\n * Created by rockyl on 2020-02-13.\n */\n\nimport {configure, getLogger} from 'log4js';\nimport path from \"path\";\nimport fs from \"fs-extra\";\n\nconst logPath = path.join(process.env.HOME || process.env.USERPROFILE, 'logs', 'tiny-image');\n\nfs.ensureDir(logPath);\n\nconfigure({\n\tappenders: {\n\t\tout: {type: 'console'},\n\t\tallLog: {\n\t\t\ttype: 'dateFile',\n\t\t\tfilename: path.join(logPath, 'log.log'),\n\t\t},\n\t},\n\tcategories: {\n\t\tdefault: {appenders: ['out', 'allLog'], level: 'debug'},\n\t}\n\n});\n\nconst logger = getLogger();\n\nexport default logger;","import Eurekaclient from 'eureka-client-ts';\nimport logger from './logger';\n\nconst eurekaConfig = {\n appName: 'duiba-tiny-image-node',\n services: ['duiba-tiny-image-node'],\n};\n\nexport async function getEurekaClient(port) {\n eurekaConfig.port = port;\n let eureka;\n try {\n eureka = new Eurekaclient(eurekaConfig);\n await eureka.start();\n } catch (e) {\n logger.error(e);\n }\n\n return eureka;\n}\n","/**\n * Created by rockyl on 2020-02-13.\n */\n\nimport logger from \"./logger\";\nimport imagemin from \"imagemin\";\nimport imageminJpegtran from \"imagemin-jpegtran\";\nimport imageminPngquant from \"imagemin-pngquant\";\n\nconst acceptTypes = ['image/png', 'image/jpeg'];\n\nexport default function applyApi(server){\n\tserver.get('/info', function (req, res, next) {\n\t\tres.sendRaw('Tiny image serve is running.');\n\t\treturn next();\n\t});\n\n\tserver.get('/monitor/check', function (req, res, next) {\n\t\tres.sendRaw('ok');\n\t\treturn next();\n\t});\n\n\tserver.post('/tinify', async function (req, res, next) {\n\t\tlet file = req.files.file;\n\n\t\tif(file){\n\t\t\tif(acceptTypes.includes(file.type)){\n\t\t\t\ttry {\n\t\t\t\t\tconst buffer = await imagemin([file.path], {\n\t\t\t\t\t\tplugins: [\n\t\t\t\t\t\t\timageminJpegtran(),\n\t\t\t\t\t\t\timageminPngquant({\n\t\t\t\t\t\t\t\tquality: [0.6, 0.8]\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t]\n\t\t\t\t\t});\n\n\t\t\t\t\tres.sendRaw(buffer[0].data, {\n\t\t\t\t\t\t'Content-Type': file.type,\n\t\t\t\t\t});\n\t\t\t\t}catch (e) {\n\t\t\t\t\tlogger.error('/tinify', 'compress failed', e.message);\n\t\t\t\t\tres.send({\n\t\t\t\t\t\tcode: 3,\n\t\t\t\t\t\tmsg: 'compress failed'\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tlogger.error('/tinify', 'type error');\n\t\t\t\tres.send({\n\t\t\t\t\tcode: 2,\n\t\t\t\t\tmsg: 'type error'\n\t\t\t\t});\n\t\t\t}\n\t\t}else{\n\t\t\tres.send({\n\t\t\t\tcode: 1,\n\t\t\t\tmsg: 'file not exists'\n\t\t\t});\n\t\t}\n\n\t\treturn next();\n\t});\n}","/**\n * Created by rockyl on 2020-02-12.\n */\n\nimport restify from 'restify';\nimport {getEurekaClient} from \"./eureka\";\nimport logger from \"./logger\";\nimport applyApi from \"./api\";\n\nlet [_, __, port = '8090'] = process.argv;\nlet eureka;\nport = parseInt(port);\n\nconst server = restify.createServer({\n\tname: 'tiny-image',\n\tversion: '1.0.0'\n});\n\nconst ignoreUrlLogger = ['/monitor/check'];\n\nserver.use(restify.plugins.acceptParser(server.acceptable));\nserver.use(restify.plugins.queryParser());\nserver.use(restify.plugins.bodyParser());\nserver.use(function (req, res, next) {\n\tif (!ignoreUrlLogger.includes(req.url)) {\n\t\tlogger.info(req.url);\n\t}\n\treturn next();\n});\n\napplyApi(server);\n\nprocess.on('uncaughtException', (err) => {\n\tlogger.error(err);\n});\n\nprocess.on(\"SIGTERM\", () => {\n\teureka.stop();\n\tsetTimeout(() => {\n\t\tprocess.exit(1)\n\t}, 6000);\n});\n\nserver.listen(port, async function () {\n\ttry {\n\t\teureka = await getEurekaClient(port);\n\t\tlogger.info('eureka register success');\n\t} catch (e) {\n\t\tlogger.error(e.name);\n\t}\n\tlogger.info('%s listening at %s', server.name, server.url);\n});\n\n\n"],"names":["configure","getLogger"],"mappings":";;;;;;;;;;;;;AAAA;;;AAGA,AAIA;AACA,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;;AAE7F,EAAE,CAAC,SA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AAI,CAAC,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAa,CAAC,EAAE;QACjD,gBAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KACrB;IACD,OAAO,IAAI,EAAE,CAAC;AACf,CAAC,CAAC,CAAC;AAEH,aAAQ,CAAC,MAAM,CAAC,CAAC;AAEjB,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;IACvC,gBAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACnB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;IAC1B,MAAM,CAAC,IAAI,EAAE,CAAC;IACd,UAAU,CAAC,GAAG,EAAE;QACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAChB,CAAC,EAAE,IAAI,CAAC,CAAC;AACV,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK;IACxB,IAAI;QACH,MAAM,GAAG,MAAM,wBAAe,CAAC,IAAI,CAAC,CAAC;QACrC,gBAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;KACvC;IAAC,OAAO,CAAC,EAAE;QACX,gBAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;KACrB;IACD,gBAAM,CAAC,IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;AAC5D,CAAC,CAAC,CAAC"}
\ No newline at end of file \ No newline at end of file
"use strict";
/**
* Created by rockyl on 2020-02-13.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const log4js_1 = require("log4js");
const path_1 = require("path");
const fs_extra_1 = require("fs-extra");
const logPath = path_1.default.join(process.env.HOME || process.env.USERPROFILE, 'logs', 'tiny-image');
fs_extra_1.default.ensureDir(logPath);
log4js_1.configure({
appenders: {
out: { type: 'console' },
allLog: {
type: 'dateFile',
filename: path_1.default.join(logPath, 'log.log'),
},
},
categories: {
default: { appenders: ['out', 'allLog'], level: 'debug' },
}
});
const logger = log4js_1.getLogger();
exports.default = logger;
//# sourceMappingURL=logger.js.map
\ No newline at end of file
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,mCAA4C;AAC5C,+BAAwB;AACxB,uCAA0B;AAE1B,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,WAAqB,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;AAEvG,kBAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AAEtB,kBAAS,CAAC;IACT,SAAS,EAAE;QACV,GAAG,EAAE,EAAC,IAAI,EAAE,SAAS,EAAC;QACtB,MAAM,EAAE;YACP,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC;SACvC;KACD;IACD,UAAU,EAAE;QACX,OAAO,EAAE,EAAC,SAAS,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,KAAK,EAAE,OAAO,EAAC;KACvD;CAED,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,kBAAS,EAAE,CAAC;AAE3B,kBAAe,MAAM,CAAC"}
\ No newline at end of file
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
<module type="WEB_MODULE" version="4"> <module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$/../duiba-tiny-image-node" /> <content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
{ {
"name": "duiba-tiny-image-node", "name": "duiba-tiny-image-node",
"version": "1.0.0", "version": "1.0.0",
"main": "index.js", "main": "dist/index.js",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@types/fs-extra": "^9.0.2",
"@types/restify": "^8.4.2",
"eureka-client-ts": "^0.2.10", "eureka-client-ts": "^0.2.10",
"fs-extra": "^8.1.0", "fs-extra": "^8.1.0",
"imagemin": "^7.0.1", "imagemin": "^7.0.1",
"imagemin-jpegtran": "^6.0.0", "imagemin-jpegtran": "^6.0.0",
"imagemin-pngquant": "^8.0.0", "imagemin-pngquant": "^8.0.0",
"is-jpg": "^2.0.0",
"is-png": "^2.0.0",
"log4js": "^6.1.2", "log4js": "^6.1.2",
"restify": "^8.5.1" "restify": "^8.5.1"
}, },
"scripts": { "scripts": {
"dev": "rollup -c -w", "dev": "tsc -w",
"build:rollup": "rollup -c",
"build": "npm install", "build": "npm install",
"clean": "rm -rf node_modules", "clean": "rm -rf node_modules",
"start": "node dist/index.js" "start": "node dist/index.js"
......
/**
* 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;
import Eurekaclient from 'eureka-client-ts'; import Eurekaclient from 'eureka-client-ts';
import logger from './logger'; import logger from './logger';
const eurekaConfig = { const eurekaConfig:any = {
appName: 'duiba-tiny-image-node', appName: 'duiba-tiny-image-node',
services: ['duiba-tiny-image-node'], services: ['duiba-tiny-image-node'],
}; };
......
...@@ -7,9 +7,9 @@ import {getEurekaClient} from "./eureka"; ...@@ -7,9 +7,9 @@ import {getEurekaClient} from "./eureka";
import logger from "./logger"; import logger from "./logger";
import applyApi from "./api"; import applyApi from "./api";
let [_, __, port = '8090'] = process.argv; let [_, __, portStr = '8090'] = process.argv;
let eureka; let eureka;
port = parseInt(port); let port = parseInt(portStr);
const server = restify.createServer({ const server = restify.createServer({
name: 'tiny-image', name: 'tiny-image',
...@@ -22,7 +22,7 @@ server.use(restify.plugins.acceptParser(server.acceptable)); ...@@ -22,7 +22,7 @@ server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.queryParser()); server.use(restify.plugins.queryParser());
server.use(restify.plugins.bodyParser()); server.use(restify.plugins.bodyParser());
server.use(function (req, res, next) { server.use(function (req, res, next) {
if (!ignoreUrlLogger.includes(req.url)) { if (!ignoreUrlLogger.includes(req.url as string)) {
logger.info(req.url); logger.info(req.url);
} }
return next(); return next();
......
...@@ -6,7 +6,7 @@ import {configure, getLogger} from 'log4js'; ...@@ -6,7 +6,7 @@ import {configure, getLogger} from 'log4js';
import path from "path"; import path from "path";
import fs from "fs-extra"; import fs from "fs-extra";
const logPath = path.join(process.env.HOME || process.env.USERPROFILE, 'logs', 'tiny-image'); const logPath = path.join(process.env.HOME || process.env.USERPROFILE as string, 'logs', 'tiny-image');
fs.ensureDir(logPath); fs.ensureDir(logPath);
......
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"allowJs": true,
"experimentalDecorators": true,
"lib": ["esnext", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"noImplicitAny": false,
"noUnusedLocals": false,
"outDir": "dist/",
"preserveConstEnums": true,
"removeComments": false,
"sourceMap": true,
"strictNullChecks": true,
"target": "ES2017",
"traceResolution": false,
"types" : ["node"]
},
"include": [
"./src"
]
}
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