1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00
joplin/packages/app-mobile/components/NoteEditor/ImageEditor/autosave.ts

27 lines
819 B
TypeScript
Raw Normal View History

import Logger from '@joplin/utils/Logger';
import Setting from '@joplin/lib/models/Setting';
import shim from '@joplin/lib/shim';
export const autosaveFilename = 'autosaved-drawing.joplin.svg';
const logger = Logger.create('ImageEditor/autosave');
export const getAutosaveFilepath = () => {
return `${Setting.value('resourceDir')}/${autosaveFilename}`;
};
export const writeAutosave = async (data: string) => {
const filePath = getAutosaveFilepath();
logger.info(`Auto-saving drawing to ${JSON.stringify(filePath)}`);
await shim.fsDriver().writeFile(filePath, data, 'utf8');
};
export const readAutosave = async (): Promise<string|null> => {
return await shim.fsDriver().readFile(getAutosaveFilepath());
};
export const clearAutosave = async () => {
await shim.fsDriver().remove(getAutosaveFilepath());
};