diff --git a/nextcloud/server.ts b/nextcloud/server.ts index c74079f..6194b6f 100644 --- a/nextcloud/server.ts +++ b/nextcloud/server.ts @@ -153,8 +153,13 @@ app.post('/dir', async (req, res) => { try { if (!req.fobj) return res.sendStatus(401); - const { fpath, deep } = req.fobj, - filesInDir = await client.getDirectoryContents(fpath, { + const { fpath, deep } = req.fobj; + if (!fpath) return res.sendStatus(400); + else if (!(await client.exists(fpath)) { + return res.status(404).send("Directory not found"); + } + + const filesInDir = await client.getDirectoryContents(fpath, { deep }); @@ -162,6 +167,7 @@ app.post('/dir', async (req, res) => { } catch (err) { console.error(err); + res.sendStatus(500); } });