Commit 509d6851 authored by rockyl's avatar rockyl

init

parent 0ca4f5c8
...@@ -7,6 +7,7 @@ const logger_1 = require("./logger"); ...@@ -7,6 +7,7 @@ const logger_1 = require("./logger");
const imagemin = require("imagemin"); const imagemin = require("imagemin");
const imageminJpegtran = require("imagemin-jpegtran"); const imageminJpegtran = require("imagemin-jpegtran");
const imageminPngquant = require("imagemin-pngquant"); const imageminPngquant = require("imagemin-pngquant");
const fs = require('fs-extra');
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) {
...@@ -23,6 +24,7 @@ function applyApi(server) { ...@@ -23,6 +24,7 @@ function applyApi(server) {
if (acceptTypes.includes(file.type)) { if (acceptTypes.includes(file.type)) {
try { try {
console.log(`start compress!`); console.log(`start compress!`);
console.log('file exists:', fs.existsSync(file.path));
const buffer = await imagemin([file.path], { const buffer = await imagemin([file.path], {
plugins: [ plugins: [
imageminJpegtran(), imageminJpegtran(),
......
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,qCAA8B;AAC9B,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACrC,MAAM,gBAAgB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AACtD,MAAM,gBAAgB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAEtD,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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AC;IACf,CAAC,CAAC,CAAC;AACJ,CAAC;AAxDD,2BAwDC"}
\ No newline at end of file \ No newline at end of file
...@@ -6,6 +6,7 @@ import logger from "./logger"; ...@@ -6,6 +6,7 @@ import logger from "./logger";
const imagemin = require("imagemin"); const imagemin = require("imagemin");
const imageminJpegtran = require("imagemin-jpegtran"); const imageminJpegtran = require("imagemin-jpegtran");
const imageminPngquant = require("imagemin-pngquant"); const imageminPngquant = require("imagemin-pngquant");
const fs = require('fs-extra');
const acceptTypes = ['image/png', 'image/jpeg']; const acceptTypes = ['image/png', 'image/jpeg'];
...@@ -27,6 +28,7 @@ export default function applyApi(server){ ...@@ -27,6 +28,7 @@ export default function applyApi(server){
if(acceptTypes.includes(file.type)){ if(acceptTypes.includes(file.type)){
try { try {
console.log(`start compress!`); console.log(`start compress!`);
console.log('file exists:', fs.existsSync(file.path));
const buffer = await imagemin([file.path], { const buffer = await imagemin([file.path], {
plugins: [ plugins: [
imageminJpegtran(), imageminJpegtran(),
......
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