mirror of
https://github.com/daledesilva/obsidian_google-keep-import.git
synced 2026-07-22 07:50:23 +00:00
Added abviilty to turn toggle unsupported files and added skipped files reporting
This commit is contained in:
parent
c7c08583a8
commit
2114e9e3bd
7 changed files with 61 additions and 31 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { Setting } from "obsidian";
|
||||
import MyPlugin from "src/main";
|
||||
import { ConfirmationModal } from "src/modals/confirmation-modal/confirmation-modal";
|
||||
import { CreatedDateTypes } from "src/types/PluginSettings";
|
||||
import { CreatedDateTypes } from "src/types/plugin-settings";
|
||||
|
||||
|
||||
///////////////////
|
||||
|
|
@ -99,6 +99,18 @@ export class InclusionSettingsGroup {
|
|||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setClass('gki_setting')
|
||||
.setName('Import unsupported files')
|
||||
.setDesc('Importing unsupported files will place them in correct folders and notify you on import so that you can convert them manually. Otherwise they will be skipped.') // TODO: If you are using this plugin to import markdown files rather than Google Keep files, turning this off might cause markdown files to be ignored on some systems if they report their file format incorrectly.
|
||||
.addToggle(toggle => {
|
||||
toggle.setValue(plugin.settings.importUnsupported)
|
||||
toggle.onChange(async (value) => {
|
||||
plugin.settings.importUnsupported = value;
|
||||
await plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ import { DataWriteOptions, Notice, Plugin, TAbstractFile, TFile, TFolder, Vault
|
|||
import MyPlugin from "src/main";
|
||||
import { ImportProgressModal } from "src/modals/import-progress-modal/import-progress-modal";
|
||||
import { filenameSanitize } from "./string-processes";
|
||||
import { CreatedDateTypes, PluginSettings } from "src/types/PluginSettings";
|
||||
import { KeepJson } from "src/types/KeepData";
|
||||
import { IgnoreImportReason, ImportResult, ImportOutcomeType } from "src/types/Results";
|
||||
import { CreatedDateTypes, PluginSettings } from "src/types/plugin-settings";
|
||||
import { KeepJson } from "src/types/keep-data";
|
||||
import { IgnoreImportReason, ImportResult, ImportOutcomeType } from "src/types/results";
|
||||
import { StartImportModal } from "src/modals/start-import-modal/start-import-modal";
|
||||
|
||||
|
||||
|
|
@ -14,6 +14,7 @@ import { StartImportModal } from "src/modals/start-import-modal/start-import-mod
|
|||
|
||||
interface ProgressSummary {
|
||||
successCount: number,
|
||||
skipCount: number,
|
||||
failCount: number,
|
||||
newLogEntries: Array<OutputLogItem>;
|
||||
};
|
||||
|
|
@ -111,6 +112,7 @@ export class FileImporter {
|
|||
private totalImports = 0;
|
||||
private successCount = 0;
|
||||
private failCount = 0;
|
||||
private skipCount = 0;
|
||||
private activeImport = false;
|
||||
private outputLog: Array<OutputLogItem> = [];
|
||||
private outputLogIter = 0;
|
||||
|
|
@ -131,6 +133,7 @@ export class FileImporter {
|
|||
this.totalImports = files.length;
|
||||
this.successCount = 0;
|
||||
this.failCount = 0;
|
||||
this.skipCount = 0;
|
||||
|
||||
for(let i=0; i<files.length; i++) {
|
||||
const file = files[i] as File;
|
||||
|
|
@ -149,34 +152,28 @@ export class FileImporter {
|
|||
if(!assetFolder) assetFolder = await getOrCreateFolder(settings.folderNames.assets, vault);
|
||||
result = await importBinaryFile(vault, assetFolder, file);
|
||||
|
||||
} else if(fileIsBinaryAndSupportedByKeep(file) && fileIsBinaryAndSupportedByObsidian(file)) {
|
||||
// Import as supported binary file
|
||||
if(!assetFolder) assetFolder = await getOrCreateFolder(settings.folderNames.assets, vault);
|
||||
result = await importBinaryFile(vault, assetFolder, file);
|
||||
|
||||
} else if(fileIsBinaryAndSupportedByKeep(file) && !fileIsBinaryAndSupportedByObsidian(file)) {
|
||||
// Import as unsupported binary file
|
||||
if(!unsupportedFolder) unsupportedFolder = await getOrCreateFolder(settings.folderNames.unsupportedAssets, vault);
|
||||
result = await importBinaryFile(vault, unsupportedFolder, file);
|
||||
result = {
|
||||
keepFilename: file.name,
|
||||
outcome: ImportOutcomeType.FormatError,
|
||||
details: `This file type isn't supported by Obsidian. The file has been imported into '${settings.folderNames.unsupportedAssets}'. Open that folder outside of Obsidian to convert or deleted those files. Any links to those files in notes will also need to be updated.`,
|
||||
}
|
||||
|
||||
} else if(fileIsBinaryAndSupportedByObsidian(file)) {
|
||||
// Import as supported binary file
|
||||
if(!assetFolder) assetFolder = await getOrCreateFolder(settings.folderNames.assets, vault);
|
||||
result = await importBinaryFile(vault, assetFolder, file);
|
||||
|
||||
} else {
|
||||
// Import as unrecognised file
|
||||
if(!unsupportedFolder) unsupportedFolder = await getOrCreateFolder(settings.folderNames.unsupportedAssets, vault);
|
||||
result = await importBinaryFile(vault, unsupportedFolder, file);
|
||||
result = {
|
||||
keepFilename: file.name,
|
||||
outcome: ImportOutcomeType.FormatError,
|
||||
details: `This file's format isn't recognised. The file has been imported into '${settings.folderNames.unsupportedAssets}'. It will appear in Obsidian if supported, otherwise you can access it outside of obsidian.`,
|
||||
if(settings.importUnsupported) {
|
||||
// Import as unsupported binary file
|
||||
if(!unsupportedFolder) unsupportedFolder = await getOrCreateFolder(settings.folderNames.unsupportedAssets, vault);
|
||||
result = await importBinaryFile(vault, unsupportedFolder, file);
|
||||
result = {
|
||||
keepFilename: file.name,
|
||||
outcome: ImportOutcomeType.FormatError,
|
||||
details: `This file type isn't supported by Obsidian. The file has been imported into '${settings.folderNames.unsupportedAssets}'. Open that folder outside of Obsidian to convert or deleted those files. Any links to those files in notes will also need to be updated.`,
|
||||
}
|
||||
} else {
|
||||
// Don't import unsupported binary file, but still log
|
||||
result = {
|
||||
keepFilename: file.name,
|
||||
outcome: ImportOutcomeType.UserIgnored,
|
||||
details: `This file type isn't supported by Obsidian and has been skipped. You can change this behaviour in the settings.`,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -196,6 +193,14 @@ export class FileImporter {
|
|||
title: `${result.keepFilename}`,
|
||||
desc: `${result.details} ${result.obsidianFilepath || ''} ${result.error ? '('+result.error+')' : ''}`,
|
||||
})
|
||||
|
||||
} else if(result.outcome === ImportOutcomeType.UserIgnored) {
|
||||
this.skipCount++;
|
||||
this.outputLog.push({
|
||||
status: 'Note',
|
||||
title: `${result.keepFilename}`,
|
||||
desc: `${result.details} ${result.error ? '('+result.error+')' : ''}`,
|
||||
})
|
||||
|
||||
} else {
|
||||
this.successCount++;
|
||||
|
|
@ -224,6 +229,7 @@ export class FileImporter {
|
|||
return {
|
||||
successCount: this.successCount,
|
||||
failCount: this.failCount,
|
||||
skipCount: this.skipCount,
|
||||
newLogEntries
|
||||
};
|
||||
}
|
||||
|
|
@ -249,9 +255,11 @@ function fileIsJson(file: File) {
|
|||
* Note that some markdown files have been found to return a blank mime type in testing and maye return false.
|
||||
*/
|
||||
function fileIsPlainText(file: File) {
|
||||
// file.name // TODO: Check for MD file name if type is blank
|
||||
return file.type === 'text/plain' ||
|
||||
file.type === 'text/markdown' ||
|
||||
file.type === 'text/x-markdown';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Notice, Plugin } from 'obsidian';
|
||||
import { CreatedDateTypes, PluginSettings } from 'src/types/PluginSettings';
|
||||
import { CreatedDateTypes, PluginSettings } from 'src/types/plugin-settings';
|
||||
import { runImportSequence } from './logic/import-logic';
|
||||
import { MySettingsTab } from './tabs/settings-tab/settings-tab';
|
||||
|
||||
|
|
@ -20,6 +20,7 @@ export const DEFAULT_SETTINGS: PluginSettings = {
|
|||
createdDate: CreatedDateTypes.googleKeep,
|
||||
importArchived: true,
|
||||
importTrashed: false,
|
||||
importUnsupported: true,
|
||||
addColorTags: true,
|
||||
addPinnedTags: true,
|
||||
addAttachmentTags: true,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ export class ImportProgressModal extends Modal {
|
|||
modalHeaderDiv: HTMLDivElement;
|
||||
bar: HTMLDivElement;
|
||||
remainingSpan: HTMLSpanElement;
|
||||
skippedSpan: HTMLSpanElement;
|
||||
failedSpan: HTMLSpanElement;
|
||||
importedSpan: HTMLSpanElement;
|
||||
outputStr: string = '';
|
||||
|
|
@ -54,7 +55,8 @@ export class ImportProgressModal extends Modal {
|
|||
|
||||
let importSummary = new ImportSummary(contentEl);
|
||||
this.remainingSpan = importSummary.addItem('remaining');
|
||||
this.failedSpan = importSummary.addItem('failed/skipped');
|
||||
this.skippedSpan = importSummary.addItem('skipped');
|
||||
this.failedSpan = importSummary.addItem('failed');
|
||||
this.importedSpan = importSummary.addItem('imported');
|
||||
|
||||
this.outputLogEl = contentEl.createDiv('gki_error-log');
|
||||
|
|
@ -73,16 +75,18 @@ export class ImportProgressModal extends Modal {
|
|||
const totalImports = this.fileImporter.getTotalImports();
|
||||
const {
|
||||
successCount,
|
||||
skipCount,
|
||||
failCount,
|
||||
newLogEntries,
|
||||
} = this.fileImporter.getLatestProgress();
|
||||
|
||||
// Update bar visual
|
||||
const perc = (successCount + failCount)/totalImports * 100;
|
||||
const perc = (successCount + skipCount + failCount)/totalImports * 100;
|
||||
this.bar.setAttr('style', `width: ${perc}%`);
|
||||
|
||||
// Update text
|
||||
this.remainingSpan.setText(`${totalImports-successCount-failCount}`);
|
||||
this.remainingSpan.setText(`${totalImports-successCount-failCount-skipCount}`);
|
||||
this.skippedSpan.setText(`${skipCount}`);
|
||||
this.failedSpan.setText(`${failCount}`);
|
||||
this.importedSpan.setText(`${successCount}`);
|
||||
|
||||
|
|
@ -92,7 +96,7 @@ export class ImportProgressModal extends Modal {
|
|||
}
|
||||
|
||||
// Finalise or continue on next frame
|
||||
if(successCount + failCount == totalImports) {
|
||||
if(successCount + skipCount + failCount == totalImports) {
|
||||
this.importCompleted = true;
|
||||
this.applyCompletedState();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -173,6 +173,10 @@ button.gki_button[disabled] {
|
|||
border-radius: 4px;
|
||||
margin-right: 0.5em;
|
||||
|
||||
&.note {
|
||||
background-color: rgba($color: #ffffff, $alpha: 0.3);
|
||||
color: #FFF;
|
||||
}
|
||||
&.error {
|
||||
background-color: rgba($color: #FF5555, $alpha: 0.3);
|
||||
color: #FFF;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ export interface PluginSettings {
|
|||
createdDate: CreatedDateTypes,
|
||||
importArchived: boolean,
|
||||
importTrashed: boolean,
|
||||
importUnsupported: boolean,
|
||||
addColorTags: boolean,
|
||||
addPinnedTags: boolean,
|
||||
addAttachmentTags: boolean,
|
||||
Loading…
Reference in a new issue