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++) {
|
||||
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}`);
|
||||
const item = await BaseItem.unserialize(content);
|
||||
const itemType = item.type_;
|
||||
const ItemClass = BaseItem.itemClass(item);
|
||||
try {
|
||||
if (stat.isDirectory()) continue;
|
||||
if (fileExtension(stat.path).toLowerCase() !== 'md') continue;
|
||||
|
||||
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) {
|
||||
await setFolderToImportTo(item.parent_id);
|
||||
delete item.type_;
|
||||
|
||||
if (!itemIdMap[item.id]) itemIdMap[item.id] = uuid.create();
|
||||
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) {
|
||||
if (itemType === BaseModel.TYPE_NOTE) {
|
||||
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.body = await replaceLinkedItemIds(item.body);
|
||||
} else if (itemType === BaseModel.TYPE_FOLDER) {
|
||||
if (destinationFolderId) continue;
|
||||
|
||||
item.title = await Folder.findUniqueItemTitle(item.title, item.parent_id);
|
||||
} else if (itemType === BaseModel.TYPE_RESOURCE) {
|
||||
const sourceId = item.id;
|
||||
if (!itemIdMap[item.id]) itemIdMap[item.id] = uuid.create();
|
||||
item.id = itemIdMap[item.id];
|
||||
createdResources[item.id] = item;
|
||||
if (!itemIdMap[item.id]) itemIdMap[item.id] = uuid.create();
|
||||
item.id = itemIdMap[item.id];
|
||||
|
||||
const sourceResourcePath = `${this.sourcePath_}/resources/${Resource.filename({ ...item, id: sourceId })}`;
|
||||
const destPath = Resource.fullPath(item);
|
||||
if (item.parent_id) {
|
||||
await setFolderToImportTo(item.parent_id);
|
||||
item.parent_id = itemIdMap[item.parent_id];
|
||||
}
|
||||
|
||||
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;
|
||||
item.title = await Folder.findUniqueItemTitle(item.title, item.parent_id);
|
||||
} else if (itemType === BaseModel.TYPE_RESOURCE) {
|
||||
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 })}`;
|
||||
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;
|
||||
}
|
||||
|
||||
const tagId = uuid.create();
|
||||
itemIdMap[item.id] = tagId;
|
||||
item.id = tagId;
|
||||
} else if (itemType === BaseModel.TYPE_NOTE_TAG) {
|
||||
noteTagsToCreate.push(item);
|
||||
continue;
|
||||
await ItemClass.save(item, { isNew: true, autoTimestamp: false });
|
||||
} catch (error) {
|
||||
error.message = `Could not import: ${stat.path}: ${error.message}`;
|
||||
throw error;
|
||||
}
|
||||
|
||||
await ItemClass.save(item, { isNew: true, autoTimestamp: false });
|
||||
}
|
||||
|
||||
for (let i = 0; i < noteTagsToCreate.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user