Skip to content

Commit a7d4597

Browse files
committed
add target in handler
1 parent 6ac8fd7 commit a7d4597

File tree

4 files changed

+71
-20
lines changed

4 files changed

+71
-20
lines changed

dist/server.js

Lines changed: 21 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/server.ls

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ uploadr = (opt = {}) ->
55
rooturl = opt.url or folder
66

77
# input: one of following ( name is optional in both case )
8-
# - {path, name}
8+
# - {path, name, target}
99
# - {buf, name}
1010
# return:
1111
# - { name, url, id } if succeed
@@ -24,8 +24,8 @@ uploadr = (opt = {}) ->
2424
dir = path.join(folder, t1, t2)
2525
imgtype(buf)
2626
.then ({ext}) ->
27-
des = path.join(dir, md5)
28-
url = path.join(rooturl, t1, t2, md5)
27+
des = if target => path.join(dir, target, md5) else path.join(dir, md5)
28+
url = if target => path.join(rooturl, target, t1, t2, md5) else path.join(rooturl, t1, t2, md5)
2929
if ext => [des,url] = ["#des.#ext", "#url.#ext"]
3030
<- fs.exists des, _
3131
if it => res {url, name, id: md5}
@@ -41,17 +41,20 @@ uploadr = (opt = {}) ->
4141
# for example:
4242
# app.post \/d/uploadr, express-formidable({multiples:true}), uploadr.route
4343
route = (req, res, next) ->
44-
handler(req, res, next)
44+
handler({opt: {}, req, res})
4545
.then -> res.send it
4646
.catch (err) ->
4747
if opt.catch => opt.catch(err, req, res, next);
4848
else
4949
console.log err
5050
res.status(500).send!
5151

52-
handler = (req, res, next) ->
52+
handler = (o = {}) ->
53+
{req, res} = o
54+
cfg = o.opt or {}
5355
files = (req.files or {}).file
5456
files = if !files => [] else if Array.isArray(files) => files else [files]
57+
if cfg and cfg.target => files = files.map -> it <<< {target: cfg.target}
5558
promises = files
5659
.map archive
5760
.map ->

web/api/uploadr.js

Lines changed: 21 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/static/assets/lib/uploadr/server.js

Lines changed: 21 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)