Skip to content

Commit

Permalink
fix(fs): fix pagination error @ get files;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Nov 15, 2021
1 parent b1cb02a commit 5d4563d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/storage-service/src/api/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ export async function getFileByName(bucket: string, filename: string) {
export async function getFilesInDirectory(bucket: string, parent: string, offset?: number, limit?: number) {
assert.ok(bucket, 'empty bucket got')
assert.ok(parent, 'empty parent got')

const options = {
skip: offset ?? 0
}
if (limit) {
options['limit'] = limit
skip: offset ?? 0,
limit: limit ?? Infinity
}

const coll = DatabaseAgent.db.collection<FileItemType>(bucket + ".files")
const files = await coll.find({ "metadata.parent": parent }, options).toArray()
return files
Expand Down
7 changes: 4 additions & 3 deletions packages/storage-service/src/router/file/get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author: Maslow<wangfugen@126.com>
* @Date: 2021-08-19 16:10:27
* @LastEditTime: 2021-11-15 18:10:10
* @LastEditTime: 2021-11-16 00:10:38
* @Description:
*/

Expand Down Expand Up @@ -52,8 +52,9 @@ export async function handleGetFile(req: express.Request, res: express.Response)
return res.status(code).send(message)
}

const offset = (req.query?.offset ?? 0) as any
const limit = req.query?.limit as any
const offset = Number(req.query?.offset ?? 0) as any
const limit = Number(req.query?.limit) as any

const files = await getFilesInDirectory(bucket_name, filename, offset, limit)
const total = await countFilesInDirectory(bucket_name, filename)
res.type('json')
Expand Down

0 comments on commit 5d4563d

Please sign in to comment.