server: torrents: replace inappropriate "||" with "??"

This commit is contained in:
Jesse Chan
2020-12-27 21:00:43 +08:00
parent 31828bdfd9
commit 262a89e34f
+4 -4
View File
@@ -54,7 +54,7 @@ const getDestination = async (
// Use default destination of torrent client
if (autoDestination == null) {
const {directoryDefault} = (await services?.clientGatewayService?.getClientSettings().catch(() => undefined)) || {};
const {directoryDefault} = (await services?.clientGatewayService?.getClientSettings().catch(() => undefined)) ?? {};
autoDestination = directoryDefault;
}
@@ -242,7 +242,7 @@ router.post<unknown, unknown, CreateTorrentOptions>('/create', async (req, res)
return;
}
const torrentFileName = sanitize(name || sanitizedPath.split(path.sep).pop() || `${Date.now()}`).concat('.torrent');
const torrentFileName = sanitize(name ?? sanitizedPath.split(path.sep).pop() ?? `${Date.now()}`).concat('.torrent');
const torrentPath = getTempPath(torrentFileName);
createTorrent(
@@ -279,7 +279,7 @@ router.post<unknown, unknown, CreateTorrentOptions>('/create', async (req, res)
isCompleted: true,
isSequential: false,
isInitialSeeding: isInitialSeeding ?? false,
start: start || false,
start: start ?? false,
})
.catch(() => {
// do nothing.
@@ -734,7 +734,7 @@ router.get(
async (req, res) => {
const {hash} = req.params;
const callback = getResponseFn(res);
const {torrentService} = req.services || {};
const {torrentService} = req.services ?? {};
if (typeof hash !== 'string' || torrentService == null) {
callback(null, new Error());