tus/tus-node-server

Error when calling `server.cleanUpExpiredUploads()`

phillip-causing opened this issue · 0 comments

When FileStore is use as datastore and use the default configstore by not providing a configstore

const datastore = new FileStore({
    directory: 'mydir',
    expirationPeriodInMilliseconds: 60000 * 60 * 24, // 24hrs,
});

Calling server.cleanUpExpiredUploads() will cause an error

Because in this line packages/file-store/configstores/FileConfigstore.ts#L43

 async list(): Promise<Array<string>> {
    return this.queue.add(async () => {
      const files = await fs.readdir(this.directory, {withFileTypes: true})
      const promises = files
        .filter((file) => file.isFile() && file.name.endsWith('.json'))
        .map((file) => fs.readFile(path.resolve(file.path, file.name), 'utf8'))

      return Promise.all(promises)
    }) as Promise<string[]>
  }

file.path is undefined but I was able to fix it by replacing it to this.directory
I was able to read the file but there is another problem, in this line it is expecting just the file_id/key packages/file-store/index.ts#L207 but what we have returned on the list above is an array of the content of the files