1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-10 22:11:50 +02:00

Transcribe: Fixes #12765: Removes file from temporary folder after storing it (#12795)

This commit is contained in:
pedr
2025-07-28 14:32:10 -03:00
committed by GitHub
parent 6e8ba8a536
commit 90d6d1747a
3 changed files with 59 additions and 2 deletions

View File

@@ -3,6 +3,9 @@ import initiateLogger from '../../services/initiateLogger';
import { BaseQueue, JobData } from '../../types';
import createJob from './createJob';
import { cleanUpDb, initDb } from '../../testUtils';
import FileStorage from '../../services/FileStorage';
import { copyFile, exists, remove } from 'fs-extra';
import { join } from 'path';
describe('createJob', () => {
let queue: BaseQueue;
@@ -17,6 +20,10 @@ describe('createJob', () => {
});
afterEach(async () => {
const job = await queue.fetch();
if (job) {
await remove(join('images', job.data.filePath));
}
await queue.stop();
await cleanUpDb('./createJob.test.sqlite3');
});
@@ -54,4 +61,20 @@ describe('createJob', () => {
const job = await queue.fetch();
expect(job).toBeNull();
});
it('should delete the original file after storing', async () => {
await copyFile('./images/htr_sample.png', './test_file.png');
const fs = new FileStorage();
const requirements = {
filepath: './test_file.png',
storeImage: fs.store,
sendToQueue: (data: JobData) => queue.send(data),
};
await createJob(requirements);
const originalFile = await exists('./test_file.png');
expect(originalFile).toBe(false);
});
});

View File

@@ -0,0 +1,34 @@
import { copyFile, exists, remove } from 'fs-extra';
import { join } from 'path';
import FileStorage from './FileStorage';
describe('FileStorage', () => {
it('should move file to storage folder', async () => {
await copyFile('./images/htr_sample.png', './test_file.png');
const fs = new FileStorage();
const name = await fs.store('./test_file.png');
const destination = join('images', name);
const destinationStillExists = await exists(destination);
expect(destinationStillExists).toBe(true);
await remove(destination);
});
it('should remove the original file', async () => {
await copyFile('./images/htr_sample.png', './test_file.png');
const fs = new FileStorage();
const name = await fs.store('./test_file.png');
const originalStillExists = await exists('./test_file.png');
expect(originalStillExists).toBe(false);
await remove(join('images', name));
});
});

View File

@@ -1,5 +1,5 @@
import { join } from 'path';
import { copyFile } from 'fs-extra';
import { move } from 'fs-extra';
import { randomBytes } from 'crypto';
import { ContentStorage } from '../types';
@@ -7,7 +7,7 @@ export default class FileStorage implements ContentStorage {
public async store(filepath: string) {
const randomName = randomBytes(16).toString('hex');
await copyFile(filepath, join('images', randomName));
await move(filepath, join('images', randomName));
return randomName;
}
}