mirror of
https://github.com/Wanxp/obsidian-douban.git
synced 2026-04-04 16:48:44 +08:00
add subject user rate info
This commit is contained in:
parent
1f30482542
commit
d212be5a75
@ -71,3 +71,11 @@ export const PersonNameModeRecords: { [key in PersonNameMode]: string } = {
|
|||||||
[PersonNameMode.CH_EN_NAME]: i18nHelper.getMessage('121208'),
|
[PersonNameMode.CH_EN_NAME]: i18nHelper.getMessage('121208'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum DoubanSubjectState {
|
||||||
|
NOT = 'have_not_watched',
|
||||||
|
WANTED = 'wanted',
|
||||||
|
DOING = 'watching',
|
||||||
|
HAS = 'watched',
|
||||||
|
UNKNOWN = 'unknown',
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,3 @@
|
|||||||
import {PersonNameMode} from "./Constsant";
|
|
||||||
import {DoubanPluginSetting} from "@App/setting/model/DoubanPluginSetting";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const doubanHeaders = {
|
export const doubanHeaders = {
|
||||||
|
|||||||
@ -10,8 +10,10 @@ import {log} from "../../utils/Logutil";
|
|||||||
export default class DoubanLogoutModel {
|
export default class DoubanLogoutModel {
|
||||||
private modal: any;
|
private modal: any;
|
||||||
private settingsManager: SettingsManager;
|
private settingsManager: SettingsManager;
|
||||||
|
private containerEl: HTMLElement;
|
||||||
constructor(containerEl: HTMLElement, settingsManager: SettingsManager) {
|
constructor(containerEl: HTMLElement, settingsManager: SettingsManager) {
|
||||||
this.settingsManager = settingsManager;
|
this.settingsManager = settingsManager;
|
||||||
|
this.containerEl = containerEl;
|
||||||
const { remote } = require('electron');
|
const { remote } = require('electron');
|
||||||
const { BrowserWindow: RemoteBrowserWindow } = remote;
|
const { BrowserWindow: RemoteBrowserWindow } = remote;
|
||||||
this.modal = new RemoteBrowserWindow({
|
this.modal = new RemoteBrowserWindow({
|
||||||
@ -31,7 +33,7 @@ export default class DoubanLogoutModel {
|
|||||||
session.webRequest.onCompleted(filter, (details:any) => {
|
session.webRequest.onCompleted(filter, (details:any) => {
|
||||||
if (details.statusCode == 200) {
|
if (details.statusCode == 200) {
|
||||||
this.settingsManager.plugin.userComponent.logout();
|
this.settingsManager.plugin.userComponent.logout();
|
||||||
constructDoubanTokenSettingsUI(containerEl, settingsManager);
|
constructDoubanTokenSettingsUI(this.containerEl, this.settingsManager);
|
||||||
this.modal.close();
|
this.modal.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import {CheerioAPI, load} from "cheerio";
|
|||||||
import YamlUtil from "../../../utils/YamlUtil";
|
import YamlUtil from "../../../utils/YamlUtil";
|
||||||
import {
|
import {
|
||||||
BasicConst,
|
BasicConst,
|
||||||
|
DoubanSubjectState,
|
||||||
PersonNameMode,
|
PersonNameMode,
|
||||||
SearchHandleMode,
|
SearchHandleMode,
|
||||||
SupportType,
|
SupportType,
|
||||||
@ -19,6 +20,7 @@ import HandleResult from "@App/data/model/HandleResult";
|
|||||||
import {getDefaultTemplateContent} from "../../../constant/DefaultTemplateContent";
|
import {getDefaultTemplateContent} from "../../../constant/DefaultTemplateContent";
|
||||||
import StringUtil from "../../../utils/StringUtil";
|
import StringUtil from "../../../utils/StringUtil";
|
||||||
import {DEFAULT_SETTINGS} from "../../../constant/DefaultSettings";
|
import {DEFAULT_SETTINGS} from "../../../constant/DefaultSettings";
|
||||||
|
import {UserStateSubject} from "@App/data/model/UserStateSubject";
|
||||||
|
|
||||||
export default abstract class DoubanAbstractLoadHandler<T extends DoubanSubject> implements DoubanSubjectLoadHandler<T> {
|
export default abstract class DoubanAbstractLoadHandler<T extends DoubanSubject> implements DoubanSubjectLoadHandler<T> {
|
||||||
|
|
||||||
@ -128,22 +130,36 @@ export default abstract class DoubanAbstractLoadHandler<T extends DoubanSubject>
|
|||||||
abstract support(extract: DoubanSubject): boolean;
|
abstract support(extract: DoubanSubject): boolean;
|
||||||
|
|
||||||
handle(url: string, context: HandleContext): void {
|
handle(url: string, context: HandleContext): void {
|
||||||
|
let headers = JSON.parse(this.doubanPlugin.settings.searchHeaders);
|
||||||
|
headers.Cookie = this.doubanPlugin.settings.loginCookiesContent;
|
||||||
|
console.log(JSON.stringify(headers))
|
||||||
const requestUrlParam: RequestUrlParam = {
|
const requestUrlParam: RequestUrlParam = {
|
||||||
url: url,
|
url: url,
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: JSON.parse(this.doubanPlugin.settings.searchHeaders),
|
headers: headers,
|
||||||
throw: true
|
throw: true
|
||||||
};
|
};
|
||||||
request(requestUrlParam)
|
request(requestUrlParam)
|
||||||
|
.then((response) => {console.log(response.toString());return response})
|
||||||
.then(load)
|
.then(load)
|
||||||
.then(this.parseSubjectFromHtml)
|
.then(this.analysisUserState)
|
||||||
|
.then(({data, userState}) => {
|
||||||
|
let sub = this.parseSubjectFromHtml(data);
|
||||||
|
sub.userState = userState;
|
||||||
|
return sub;
|
||||||
|
})
|
||||||
.then(content => this.toEditor(context, content))
|
.then(content => this.toEditor(context, content))
|
||||||
// .then(content => content ? editor.replaceSelection(content) : content)
|
// .then(content => content ? editor.replaceSelection(content) : content)
|
||||||
.catch(e => log.error(i18nHelper.getMessage('130101')))
|
.catch(e => log
|
||||||
|
.error(
|
||||||
|
i18nHelper.getMessage('130101')
|
||||||
|
.replace('{0}', e.toString())
|
||||||
|
));
|
||||||
;
|
;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
abstract parseSubjectFromHtml(data: CheerioAPI): T | undefined;
|
abstract parseSubjectFromHtml(data: CheerioAPI): T | undefined;
|
||||||
|
|
||||||
toEditor(context: HandleContext, extract: T): T {
|
toEditor(context: HandleContext, extract: T): T {
|
||||||
@ -287,4 +303,46 @@ export default abstract class DoubanAbstractLoadHandler<T extends DoubanSubject>
|
|||||||
return val ? val : defaultContent;
|
return val ? val : defaultContent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
analysisUserState(html: CheerioAPI): {data:CheerioAPI , userState: UserStateSubject} {
|
||||||
|
if(!html('.nav-user-account')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
let rate = html(html('input#n_rating').get(0)).val();
|
||||||
|
let tagsStr = html(html('div#interest_sect_level > div.a_stars > span.color_gray').get(0)).text().trim();
|
||||||
|
let tags = tagsStr.replace('标签:', '').split(' ');
|
||||||
|
let stateWord = html(html('div#interest_sect_level > div.a_stars > span.mr10').get(0)).text().trim();
|
||||||
|
let collectionDateStr = html(html('div#interest_sect_level > div.a_stars > span.mr10 > span.collection_date').get(0)).text().trim();
|
||||||
|
let userState1 = DoubanAbstractLoadHandler.getUserState(stateWord);
|
||||||
|
let component = html(html('div#interest_sect_level > div.a_stars > span.color_gray').get(0)).next().next().text().trim();
|
||||||
|
|
||||||
|
|
||||||
|
const userState: UserStateSubject = {
|
||||||
|
tags: tags,
|
||||||
|
rate: rate?Number(rate):null,
|
||||||
|
state: userState1,
|
||||||
|
collectionDate: collectionDateStr?moment(collectionDateStr, 'YYYY-MM-DD').toDate():null,
|
||||||
|
comment: component
|
||||||
|
}
|
||||||
|
return {data: html, userState: userState};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static getUserState(stateWord:string):DoubanSubjectState {
|
||||||
|
let state:DoubanSubjectState;
|
||||||
|
if(!stateWord) {
|
||||||
|
return DoubanSubjectState.UNKNOWN;
|
||||||
|
}
|
||||||
|
if(stateWord.indexOf('想')>=0 ) {
|
||||||
|
state = DoubanSubjectState.WANTED;
|
||||||
|
}else if(stateWord.indexOf('在')>=0) {
|
||||||
|
state = DoubanSubjectState.DOING;
|
||||||
|
}else if(stateWord.indexOf('过')>=0) {
|
||||||
|
state = DoubanSubjectState.HAS;
|
||||||
|
}else {
|
||||||
|
state = DoubanSubjectState.NOT;
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import {UserStateSubject} from "@App/data/model/UserStateSubject";
|
||||||
|
|
||||||
export default class DoubanSubject {
|
export default class DoubanSubject {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
@ -9,6 +11,7 @@ export default class DoubanSubject {
|
|||||||
publisher: string;
|
publisher: string;
|
||||||
datePublished: Date;
|
datePublished: Date;
|
||||||
genre: string[];
|
genre: string[];
|
||||||
|
userState?: UserStateSubject;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ParameterMap: Map<string, string> = new Map([
|
const ParameterMap: Map<string, string> = new Map([
|
||||||
|
|||||||
9
src/douban/data/model/UserStateSubject.ts
Normal file
9
src/douban/data/model/UserStateSubject.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import {DoubanSubjectState} from "../../../constant/Constsant";
|
||||||
|
|
||||||
|
export interface UserStateSubject {
|
||||||
|
tags: string[];
|
||||||
|
rate: number;
|
||||||
|
state: DoubanSubjectState;
|
||||||
|
comment: string;
|
||||||
|
collectionDate: Date;
|
||||||
|
}
|
||||||
@ -19,7 +19,7 @@ export default class Searcher {
|
|||||||
return request(requestUrlParam)
|
return request(requestUrlParam)
|
||||||
.then(load)
|
.then(load)
|
||||||
.then(SearchParserHandler.parseSearch)
|
.then(SearchParserHandler.parseSearch)
|
||||||
.catch(e => log.error(i18nHelper.getMessage('130101')))
|
.catch(e => log.error(i18nHelper.getMessage('130101').replace('{0}', e.toString())));
|
||||||
;
|
;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -150,7 +150,6 @@ export function constructHasLoginSettingsUI(containerEl: HTMLElement, manager: S
|
|||||||
const loginModel = new DoubanLogoutModel(containerEl, manager);
|
const loginModel = new DoubanLogoutModel(containerEl, manager);
|
||||||
await loginModel.doLogout();
|
await loginModel.doLogout();
|
||||||
button.setDisabled(false);
|
button.setDisabled(false);
|
||||||
// manager.updateSetting('loginCookiesContent', '');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,7 +78,7 @@ export default class UserComponent {
|
|||||||
return request(requestUrlParam)
|
return request(requestUrlParam)
|
||||||
.then(load)
|
.then(load)
|
||||||
.then(this.getUserInfo)
|
.then(this.getUserInfo)
|
||||||
.catch(e => log.error(i18nHelper.getMessage('130101')))
|
.catch(e => log.error(i18nHelper.getMessage('130101').replace('{0}', e.toString())));
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@ export default {
|
|||||||
'120006': `Just copy the web address to the current input box.`,
|
'120006': `Just copy the web address to the current input box.`,
|
||||||
|
|
||||||
'100101': `Login Douban`,
|
'100101': `Login Douban`,
|
||||||
|
'100111': `Douban login info Expired, please login again`,
|
||||||
|
|
||||||
|
|
||||||
'1210': `Basic Setting`,
|
'1210': `Basic Setting`,
|
||||||
@ -134,7 +135,7 @@ export default {
|
|||||||
|
|
||||||
|
|
||||||
//error
|
//error
|
||||||
'130101': `Fetch Data Error, You can go to Github add Issues`,
|
'130101': `Fetch Data Error, {0}`,
|
||||||
'140101': `Not support for current type. You can add Issues at Github:Wanxp/obsidian-douban`,
|
'140101': `Not support for current type. You can add Issues at Github:Wanxp/obsidian-douban`,
|
||||||
|
|
||||||
'140201': `[Obsidian Douban]: searching '{0}'...`,
|
'140201': `[Obsidian Douban]: searching '{0}'...`,
|
||||||
|
|||||||
@ -14,6 +14,8 @@ export default {
|
|||||||
'110202': `{0} 模板文件无法读取`,
|
'110202': `{0} 模板文件无法读取`,
|
||||||
|
|
||||||
'100101': `登录豆瓣`,
|
'100101': `登录豆瓣`,
|
||||||
|
'100111': `豆瓣登录信息过期,请至Douban插件重新登录`,
|
||||||
|
|
||||||
|
|
||||||
//DoubanSettingTab
|
//DoubanSettingTab
|
||||||
'1201': `Obsidian-豆瓣`,
|
'1201': `Obsidian-豆瓣`,
|
||||||
@ -131,7 +133,7 @@ export default {
|
|||||||
|
|
||||||
'121901': `复制'默认'模板内容`,
|
'121901': `复制'默认'模板内容`,
|
||||||
|
|
||||||
'130101': `获取数据失败,您如有需要请至Github提交Issues`,
|
'130101': `获取数据失败,{0}`,
|
||||||
'130102': `Obsidian Douban插件错误提示:`,
|
'130102': `Obsidian Douban插件错误提示:`,
|
||||||
'130103': `Obsidian Douban插件异常提示:`,
|
'130103': `Obsidian Douban插件异常提示:`,
|
||||||
'140101': `当前版本暂不支持该类型导入,请升级Obsidian Douban或至github提交issuess获取帮助`,
|
'140101': `当前版本暂不支持该类型导入,请升级Obsidian Douban或至github提交issuess获取帮助`,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user