Commit 58b9840a authored by rockyl's avatar rockyl

rewrite by ts

parent 777fa58a
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
*/ */
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = require("./logger"); const logger_1 = require("./logger");
const imagemin_1 = require("imagemin"); const imagemin = require("imagemin");
const imagemin_jpegtran_1 = require("imagemin-jpegtran"); const imageminJpegtran = require("imagemin-jpegtran");
const imagemin_pngquant_1 = require("imagemin-pngquant"); const imageminPngquant = require("imagemin-pngquant");
const acceptTypes = ['image/png', 'image/jpeg']; const acceptTypes = ['image/png', 'image/jpeg'];
function applyApi(server) { function applyApi(server) {
server.get('/info', function (req, res, next) { server.get('/info', function (req, res, next) {
...@@ -22,10 +22,10 @@ function applyApi(server) { ...@@ -22,10 +22,10 @@ function applyApi(server) {
if (file) { if (file) {
if (acceptTypes.includes(file.type)) { if (acceptTypes.includes(file.type)) {
try { try {
const buffer = await imagemin_1.default([file.path], { const buffer = await imagemin([file.path], {
plugins: [ plugins: [
imagemin_jpegtran_1.default(), imageminJpegtran(),
imagemin_pngquant_1.default({ imageminPngquant({
quality: [0.6, 0.8] quality: [0.6, 0.8]
}) })
] ]
......
{"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,gBAAgB,EAAE,UAAU,GAAG,E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AAC,GAAG,EAAE,GAAG,CAAC;6BACnB,CAAC;yBACF;qBACD,CAAC,CAAC;oBAEH,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;wBAC3B,cAAc,EAAE,IAAI,CAAC,IAAI;qBACzB,CAAC,CAAC;iBACH;gBAAA,OAAO,CAAC,EAAE;oBACV,gBAAM,CAAC,KAAK,CAAC,SAAS,EAAE,iBAAiB,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;oBACtD,GAAG,CAAC,IAAI,CAAC;wBACR,IAAI,EAAE,CAAC;wBACP,GAAG,EAAE,iBAAiB;qBACtB,CAAC,CAAC;iBACH;aACD;iBAAI;gBACJ,gBAAM,CAAC,KAAK,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;gBACtC,GAAG,CAAC,IAAI,CAAC;oBACR,IAAI,EAAE,CAAC;oBACP,GAAG,EAAE,YAAY;iBACjB,CAAC,CAAC;aACH;SACD;aAAI;YACJ,GAAG,CAAC,IAAI,CAAC;gBACR,IAAI,EAAE,CAAC;gBACP,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 \ No newline at end of file
...@@ -3,21 +3,21 @@ ...@@ -3,21 +3,21 @@
* Created by rockyl on 2020-02-12. * Created by rockyl on 2020-02-12.
*/ */
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const restify_1 = require("restify"); const restify = require('restify');
const eureka_1 = require("./eureka"); const eureka_1 = require("./eureka");
const logger_1 = require("./logger"); const logger_1 = require("./logger");
const api_1 = require("./api"); const api_1 = require("./api");
let [_, __, portStr = '8090'] = process.argv; let [_, __, portStr = '8090'] = process.argv;
let eureka; let eureka;
let port = parseInt(portStr); 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_1.default.info(req.url); logger_1.default.info(req.url);
......
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,qCAA8B;AAC9B,qCAAyC;AACzC,qCAA8B;AAC9B,+BAA6B;AAE7B,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,GAAG,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;AAC7C,IAAI,MAAM,CAAC;AACX,IAAI,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;AAE7B,MAAM,MAAM,GAAG,iBAAO,CAAC,YAAY,CAAC;IACnC,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,OAAO;CAChB,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAE3C,MAAM,CAAC,GAAG,CAAC,iBAAO,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;AAC5D,MAAM,CAAC,GAAG,CAAC,iBAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;AAC1C,MAAM,CAAC,GAAG,CAAC,iBAAO,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;AACzC,MAAM,CAAC,GAAG,CAAC,UAAU,GAAG,EAAE,GAAG,EAAE,IAAI;IAClC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,G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,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
...@@ -4,16 +4,16 @@ ...@@ -4,16 +4,16 @@
*/ */
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const log4js_1 = require("log4js"); const log4js_1 = require("log4js");
const path_1 = require("path"); const path = require("path");
const fs_extra_1 = require("fs-extra"); const fs = require("fs-extra");
const logPath = path_1.default.join(process.env.HOME || process.env.USERPROFILE, 'logs', 'tiny-image'); const logPath = path.join(process.env.HOME || process.env.USERPROFILE, 'logs', 'tiny-image');
fs_extra_1.default.ensureDir(logPath); fs.ensureDir(logPath);
log4js_1.configure({ log4js_1.configure({
appenders: { appenders: {
out: { type: 'console' }, out: { type: 'console' },
allLog: { allLog: {
type: 'dateFile', type: 'dateFile',
filename: path_1.default.join(logPath, 'log.log'), filename: path.join(logPath, 'log.log'),
}, },
}, },
categories: { categories: {
......
{"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"} {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,mCAA4C;AAC5C,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAE/B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,WAAqB,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;AAEvG,EAAE,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,IAAI,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 \ No newline at end of file
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
*/ */
import logger from "./logger"; import logger from "./logger";
import imagemin from "imagemin"; const imagemin = require("imagemin");
import imageminJpegtran from "imagemin-jpegtran"; const imageminJpegtran = require("imagemin-jpegtran");
import imageminPngquant from "imagemin-pngquant"; const imageminPngquant = require("imagemin-pngquant");
const acceptTypes = ['image/png', 'image/jpeg']; const acceptTypes = ['image/png', 'image/jpeg'];
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Created by rockyl on 2020-02-12. * Created by rockyl on 2020-02-12.
*/ */
import restify from 'restify'; const restify = require('restify');
import {getEurekaClient} from "./eureka"; import {getEurekaClient} from "./eureka";
import logger from "./logger"; import logger from "./logger";
import applyApi from "./api"; import applyApi from "./api";
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
*/ */
import {configure, getLogger} from 'log4js'; import {configure, getLogger} from 'log4js';
import path from "path"; const path = require("path");
import fs from "fs-extra"; const fs = require("fs-extra");
const logPath = path.join(process.env.HOME || process.env.USERPROFILE as string, 'logs', 'tiny-image'); const logPath = path.join(process.env.HOME || process.env.USERPROFILE as string, 'logs', 'tiny-image');
......
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