Skip to content

Commit

Permalink
fix(h5p-server): dir temporary storage works with sub-directories (#1710
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sr258 authored Aug 28, 2021
1 parent 3aab69b commit 9b7c0ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ export default class DirectoryTemporaryFileStorage
return (
await Promise.all(
users.map(async (u) => {
const filesOfUser = await getAllFiles.async.array(
this.getAbsoluteUserDirectoryPath(u)
);
const basePath = this.getAbsoluteUserDirectoryPath(u);
const basePathLength = basePath.length + 1;
const filesOfUser = await getAllFiles.async.array(basePath);
return Promise.all(
filesOfUser
.map((f) => path.basename(f))
.map((f) => f.substr(basePathLength))
.filter((f) => !f.endsWith('.metadata'))
.map((f) => this.getTemporaryFileInfo(f, u))
);
Expand Down
20 changes: 16 additions & 4 deletions packages/h5p-server/test/TemporaryFileManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,17 @@ describe('TemporaryFileManager', () => {
config
);

// add file that will expire
const expiringFilename = await tmpManager.addFile(
// add files that will expire
const expiringFilename1 = await tmpManager.addFile(
'dir/expiring.json',
fsExtra.createReadStream(
path.resolve(
'test/data/content-type-cache/real-content-types.json'
)
),
user
);
const expiringFilename2 = await tmpManager.addFile(
'expiring.json',
fsExtra.createReadStream(
path.resolve(
Expand All @@ -115,7 +124,7 @@ describe('TemporaryFileManager', () => {

// add second file that won't expire
const nonExpiringFilename = await tmpManager.addFile(
'non-expiring.json',
'dir/non-expiring.json',
fsExtra.createReadStream(
path.resolve(
'test/data/content-type-cache/real-content-types.json'
Expand All @@ -134,7 +143,10 @@ describe('TemporaryFileManager', () => {

// check if only one file remains
await expect(
tmpManager.getFileStream(expiringFilename, user)
tmpManager.getFileStream(expiringFilename1, user)
).rejects.toThrow();
await expect(
tmpManager.getFileStream(expiringFilename2, user)
).rejects.toThrow();
const stream = await tmpManager.getFileStream(
nonExpiringFilename,
Expand Down

0 comments on commit 9b7c0ae

Please sign in to comment.