Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tiny-image
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
tiny-image
Commits
dfdb6f5d
Commit
dfdb6f5d
authored
Feb 13, 2020
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
日志文件修改
parent
5cdbd1fd
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
134 additions
and
100 deletions
+134
-100
index.js
dist/index.js
+65
-49
index.js.map
dist/index.js.map
+1
-1
api.js
src/api.js
+59
-0
index.js
src/index.js
+2
-46
logger.js
src/logger.js
+7
-4
No files found.
dist/index.js
View file @
dfdb6f5d
...
@@ -3,13 +3,13 @@
...
@@ -3,13 +3,13 @@
function
_interopDefault
(
ex
)
{
return
(
ex
&&
(
typeof
ex
===
'object'
)
&&
'default'
in
ex
)
?
ex
[
'default'
]
:
ex
;
}
function
_interopDefault
(
ex
)
{
return
(
ex
&&
(
typeof
ex
===
'object'
)
&&
'default'
in
ex
)
?
ex
[
'default'
]
:
ex
;
}
var
restify
=
_interopDefault
(
require
(
'restify'
));
var
restify
=
_interopDefault
(
require
(
'restify'
));
var
imagemin
=
_interopDefault
(
require
(
'imagemin'
));
var
imageminJpegtran
=
_interopDefault
(
require
(
'imagemin-jpegtran'
));
var
imageminPngquant
=
_interopDefault
(
require
(
'imagemin-pngquant'
));
var
Eurekaclient
=
_interopDefault
(
require
(
'eureka-client-ts'
));
var
Eurekaclient
=
_interopDefault
(
require
(
'eureka-client-ts'
));
var
log4js
=
require
(
'log4js'
);
var
log4js
=
require
(
'log4js'
);
var
path
=
_interopDefault
(
require
(
'path'
));
var
path
=
_interopDefault
(
require
(
'path'
));
var
fs
=
_interopDefault
(
require
(
'fs-extra'
));
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.
* Created by rockyl on 2020-02-13.
...
@@ -21,11 +21,14 @@ fs.ensureDir(logPath);
...
@@ -21,11 +21,14 @@ fs.ensureDir(logPath);
log4js
.
configure
({
log4js
.
configure
({
appenders
:
{
appenders
:
{
out
:
{
type
:
'console'
},
out
:
{
type
:
'console'
},
allLog
:
{
type
:
'file'
,
filename
:
path
.
join
(
logPath
,
'log.log'
),
keepFileExt
:
true
,
maxLogSize
:
10485760
,
backups
:
3
},
allLog
:
{
type
:
'dateFile'
,
filename
:
path
.
join
(
logPath
,
'log.log'
),
},
},
},
categories
:
{
categories
:
{
default
:
{
appenders
:
[
'out'
,
'allLog'
],
level
:
'debug'
},
default
:
{
appenders
:
[
'out'
,
'allLog'
],
level
:
'debug'
},
}
}
});
});
...
@@ -50,6 +53,61 @@ async function getEurekaClient(port) {
...
@@ -50,6 +53,61 @@ async function getEurekaClient(port) {
return
eureka
;
return
eureka
;
}
}
/**
* Created by rockyl on 2020-02-13.
*/
const
acceptTypes
=
[
'image/png'
,
'image/jpeg'
];
function
applyApi
(
server
){
server
.
get
(
'/echo/:name'
,
function
(
req
,
res
,
next
)
{
res
.
send
(
req
.
params
);
return
next
();
});
server
.
get
(
'/monitor/check'
,
function
(
req
,
res
,
next
)
{
res
.
sendRaw
(
'ok'
);
return
next
();
});
server
.
post
(
'/tinify'
,
async
function
(
req
,
res
,
next
)
{
logger
.
info
(
'/tinify'
);
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
)
{
logger
.
error
(
'/tinify'
,
'compress failed'
);
res
.
send
({
code
:
2
,
msg
:
'compress failed'
});
}
}
else
{
logger
.
error
(
'/tinify'
,
'type error'
);
res
.
send
({
code
:
1
,
msg
:
'type error'
});
}
return
next
();
});
}
/**
/**
* Created by rockyl on 2020-02-12.
* Created by rockyl on 2020-02-12.
*/
*/
...
@@ -58,8 +116,6 @@ let [_, __, port = '8090'] = process.argv;
...
@@ -58,8 +116,6 @@ let [_, __, port = '8090'] = process.argv;
let
eureka
;
let
eureka
;
port
=
parseInt
(
port
);
port
=
parseInt
(
port
);
const
acceptTypes
=
[
'image/png'
,
'image/jpeg'
];
const
server
=
restify
.
createServer
({
const
server
=
restify
.
createServer
({
name
:
'tiny-image'
,
name
:
'tiny-image'
,
version
:
'1.0.0'
version
:
'1.0.0'
...
@@ -69,47 +125,7 @@ server.use(restify.plugins.acceptParser(server.acceptable));
...
@@ -69,47 +125,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
.
get
(
'/echo/:name'
,
function
(
req
,
res
,
next
)
{
applyApi
(
server
);
res
.
send
(
req
.
params
);
return
next
();
});
server
.
post
(
'/tinify'
,
async
function
(
req
,
res
,
next
)
{
logger
.
info
(
'/tinify'
);
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
)
{
logger
.
error
(
'/tinify'
,
'compress failed'
);
res
.
send
({
code
:
2
,
msg
:
'compress failed'
});
}
}
else
{
logger
.
error
(
'/tinify'
,
'type error'
);
res
.
send
({
code
:
1
,
msg
:
'type error'
});
}
return
next
();
});
process
.
on
(
'uncaughtException'
,
(
err
)
=>
{
process
.
on
(
'uncaughtException'
,
(
err
)
=>
{
logger
.
error
(
err
);
logger
.
error
(
err
);
...
...
dist/index.js.map
View file @
dfdb6f5d
This diff is collapsed.
Click to expand it.
src/api.js
0 → 100644
View file @
dfdb6f5d
/**
* Created by rockyl on 2020-02-13.
*/
import
logger
from
"./logger"
;
import
imagemin
from
"imagemin"
;
import
imageminJpegtran
from
"imagemin-jpegtran"
;
import
imageminPngquant
from
"imagemin-pngquant"
;
const
acceptTypes
=
[
'image/png'
,
'image/jpeg'
];
export
default
function
applyApi
(
server
){
server
.
get
(
'/echo/:name'
,
function
(
req
,
res
,
next
)
{
res
.
send
(
req
.
params
);
return
next
();
});
server
.
get
(
'/monitor/check'
,
function
(
req
,
res
,
next
)
{
res
.
sendRaw
(
'ok'
);
return
next
();
});
server
.
post
(
'/tinify'
,
async
function
(
req
,
res
,
next
)
{
logger
.
info
(
'/tinify'
);
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
)
{
logger
.
error
(
'/tinify'
,
'compress failed'
);
res
.
send
({
code
:
2
,
msg
:
'compress failed'
});
}
}
else
{
logger
.
error
(
'/tinify'
,
'type error'
);
res
.
send
({
code
:
1
,
msg
:
'type error'
});
}
return
next
();
});
}
\ No newline at end of file
src/index.js
View file @
dfdb6f5d
...
@@ -3,18 +3,14 @@
...
@@ -3,18 +3,14 @@
*/
*/
import
restify
from
'restify'
;
import
restify
from
'restify'
;
import
imagemin
from
'imagemin'
;
import
imageminJpegtran
from
'imagemin-jpegtran'
;
import
imageminPngquant
from
'imagemin-pngquant'
;
import
{
getEurekaClient
}
from
"./eureka"
;
import
{
getEurekaClient
}
from
"./eureka"
;
import
logger
from
"./logger"
;
import
logger
from
"./logger"
;
import
applyApi
from
"./api"
;
let
[
_
,
__
,
port
=
'8090'
]
=
process
.
argv
;
let
[
_
,
__
,
port
=
'8090'
]
=
process
.
argv
;
let
eureka
;
let
eureka
;
port
=
parseInt
(
port
);
port
=
parseInt
(
port
);
const
acceptTypes
=
[
'image/png'
,
'image/jpeg'
];
const
server
=
restify
.
createServer
({
const
server
=
restify
.
createServer
({
name
:
'tiny-image'
,
name
:
'tiny-image'
,
version
:
'1.0.0'
version
:
'1.0.0'
...
@@ -24,47 +20,7 @@ server.use(restify.plugins.acceptParser(server.acceptable));
...
@@ -24,47 +20,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
.
get
(
'/echo/:name'
,
function
(
req
,
res
,
next
)
{
applyApi
(
server
);
res
.
send
(
req
.
params
);
return
next
();
});
server
.
post
(
'/tinify'
,
async
function
(
req
,
res
,
next
)
{
logger
.
info
(
'/tinify'
);
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
)
{
logger
.
error
(
'/tinify'
,
'compress failed'
);
res
.
send
({
code
:
2
,
msg
:
'compress failed'
});
}
}
else
{
logger
.
error
(
'/tinify'
,
'type error'
);
res
.
send
({
code
:
1
,
msg
:
'type error'
});
}
return
next
();
});
process
.
on
(
'uncaughtException'
,
(
err
)
=>
{
process
.
on
(
'uncaughtException'
,
(
err
)
=>
{
logger
.
error
(
err
);
logger
.
error
(
err
);
...
...
src/logger.js
View file @
dfdb6f5d
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* Created by rockyl on 2020-02-13.
* Created by rockyl on 2020-02-13.
*/
*/
import
{
configure
,
getLogger
}
from
'log4js'
;
import
{
configure
,
getLogger
}
from
'log4js'
;
import
path
from
"path"
;
import
path
from
"path"
;
import
fs
from
"fs-extra"
;
import
fs
from
"fs-extra"
;
...
@@ -12,11 +12,14 @@ fs.ensureDir(logPath);
...
@@ -12,11 +12,14 @@ fs.ensureDir(logPath);
configure
({
configure
({
appenders
:
{
appenders
:
{
out
:
{
type
:
'console'
},
out
:
{
type
:
'console'
},
allLog
:
{
type
:
'file'
,
filename
:
path
.
join
(
logPath
,
'log.log'
),
keepFileExt
:
true
,
maxLogSize
:
10485760
,
backups
:
3
},
allLog
:
{
type
:
'dateFile'
,
filename
:
path
.
join
(
logPath
,
'log.log'
),
},
},
},
categories
:
{
categories
:
{
default
:
{
appenders
:
[
'out'
,
'allLog'
],
level
:
'debug'
},
default
:
{
appenders
:
[
'out'
,
'allLog'
],
level
:
'debug'
},
}
}
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment