You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-26 22:41:17 +02:00
Desktop, Mobile: Print name of file when import fails
This commit is contained in:
@@ -80,65 +80,71 @@ export default class InteropService_Importer_Raw extends InteropService_Importer
|
|||||||
|
|
||||||
for (let i = 0; i < stats.length; i++) {
|
for (let i = 0; i < stats.length; i++) {
|
||||||
const stat = stats[i];
|
const stat = stats[i];
|
||||||
if (stat.isDirectory()) continue;
|
|
||||||
if (fileExtension(stat.path).toLowerCase() !== 'md') continue;
|
|
||||||
|
|
||||||
const content = await shim.fsDriver().readFile(`${this.sourcePath_}/${stat.path}`);
|
try {
|
||||||
const item = await BaseItem.unserialize(content);
|
if (stat.isDirectory()) continue;
|
||||||
const itemType = item.type_;
|
if (fileExtension(stat.path).toLowerCase() !== 'md') continue;
|
||||||
const ItemClass = BaseItem.itemClass(item);
|
|
||||||
|
|
||||||
delete item.type_;
|
const content = await shim.fsDriver().readFile(`${this.sourcePath_}/${stat.path}`);
|
||||||
|
const item = await BaseItem.unserialize(content);
|
||||||
|
const itemType = item.type_;
|
||||||
|
const ItemClass = BaseItem.itemClass(item);
|
||||||
|
|
||||||
if (itemType === BaseModel.TYPE_NOTE) {
|
delete item.type_;
|
||||||
await setFolderToImportTo(item.parent_id);
|
|
||||||
|
|
||||||
if (!itemIdMap[item.id]) itemIdMap[item.id] = uuid.create();
|
if (itemType === BaseModel.TYPE_NOTE) {
|
||||||
item.id = itemIdMap[item.id];
|
|
||||||
item.parent_id = itemIdMap[item.parent_id];
|
|
||||||
item.body = await replaceLinkedItemIds(item.body);
|
|
||||||
} else if (itemType === BaseModel.TYPE_FOLDER) {
|
|
||||||
if (destinationFolderId) continue;
|
|
||||||
|
|
||||||
if (!itemIdMap[item.id]) itemIdMap[item.id] = uuid.create();
|
|
||||||
item.id = itemIdMap[item.id];
|
|
||||||
|
|
||||||
if (item.parent_id) {
|
|
||||||
await setFolderToImportTo(item.parent_id);
|
await setFolderToImportTo(item.parent_id);
|
||||||
|
|
||||||
|
if (!itemIdMap[item.id]) itemIdMap[item.id] = uuid.create();
|
||||||
|
item.id = itemIdMap[item.id];
|
||||||
item.parent_id = itemIdMap[item.parent_id];
|
item.parent_id = itemIdMap[item.parent_id];
|
||||||
}
|
item.body = await replaceLinkedItemIds(item.body);
|
||||||
|
} else if (itemType === BaseModel.TYPE_FOLDER) {
|
||||||
|
if (destinationFolderId) continue;
|
||||||
|
|
||||||
item.title = await Folder.findUniqueItemTitle(item.title, item.parent_id);
|
if (!itemIdMap[item.id]) itemIdMap[item.id] = uuid.create();
|
||||||
} else if (itemType === BaseModel.TYPE_RESOURCE) {
|
item.id = itemIdMap[item.id];
|
||||||
const sourceId = item.id;
|
|
||||||
if (!itemIdMap[item.id]) itemIdMap[item.id] = uuid.create();
|
|
||||||
item.id = itemIdMap[item.id];
|
|
||||||
createdResources[item.id] = item;
|
|
||||||
|
|
||||||
const sourceResourcePath = `${this.sourcePath_}/resources/${Resource.filename({ ...item, id: sourceId })}`;
|
if (item.parent_id) {
|
||||||
const destPath = Resource.fullPath(item);
|
await setFolderToImportTo(item.parent_id);
|
||||||
|
item.parent_id = itemIdMap[item.parent_id];
|
||||||
|
}
|
||||||
|
|
||||||
if (await shim.fsDriver().exists(sourceResourcePath)) {
|
item.title = await Folder.findUniqueItemTitle(item.title, item.parent_id);
|
||||||
await shim.fsDriver().copy(sourceResourcePath, destPath);
|
} else if (itemType === BaseModel.TYPE_RESOURCE) {
|
||||||
} else {
|
const sourceId = item.id;
|
||||||
result.warnings.push(sprintf('Could not find resource file: %s', sourceResourcePath));
|
if (!itemIdMap[item.id]) itemIdMap[item.id] = uuid.create();
|
||||||
}
|
item.id = itemIdMap[item.id];
|
||||||
} else if (itemType === BaseModel.TYPE_TAG) {
|
createdResources[item.id] = item;
|
||||||
const tag = await Tag.loadByTitle(item.title);
|
|
||||||
if (tag) {
|
const sourceResourcePath = `${this.sourcePath_}/resources/${Resource.filename({ ...item, id: sourceId })}`;
|
||||||
itemIdMap[item.id] = tag.id;
|
const destPath = Resource.fullPath(item);
|
||||||
|
|
||||||
|
if (await shim.fsDriver().exists(sourceResourcePath)) {
|
||||||
|
await shim.fsDriver().copy(sourceResourcePath, destPath);
|
||||||
|
} else {
|
||||||
|
result.warnings.push(sprintf('Could not find resource file: %s', sourceResourcePath));
|
||||||
|
}
|
||||||
|
} else if (itemType === BaseModel.TYPE_TAG) {
|
||||||
|
const tag = await Tag.loadByTitle(item.title);
|
||||||
|
if (tag) {
|
||||||
|
itemIdMap[item.id] = tag.id;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tagId = uuid.create();
|
||||||
|
itemIdMap[item.id] = tagId;
|
||||||
|
item.id = tagId;
|
||||||
|
} else if (itemType === BaseModel.TYPE_NOTE_TAG) {
|
||||||
|
noteTagsToCreate.push(item);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tagId = uuid.create();
|
await ItemClass.save(item, { isNew: true, autoTimestamp: false });
|
||||||
itemIdMap[item.id] = tagId;
|
} catch (error) {
|
||||||
item.id = tagId;
|
error.message = `Could not import: ${stat.path}: ${error.message}`;
|
||||||
} else if (itemType === BaseModel.TYPE_NOTE_TAG) {
|
throw error;
|
||||||
noteTagsToCreate.push(item);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await ItemClass.save(item, { isNew: true, autoTimestamp: false });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < noteTagsToCreate.length; i++) {
|
for (let i = 0; i < noteTagsToCreate.length; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user