-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fixed double extension for screenshots (#2419)
Check if the key in a File Key Value Storage already has an extension. If so use the key as the file name directly, otherwise append extension. Closes #1980
- Loading branch information
Showing
3 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
36 changes: 36 additions & 0 deletions
36
packages/memory-storage/test/key-value-store/with-extension.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { resolve } from 'node:path'; | ||
|
||
import { existsSync, emptyDirSync } from 'fs-extra'; | ||
import { createKeyValueStorageImplementation } from 'packages/memory-storage/src/fs/key-value-store'; | ||
|
||
describe('KeyValueStore should append extension only when needed', () => { | ||
const mockImageBuffer = Buffer.from('This is a test image', 'utf8'); | ||
|
||
afterAll(() => emptyDirSync('tmp')); | ||
|
||
test('should append extension when needed', async () => { | ||
const testDir = resolve('tmp', 'test_no_extension'); | ||
const storage = createKeyValueStorageImplementation({ | ||
persistStorage: true, | ||
storeDirectory: testDir, | ||
writeMetadata: true, | ||
}); | ||
await storage.update({ key: 'jibberish', value: mockImageBuffer, contentType: 'image/jpeg', extension: 'jpeg' }); | ||
|
||
expect(existsSync(resolve(testDir, 'jibberish.jpeg'))).toBeTruthy(); | ||
expect(existsSync(resolve(testDir, 'jibberish'))).toBeFalsy(); | ||
}); | ||
|
||
test('should not append extension when already available', async () => { | ||
const testDir = resolve('tmp', 'test_extension'); | ||
const storage = createKeyValueStorageImplementation({ | ||
persistStorage: true, | ||
storeDirectory: testDir, | ||
writeMetadata: true, | ||
}); | ||
await storage.update({ key: 'jibberish.jpg', value: mockImageBuffer, contentType: 'image/jpeg', extension: 'jpeg' }); | ||
|
||
expect(existsSync(resolve(testDir, 'jibberish.jpg'))).toBeTruthy(); | ||
expect(existsSync(resolve(testDir, 'jibberish.jpg.jpeg'))).toBeFalsy(); | ||
}); | ||
}); |