mirror of
https://github.com/Wanxp/obsidian-douban.git
synced 2026-04-05 01:28:46 +08:00
add function sync breakdown resume
This commit is contained in:
parent
076883aada
commit
2a10100ed0
@ -30,4 +30,5 @@ export const DEFAULT_SETTINGS: DoubanPluginSetting = {
|
||||
loginCookiesContent: '',
|
||||
cacheImage: true,
|
||||
attachmentPath: 'assets',
|
||||
syncHandledData: new Map(),
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ export class DoubanSyncModal extends Modal {
|
||||
if (!this.plugin.statusHolder.syncStarted) {
|
||||
progress.innerHTML = `<p>
|
||||
<label for="file">${i18nHelper.getMessage('110033')}</label>
|
||||
<progress class="obsidian_douban_sync_slider" max="${syncStatus.getTotal()}" value="${syncStatus.getHandle()}"> </progress> <span> ${syncStatus.getHandle()}/${syncStatus.getTotal()}:${i18nHelper.getMessage('110036')} </span>
|
||||
<progress class="obsidian_douban_sync_slider" max="${syncStatus.getTotal() == 0 ? 1:syncStatus.getTotal()}" value="${syncStatus.getHandle()}"> </progress> <span> ${syncStatus.getHandle()}/${syncStatus.getTotal()}:${i18nHelper.getMessage('110036')} </span>
|
||||
</p>`
|
||||
backgroundButton.setDisabled(true);
|
||||
stopButton.setButtonText(i18nHelper.getMessage('110036'))
|
||||
@ -98,7 +98,7 @@ export class DoubanSyncModal extends Modal {
|
||||
}
|
||||
progress.innerHTML = `<p>
|
||||
<label for="file">${i18nHelper.getMessage('110033')}</label>
|
||||
<progress class="obsidian_douban_sync_slider" max="${syncStatus.getTotal()}" value="${syncStatus.getHandle()}"> </progress> <span> ${syncStatus.getHandle()}/${syncStatus.getTotal()} </span>
|
||||
<progress class="obsidian_douban_sync_slider" max="${syncStatus.getTotal() == 0 ? 1:syncStatus.getTotal()}" value="${syncStatus.getHandle()}"> </progress> <span> ${syncStatus.getHandle()}/${syncStatus.getTotal()} </span>
|
||||
</p>`}
|
||||
|
||||
private showSyncConfig(contentEl: HTMLElement) {
|
||||
@ -114,6 +114,7 @@ export class DoubanSyncModal extends Modal {
|
||||
cacheImage: ( settings.cacheImage == null) ? DEFAULT_SETTINGS.cacheImage : settings.cacheImage,
|
||||
attachmentPath: (settings.attachmentPath == '' || settings.attachmentPath == null) ? DEFAULT_SETTINGS.attachmentPath : settings.attachmentPath,
|
||||
templateFile: (settings.movieTemplateFile == '' || settings.movieTemplateFile == null) ? DEFAULT_SETTINGS.movieTemplateFile : settings.movieTemplateFile,
|
||||
incrementalUpdate: true,
|
||||
};
|
||||
this.showConfigPan(contentEl.createDiv('config'), syncConfig, false);
|
||||
const controls = contentEl.createDiv("controls");
|
||||
@ -155,6 +156,7 @@ export class DoubanSyncModal extends Modal {
|
||||
this.showOutputFolderSelections(contentEl, config, disable);
|
||||
this.showOutiFleName(contentEl, config, disable);
|
||||
this.showAttachmentsFileConfig(contentEl, config, disable);
|
||||
this.showUpdateAllConfig(contentEl, config, disable);
|
||||
this.showForceUpdateConfig(contentEl, config, disable);
|
||||
}
|
||||
|
||||
@ -219,32 +221,20 @@ export class DoubanSyncModal extends Modal {
|
||||
}
|
||||
|
||||
private showOutiFleName(containerEl: HTMLElement, config: SyncConfig, disable:boolean) {
|
||||
const {settings} = this.plugin;
|
||||
const placeHolder =(settings.dataFileNamePath == '' || settings.dataFileNamePath == null) ? DEFAULT_SETTINGS.dataFileNamePath : settings.dataFileNamePath;
|
||||
const dataFilePathSetting = new Setting(containerEl)
|
||||
.setName(i18nHelper.getMessage('121601'))
|
||||
.setDesc(i18nHelper.getMessage('121602'))
|
||||
.addText((textField) => {
|
||||
textField.setPlaceholder(placeHolder)
|
||||
textField.setPlaceholder(i18nHelper.getMessage('121602'))
|
||||
.setValue(config.dataFileNamePath)
|
||||
.onChange(async (value) => {
|
||||
config.dataFileNamePath = value
|
||||
});
|
||||
})
|
||||
.setDisabled(disable);
|
||||
// dataFilePathSetting.addExtraButton((button) => {
|
||||
// button
|
||||
// .setIcon('reset')
|
||||
// .setTooltip(i18nHelper.getMessage('121902'))
|
||||
// .onClick(async () => {
|
||||
// config.dataFileNamePath = placeHolder
|
||||
// this.showOutiFleName(containerEl, config, disable);
|
||||
// });
|
||||
// })
|
||||
}
|
||||
|
||||
showOutputFolderSelections(containerEl: HTMLElement, config: SyncConfig, disable:boolean) {
|
||||
const placeHolder:string = this.plugin.settings.dataFilePath ? this.plugin.settings.dataFilePath : DEFAULT_SETTINGS.dataFilePath;
|
||||
new Setting(containerEl)
|
||||
.setName( i18nHelper.getMessage('121501'))
|
||||
.setDesc( i18nHelper.getMessage('121502'))
|
||||
@ -253,7 +243,7 @@ export class DoubanSyncModal extends Modal {
|
||||
// @ts-ignore
|
||||
search.setValue(config.dataFilePath)
|
||||
// @ts-ignore
|
||||
.setPlaceholder(placeHolder)
|
||||
.setPlaceholder(i18nHelper.getMessage('121503'))
|
||||
.onChange(async (value: string) => {
|
||||
config.dataFilePath = value;
|
||||
});
|
||||
@ -265,7 +255,6 @@ export class DoubanSyncModal extends Modal {
|
||||
containerEl.empty();
|
||||
const key:string = this.getKey(config.syncType);
|
||||
// @ts-ignore
|
||||
const placeHolder:string = this.plugin.settings[key] ? this.plugin.settings[key] : DEFAULT_SETTINGS[key];
|
||||
let setting = new Setting(containerEl)
|
||||
.setName(i18nHelper.getMessage('121101'))
|
||||
.setDesc(i18nHelper.getMessage('121102'))
|
||||
@ -274,7 +263,6 @@ export class DoubanSyncModal extends Modal {
|
||||
// @ts-ignore
|
||||
search.setValue(config.templateFile)
|
||||
// @ts-ignore
|
||||
.setPlaceholder(placeHolder)
|
||||
.onChange(async (value: string) => {
|
||||
config.templateFile = value;
|
||||
});
|
||||
@ -323,6 +311,8 @@ export class DoubanSyncModal extends Modal {
|
||||
.setDisabled(disable);
|
||||
}
|
||||
|
||||
|
||||
|
||||
showAttachmentsFileConfig(containerEl: HTMLElement, config: SyncConfig, disable:boolean) {
|
||||
const settings = new Setting(containerEl);
|
||||
let attachmentFileEl = containerEl.createDiv('attachment-file-path-selection');
|
||||
@ -346,7 +336,6 @@ export class DoubanSyncModal extends Modal {
|
||||
if (!show) {
|
||||
return;
|
||||
}
|
||||
const placeHolder:string = this.plugin.settings.attachmentPath ? this.plugin.settings.attachmentPath : DEFAULT_SETTINGS.attachmentPath;
|
||||
new Setting(containerEl)
|
||||
.setName( i18nHelper.getMessage('121432'))
|
||||
.setDesc( i18nHelper.getMessage('121433'))
|
||||
@ -355,7 +344,7 @@ export class DoubanSyncModal extends Modal {
|
||||
// @ts-ignore
|
||||
search.setValue(config.attachmentPath)
|
||||
// @ts-ignore
|
||||
.setPlaceholder(placeHolder)
|
||||
.setPlaceholder(i18nHelper.getMessage('121434'))
|
||||
.onChange(async (value: string) => {
|
||||
config.attachmentPath = value;
|
||||
});
|
||||
@ -363,4 +352,19 @@ export class DoubanSyncModal extends Modal {
|
||||
.setDisabled(disable);
|
||||
}
|
||||
|
||||
showUpdateAllConfig(containerEl: HTMLElement, config: SyncConfig, disable:boolean) {
|
||||
new Setting(containerEl)
|
||||
.setName(i18nHelper.getMessage('110039'))
|
||||
.setDesc(i18nHelper.getMessage('110040'))
|
||||
.addToggle((toggleComponent) => {
|
||||
toggleComponent
|
||||
.setTooltip(i18nHelper.getMessage('110040'))
|
||||
.setValue(config.incrementalUpdate)
|
||||
.onChange(async (value) => {
|
||||
config.incrementalUpdate = value;
|
||||
});
|
||||
})
|
||||
.setDisabled(disable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -160,9 +160,9 @@ export default abstract class DoubanAbstractLoadHandler<T extends DoubanSubject>
|
||||
log.error(i18nHelper.getMessage('130101', e.toString()), e);
|
||||
if (url) {
|
||||
let id = StringUtil.analyzeIdByUrl(url);
|
||||
context.syncStatusHolder?context.syncStatusHolder.fail(id, ''):null;
|
||||
context.syncStatusHolder?context.syncStatusHolder.syncFail(id, ''):null;
|
||||
}else {
|
||||
context.syncStatusHolder?context.syncStatusHolder.handled(1):null;
|
||||
context.syncStatusHolder?context.syncStatusHolder.syncHandled(1):null;
|
||||
|
||||
}
|
||||
});
|
||||
@ -338,12 +338,14 @@ export default abstract class DoubanAbstractLoadHandler<T extends DoubanSubject>
|
||||
|
||||
private async getTemplate(extract: T, context: HandleContext): Promise<string> {
|
||||
const {syncConfig} = context;
|
||||
if (syncConfig && syncConfig.templateFile) {
|
||||
if (syncConfig) {
|
||||
if(syncConfig.templateFile) {
|
||||
const val = await this.doubanPlugin.fileHandler.getFileContent(syncConfig.templateFile);
|
||||
if (val) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
const tempKey: TemplateKey = this.getTemplateKey();
|
||||
const templatePath: string = context.settings[tempKey];
|
||||
let useUserState:boolean = context.userComponent.isLogin() &&
|
||||
|
||||
@ -7,6 +7,7 @@ import DoubanPlugin from "../../../main";
|
||||
import SyncStatusHolder from "../../sync/model/SyncStatusHolder";
|
||||
import {SyncConfig} from "../../sync/model/SyncConfig";
|
||||
import DoubanSubject from "./DoubanSubject";
|
||||
import GlobalStatusHolder from "../../model/GlobalStatusHolder";
|
||||
|
||||
export default interface HandleContext {
|
||||
plugin:DoubanPlugin;
|
||||
@ -16,7 +17,7 @@ export default interface HandleContext {
|
||||
userComponent: UserComponent;
|
||||
netFileHandler: NetFileHandler;
|
||||
showAfterCreate?:boolean;
|
||||
syncStatusHolder?:SyncStatusHolder;
|
||||
syncStatusHolder?:GlobalStatusHolder;
|
||||
action:string;
|
||||
syncConfig?: SyncConfig;
|
||||
listItem?:DoubanSubject;
|
||||
|
||||
@ -1,17 +1,30 @@
|
||||
import GlobalSyncStatusHolder from "../sync/model/GlobalSyncStatusHolder";
|
||||
import {SyncConfig} from "../sync/model/SyncConfig";
|
||||
import {Notice} from "obsidian";
|
||||
import {App, Notice} from "obsidian";
|
||||
import {i18nHelper} from "../../lang/helper";
|
||||
import {SyncTypeRecords} from "../../constant/Constsant";
|
||||
import { SyncTypeRecords} from "../../constant/Constsant";
|
||||
import {DoubanSubjectState} from "../../constant/DoubanUserState";
|
||||
import SyncStatusHolder from "../sync/model/SyncStatusHolder";
|
||||
import DoubanPlugin from "../../main";
|
||||
import {HandleKey} from "../sync/model/HandledKey";
|
||||
import {HandleValue} from "../sync/model/HandleValue";
|
||||
|
||||
export default class GlobalStatusHolder {
|
||||
public syncStatus:GlobalSyncStatusHolder;
|
||||
public syncStatus:SyncStatusHolder;
|
||||
public syncStarted:boolean;
|
||||
public syncStartTime:number;
|
||||
|
||||
public completeSync() {
|
||||
private _app:App;
|
||||
private _plugin:DoubanPlugin;
|
||||
|
||||
|
||||
constructor(app:App, plugin:DoubanPlugin) {
|
||||
this._app = app;
|
||||
this._plugin = plugin;
|
||||
}
|
||||
|
||||
public async completeSync() {
|
||||
this.syncStarted = false;
|
||||
await this.saveHandledData();
|
||||
}
|
||||
|
||||
public startSync(syncConfigOut: SyncConfig):boolean {
|
||||
@ -21,7 +34,7 @@ export default class GlobalStatusHolder {
|
||||
new Notice(i18nHelper.getMessage('110008'), SyncTypeRecords[syncConfig.syncType], DoubanSubjectState[syncConfig.scope]);
|
||||
return false;
|
||||
}
|
||||
this.syncStatus = new GlobalSyncStatusHolder(syncConfigOut);
|
||||
this.syncStatus = new SyncStatusHolder(syncConfigOut);
|
||||
this.syncStarted = true;
|
||||
this.syncStartTime = new Date().getTime();
|
||||
return true;
|
||||
@ -29,10 +42,70 @@ export default class GlobalStatusHolder {
|
||||
|
||||
public stopSync() {
|
||||
this.syncStarted = false;
|
||||
|
||||
}
|
||||
|
||||
public syncing() {
|
||||
return this.syncStarted;
|
||||
}
|
||||
|
||||
public syncReplace(id:string, title:string) {
|
||||
this.syncStatus.replace(id, title);
|
||||
}
|
||||
|
||||
public syncExists(id:string, title:string) {
|
||||
this.syncStatus.exists(id, title);
|
||||
}
|
||||
|
||||
public syncCreate(id:string, title:string) {
|
||||
this.syncStatus.create(id, title);
|
||||
}
|
||||
|
||||
public syncFail(id:string, title:string) {
|
||||
this.syncStatus.fail(id, title);
|
||||
}
|
||||
|
||||
public putSyncHandledData(handledData:Map<HandleKey, Set<HandleValue>>) {
|
||||
this.syncStatus.handledData = handledData;
|
||||
}
|
||||
|
||||
public initSyncHandledData() {
|
||||
this.putSyncHandledData(this._plugin.settings.syncHandledData);
|
||||
const incrementalUpdate:boolean = this.syncStatus.syncConfig.incrementalUpdate;
|
||||
if (incrementalUpdate == false) {
|
||||
this.syncStatus.resetSyncHandledSet();
|
||||
}
|
||||
}
|
||||
|
||||
public setTotal(total:number) {
|
||||
this.syncStatus.setTotal(total);
|
||||
}
|
||||
|
||||
syncHandled(num:number) {
|
||||
this.syncStatus.handled(num);
|
||||
}
|
||||
|
||||
syncTotalNum(num:number) {
|
||||
this.syncStatus.setTotal(num);
|
||||
}
|
||||
|
||||
getSyncTotal():number {
|
||||
return this.syncStatus.getTotal();
|
||||
}
|
||||
|
||||
getSyncHandle():number {
|
||||
return this.syncStatus.getHandle();
|
||||
}
|
||||
|
||||
private async saveHandledData() {
|
||||
if(!this.syncStatus || !this.syncStatus.handledData) {
|
||||
return;
|
||||
}
|
||||
this._plugin.settings.syncHandledData = this.syncStatus.handledData;
|
||||
await this._plugin.saveSettings();
|
||||
|
||||
}
|
||||
|
||||
shouldSync(id: string) {
|
||||
return this.syncStatus.shouldSync(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
import {CustomProperty} from "./CustomProperty";
|
||||
import {SyncConfig} from "../../sync/model/SyncConfig";
|
||||
import {HandleKey} from "../../sync/model/HandledKey";
|
||||
import {HandleValue} from "../../sync/model/HandleValue";
|
||||
|
||||
export interface DoubanPluginSetting {
|
||||
movieTemplateFile: string,
|
||||
@ -21,4 +24,5 @@ export interface DoubanPluginSetting {
|
||||
loginCookiesContent: string,
|
||||
cacheImage: boolean,
|
||||
attachmentPath: string,
|
||||
syncHandledData?:Map<HandleKey, Set<HandleValue>>,
|
||||
}
|
||||
|
||||
@ -71,9 +71,11 @@ export abstract class DoubanAbstractSyncHandler<T extends DoubanSubject> implem
|
||||
if (!context.plugin.statusHolder.syncing()) {
|
||||
return;
|
||||
}
|
||||
if(context.syncStatusHolder.shouldSync(item.id)) {
|
||||
await this.doubanSubjectLoadHandler.handle(item.url, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -48,9 +48,9 @@ export default class SyncHandler {
|
||||
|
||||
async showResult() {
|
||||
const {syncStatusHolder} = this.context;
|
||||
const {statusHandleMap} = syncStatusHolder;
|
||||
const {syncResultMap} = syncStatusHolder;
|
||||
let summary:string = `${i18nHelper.getMessage('syncall')}: ${syncStatusHolder.getTotal()}
|
||||
const {statusHandleMap} = syncStatusHolder.syncStatus;
|
||||
const {syncResultMap} = syncStatusHolder.syncStatus;
|
||||
let summary:string = `${i18nHelper.getMessage('syncall')}: ${syncStatusHolder.getSyncTotal()}
|
||||
`;
|
||||
for (const [key, value] of statusHandleMap) {
|
||||
// @ts-ignore
|
||||
@ -63,7 +63,7 @@ export default class SyncHandler {
|
||||
details+= `${value.id}-[[${value.title}]]: ${i18nHelper.getMessage(value.status)}
|
||||
`;
|
||||
}
|
||||
summary+= `${i18nHelper.getMessage('notsync')}: ${syncStatusHolder.getTotal() - syncStatusHolder.getHandle()}
|
||||
summary+= `${i18nHelper.getMessage('notsync')}: ${syncStatusHolder.getSyncTotal() - syncStatusHolder.getSyncHandle()}
|
||||
`
|
||||
|
||||
const result : string = i18nHelper.getMessage('110037', summary, details);
|
||||
|
||||
@ -8,7 +8,7 @@ export default class GlobalSyncStatusHolder {
|
||||
|
||||
constructor(syncConfig: SyncConfig) {
|
||||
this.syncConfig = syncConfig;
|
||||
this.total = 100;
|
||||
this.total = 0;
|
||||
this.handle = 0;
|
||||
}
|
||||
|
||||
|
||||
3
src/org/wanxp/douban/sync/model/HandleValue.ts
Normal file
3
src/org/wanxp/douban/sync/model/HandleValue.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export interface HandleValue {
|
||||
v: string;
|
||||
}
|
||||
3
src/org/wanxp/douban/sync/model/HandledKey.ts
Normal file
3
src/org/wanxp/douban/sync/model/HandledKey.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export interface HandleKey {
|
||||
k: string;
|
||||
}
|
||||
@ -1,10 +1,11 @@
|
||||
export interface SyncConfig {
|
||||
syncType: string,
|
||||
scope: string,
|
||||
force:boolean,
|
||||
dataFilePath:string;
|
||||
dataFileNamePath:string;
|
||||
force: boolean,
|
||||
dataFilePath: string;
|
||||
dataFileNamePath: string;
|
||||
cacheImage:boolean;
|
||||
attachmentPath:string;
|
||||
templateFile:string;
|
||||
attachmentPath: string;
|
||||
templateFile: string;
|
||||
incrementalUpdate: boolean;
|
||||
}
|
||||
|
||||
@ -2,10 +2,12 @@ import {SyncConfig} from "./SyncConfig";
|
||||
import GlobalSyncStatusHolder from "./GlobalSyncStatusHolder";
|
||||
import {SyncItemResult} from "./SyncItemResult";
|
||||
import {SyncItemStatus} from "../../../constant/Constsant";
|
||||
import GlobalStatusHolder from "../../model/GlobalStatusHolder";
|
||||
import {HandleKey} from "./HandledKey";
|
||||
import {HandleValue} from "./HandleValue";
|
||||
|
||||
export default class SyncStatusHolder extends GlobalSyncStatusHolder{
|
||||
|
||||
public handledData: Map<HandleKey, Set<HandleValue>>;
|
||||
public syncResultMap: Map<string, SyncItemResult> = new Map();
|
||||
public statusHandleMap: Map<SyncItemStatus, number> = new Map([
|
||||
[SyncItemStatus.exists, 0],
|
||||
@ -13,23 +15,23 @@ export default class SyncStatusHolder extends GlobalSyncStatusHolder{
|
||||
[SyncItemStatus.create, 0],
|
||||
[SyncItemStatus.fail, 0],
|
||||
]);
|
||||
private globalStatus:GlobalStatusHolder;
|
||||
|
||||
|
||||
constructor(syncConfig: SyncConfig, globalStatus: GlobalStatusHolder) {
|
||||
constructor(syncConfig: SyncConfig) {
|
||||
super(syncConfig)
|
||||
this.globalStatus = globalStatus;
|
||||
}
|
||||
|
||||
public replace(id:string, title:string) {
|
||||
this.putToHandled(id, title);
|
||||
this.updateResult(id, title, SyncItemStatus.replace);
|
||||
}
|
||||
|
||||
public exists(id:string, title:string) {
|
||||
this.putToHandled(id, title);
|
||||
this.updateResult(id, title, SyncItemStatus.exists);
|
||||
}
|
||||
|
||||
public create(id:string, title:string) {
|
||||
this.putToHandled(id, title);
|
||||
this.updateResult(id, title, SyncItemStatus.create);
|
||||
}
|
||||
|
||||
@ -41,16 +43,36 @@ export default class SyncStatusHolder extends GlobalSyncStatusHolder{
|
||||
this.syncResultMap.set(id, {id: id,title:title,status:status});
|
||||
this.statusHandleMap.set(status, this.statusHandleMap.get(status) + 1);
|
||||
super.handled(1);
|
||||
if (this.globalStatus.syncing()) {
|
||||
this.globalStatus.syncStatus.handled(1);
|
||||
}
|
||||
}
|
||||
|
||||
public setTotal(total:number) {
|
||||
super.totalNum(total);
|
||||
this.globalStatus.syncStatus.totalNum(total);
|
||||
}
|
||||
|
||||
|
||||
private putToHandled(id: string, title: string) {
|
||||
if (!this.handledData) {
|
||||
this.handledData = new Map<HandleKey, Set<HandleValue>>();
|
||||
}
|
||||
const key = {k: this.syncConfig.dataFilePath}
|
||||
if (!this.handledData.has(key)) {
|
||||
this.handledData.set(key, new Set<HandleValue>());
|
||||
}
|
||||
this.handledData.get(key).add({v:id})
|
||||
}
|
||||
|
||||
resetSyncHandledSet() {
|
||||
if (!this.handledData) {
|
||||
return;
|
||||
}
|
||||
const key = {k: this.syncConfig.dataFilePath}
|
||||
if (this.handledData.has(key)) {
|
||||
this.handledData.set(key, new Set<HandleValue>());
|
||||
}
|
||||
}
|
||||
|
||||
shouldSync(id: string) {
|
||||
const key = {k: this.syncConfig.dataFilePath}
|
||||
return !this.handledData.get(key).has({v:id});
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,6 +33,11 @@ export default {
|
||||
PS: This file could be delete if you want to.
|
||||
`,
|
||||
'110038': `DoubanSyncResult`,
|
||||
'110039': `SyncNotSync:`,
|
||||
'110040': `Only sync that haven't been synced yet. if not enabled, will sync all the subject'`,
|
||||
'110041': `If`,
|
||||
|
||||
|
||||
'exists':`[exists]`,
|
||||
'replace':`[replace]`,
|
||||
'create':`[create]`,
|
||||
@ -182,6 +187,7 @@ PS: This file could be delete if you want to.
|
||||
'121601': `Note Name`,
|
||||
'121602': `Nodes created from Obsidian-Douban will use this fileName as template(also support filePath),
|
||||
If blank, they will be created by default name. support all basic template variables. example: {{type}}/{{title}}`,
|
||||
'121603': `assets`,
|
||||
|
||||
'121701': `Search Template File`,
|
||||
// '121702': `Movie created from Obsidian-Douban will be placed in this folder, If blank, they will be placed in the default location for this vault. `,
|
||||
|
||||
@ -35,6 +35,9 @@ export default {
|
||||
注:此文档可删除
|
||||
`,
|
||||
'110038': `豆瓣同步结果`,
|
||||
'110039': `增量同步:`,
|
||||
'110040': `仅同步上面'笔记存放位置'目录中最近新增/同步失败/未同步的部分,不同步已同步的内容.若关闭则会全量同步.增量同步会更快,适合之前同步中途失败停止或最近有豆瓣新增了内容,全量同步适合修改了模板或修改了存放路径情况下进行.`,
|
||||
'110041': `使用增量`,
|
||||
|
||||
'exists':`[未替换]`,
|
||||
'replace':`[已替换]`,
|
||||
|
||||
@ -44,7 +44,7 @@ export default class DoubanPlugin extends Plugin {
|
||||
return;
|
||||
}
|
||||
if (Action.Sync == context.action) {
|
||||
this.showStatus(i18nHelper.getMessage('140207', syncStatusHolder.getHandle(), syncStatusHolder.getTotal(), extract.title));
|
||||
this.showStatus(i18nHelper.getMessage('140207', syncStatusHolder.getSyncHandle(), syncStatusHolder.getSyncTotal(), extract.title));
|
||||
}else {
|
||||
this.showStatus(i18nHelper.getMessage('140204', extract.title));
|
||||
}
|
||||
@ -53,13 +53,13 @@ export default class DoubanPlugin extends Plugin {
|
||||
await this.putContentToObsidian(context, result);
|
||||
}
|
||||
if (Action.Sync == context.action) {
|
||||
this.showStatus(i18nHelper.getMessage('140208', syncStatusHolder.getHandle(), syncStatusHolder.getTotal(), extract.title));
|
||||
this.showStatus(i18nHelper.getMessage('140208', syncStatusHolder.getSyncHandle(), syncStatusHolder.getSyncTotal(), extract.title));
|
||||
}else {
|
||||
this.showStatus(i18nHelper.getMessage('140205', extract.title));
|
||||
}
|
||||
} catch (e) {
|
||||
log.error(i18nHelper.getMessage('140206', e.message), e);
|
||||
syncStatusHolder!=null?syncStatusHolder.fail(extract.id, extract.title):null;
|
||||
syncStatusHolder!=null?syncStatusHolder.syncFail(extract.id, extract.title):null;
|
||||
} finally {
|
||||
this.clearStatusBarDelay();
|
||||
}
|
||||
@ -93,16 +93,16 @@ export default class DoubanPlugin extends Plugin {
|
||||
const {subject} = result;
|
||||
const {content} = result;
|
||||
if (Action.Sync == context.action) {
|
||||
if (context.syncStatusHolder.syncConfig.force) {
|
||||
if (context.syncStatusHolder.syncStatus.syncConfig.force) {
|
||||
const exists:boolean = await this.fileHandler.createOrReplaceNewNoteWithData(filePath, content, context.showAfterCreate);
|
||||
if (exists) {
|
||||
syncStatusHolder != null ? syncStatusHolder.replace(subject.id, subject.title):null;
|
||||
syncStatusHolder != null ? syncStatusHolder.syncReplace(subject.id, subject.title):null;
|
||||
}else {
|
||||
syncStatusHolder != null ?syncStatusHolder.create(subject.id, subject.title):null;
|
||||
syncStatusHolder != null ?syncStatusHolder.syncCreate(subject.id, subject.title):null;
|
||||
}
|
||||
}else {
|
||||
const created:boolean = await this.fileHandler.createNewNoteWithData(filePath, content, context.showAfterCreate, false);
|
||||
created ?syncStatusHolder.create(subject.id, subject.title):syncStatusHolder.exists(subject.id, subject.title);
|
||||
created ?syncStatusHolder.syncCreate(subject.id, subject.title):syncStatusHolder.syncExists(subject.id, subject.title);
|
||||
}
|
||||
}else {
|
||||
await this.fileHandler.createNewNoteWithData(filePath, content, context.showAfterCreate);
|
||||
@ -198,7 +198,8 @@ export default class DoubanPlugin extends Plugin {
|
||||
settings: this.settings,
|
||||
userComponent: this.userComponent,
|
||||
netFileHandler: this.netFileHandler,
|
||||
action: Action.Sync}),
|
||||
action: Action.Sync,
|
||||
syncStatusHolder: this.statusHolder}),
|
||||
});
|
||||
|
||||
this.settingsManager = new SettingsManager(app, this);
|
||||
@ -209,7 +210,7 @@ export default class DoubanPlugin extends Plugin {
|
||||
}
|
||||
|
||||
this.addSettingTab(new DoubanSettingTab(this.app, this));
|
||||
this.statusHolder = new GlobalStatusHolder();
|
||||
this.statusHolder = new GlobalStatusHolder(this.app, this);
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
@ -248,9 +249,10 @@ export default class DoubanPlugin extends Plugin {
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
context.syncStatusHolder = new SyncStatusHolder(syncConfig, this.statusHolder);
|
||||
// @ts-ignore
|
||||
new Notice(i18nHelper.getMessage('140301', SyncTypeRecords[syncConfig.syncType]));
|
||||
this.initSyncDefaultSettings(syncConfig);
|
||||
context.syncStatusHolder.initSyncHandledData();
|
||||
|
||||
// @ts-ignore
|
||||
this.showStatus(i18nHelper.getMessage('140203', SyncTypeRecords[syncConfig.syncType]));
|
||||
@ -260,7 +262,7 @@ export default class DoubanPlugin extends Plugin {
|
||||
} catch (e) {
|
||||
log.error(i18nHelper.getMessage('140206', e.message), e);
|
||||
} finally {
|
||||
context.plugin.statusHolder.completeSync();
|
||||
await context.plugin.statusHolder.completeSync();
|
||||
this.clearStatusBarDelay();
|
||||
}
|
||||
}
|
||||
@ -278,5 +280,12 @@ export default class DoubanPlugin extends Plugin {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private initSyncDefaultSettings(syncConfig: SyncConfig) {
|
||||
syncConfig.dataFilePath = syncConfig.dataFilePath ? syncConfig.dataFilePath : DEFAULT_SETTINGS.dataFilePath;
|
||||
syncConfig.templateFile = syncConfig.templateFile ? syncConfig.templateFile : '';
|
||||
syncConfig.attachmentPath = syncConfig.attachmentPath ? syncConfig.attachmentPath : DEFAULT_SETTINGS.attachmentPath;
|
||||
syncConfig.dataFileNamePath = syncConfig.dataFileNamePath ? syncConfig.dataFileNamePath : DEFAULT_SETTINGS.dataFileNamePath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user