server: add /token endpoint to get retrieval token of content

This commit is contained in:
Jesse Chan
2021-01-23 22:59:02 +08:00
parent 1d1a478391
commit 4f38447459
+30
View File
@@ -663,6 +663,36 @@ router.patch<{hash: string}, unknown, SetTorrentContentsPropertiesOptions>('/:ha
});
});
/**
* GET /api/torrents/{hash}/contents/{indices}/token
* @summary Gets retrieval token of contents of a torrent.
* @tags Torrent
* @security User
* @param {string} hash.path
* @param {string} indices.path - 'all' or indices of selected contents separated by ','
* @return {string} 200 - token - text/plain
*/
router.get<{hash: string; indices: string}, unknown, unknown, {token: string}>(
'/:hash/contents/:indices/token',
// This operation performs authentication operations.
rateLimit({
windowMs: 5 * 60 * 1000,
max: 200,
}),
(req, res) => {
if (req.user) {
const {hash, indices} = req.params;
res.status(200).send(
getToken<ContentToken>({
username: req.user.username,
hash,
indices,
}),
);
}
},
);
/**
* GET /api/torrents/{hash}/contents/{indices}/data
* @summary Gets downloaded data of contents of a torrent.