1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-18 23:07:45 +02:00

Handle resource conflicts

This commit is contained in:
Laurent Cozic
2020-05-31 16:57:16 +01:00
parent 1852d9291d
commit 36776cd615
7 changed files with 153 additions and 18 deletions

View File

@ -205,18 +205,26 @@ function shimInit() {
return Resource.save(resource, { isNew: true });
};
shim.updateResourceBlob = async function(resourceId, newBlobFilePath) {
shim.duplicateResource = async function(resourceId) {
const resource = await Resource.load(resourceId);
const readyStatus = await Resource.readyStatus(resourceId);
if (readyStatus !== 'ok') throw new Error(`Cannot set resource blob because resource is not ready. Status: ${readyStatus}`);
const localState = await Resource.localState(resource);
const fileStat = await shim.fsDriver().stat(newBlobFilePath);
await shim.fsDriver().copy(newBlobFilePath, Resource.fullPath(resource));
let newResource = { ...resource };
delete newResource.id;
newResource = await Resource.save(newResource);
await Resource.save({
id: resource.id,
size: fileStat.size,
});
const newLocalState = { ...localState };
newLocalState.resource_id = newResource.id;
delete newLocalState.id;
await Resource.setLocalState(newResource, newLocalState);
const sourcePath = Resource.fullPath(resource);
if (await shim.fsDriver().exists(sourcePath)) {
await shim.fsDriver().copy(sourcePath, Resource.fullPath(newResource));
}
return newResource;
};
shim.attachFileToNoteBody = async function(noteBody, filePath, position = null, options = null) {