Skip to content

Commit

Permalink
Preview capability in file download server API
Browse files Browse the repository at this point in the history
  • Loading branch information
amourzenkov-sc committed Nov 14, 2017
1 parent f827ce0 commit 8d0fe3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 6 additions & 8 deletions server-nodejs/docs/api-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,12 @@ None.

### Request Query Parameters

| Name | Value |
|----------------|-------------|
| items | dir/file id |
| items | dir/file id |
| ... | ... |


When multiple items, all _must_ be from the same folder. Both folder and file ids are allowed in __items__ array.
| Name | Value | Default | Comments |
|----------------|---------------|---------|-----------------------------------------------------------|
| preview | true or false | false | Applicable only when single *items* parameter is file ID |
| items | dir/file id | - | Both folder and file ids are allowed as *items* |
| items | dir/file id | - | When multiple *items*, all _must_ be from the same folder |
| ... | ... | ... | |

### Response

Expand Down
3 changes: 3 additions & 0 deletions server-nodejs/router/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { id2path } = require('./lib');

module.exports = ({ options, req, res, handleError }) => {
const ids = Array.isArray(req.query.items) ? req.query.items : [req.query.items];
const preview = req.query.preview === 'true';
let reqPaths;

try {
Expand All @@ -33,6 +34,8 @@ module.exports = ({ options, req, res, handleError }) => {
}],
filename: (absPaths[0] === options.fsRoot ? options.rootName : path.basename(absPaths[0])) + '.zip'
});
} else if (preview) {
res.sendFile(absPaths[0]);
} else {
res.download(absPaths[0]);
}
Expand Down

0 comments on commit 8d0fe3b

Please sign in to comment.