2021-04-07 19:41:54 +02:00
|
|
|
import Resource from '@joplin/lib/models/Resource';
|
|
|
|
import { ResourceEntity } from '@joplin/lib/services/database/types';
|
|
|
|
import shim from '@joplin/lib/shim';
|
|
|
|
import { CachesDirectoryPath } from 'react-native-fs';
|
|
|
|
|
2022-10-13 23:02:06 +02:00
|
|
|
// when refactoring this name, make sure to refactor the `SharePackage.java` (in android) as well
|
2021-04-07 19:41:54 +02:00
|
|
|
const DIR_NAME = 'sharedFiles';
|
|
|
|
|
2023-06-30 10:55:56 +02:00
|
|
|
// Copy a file to be shared to cache, renaming it to its orignal name
|
2021-04-07 19:41:54 +02:00
|
|
|
export async function copyToCache(resource: ResourceEntity): Promise<string> {
|
|
|
|
const filename = Resource.friendlySafeFilename(resource);
|
|
|
|
|
|
|
|
const targetDir = `${CachesDirectoryPath}/${DIR_NAME}`;
|
|
|
|
await shim.fsDriver().mkdir(targetDir);
|
|
|
|
|
|
|
|
const targetFile = `${targetDir}/${filename}`;
|
|
|
|
|
|
|
|
await shim.fsDriver().copy(Resource.fullPath(resource), targetFile);
|
|
|
|
|
|
|
|
return targetFile;
|
|
|
|
}
|
|
|
|
|
2023-06-30 10:55:56 +02:00
|
|
|
// Clear previously shared files from cache
|
2021-04-07 19:41:54 +02:00
|
|
|
export async function clearSharedFilesCache(): Promise<void> {
|
|
|
|
return shim.fsDriver().remove(`${CachesDirectoryPath}/sharedFiles`);
|
|
|
|
}
|