add debug mode

This commit is contained in:
wanxp 2022-11-26 15:55:41 +08:00
parent a455baeb41
commit b3b9ab2c44
14 changed files with 165 additions and 5 deletions

@ -18,6 +18,7 @@ export const DEFAULT_SETTINGS: DoubanPluginSetting = {
dataFilePath: "", dataFilePath: "",
dataFileNamePath: "/{{type}}/{{title}}", dataFileNamePath: "/{{type}}/{{title}}",
statusBar: true, statusBar: true,
debugMode: false,
customProperties: [ customProperties: [
{name: 'myType', value: 'movie', field: SupportType.MOVIE}, {name: 'myType', value: 'movie', field: SupportType.MOVIE},
{name: 'myType', value: 'book', field: SupportType.BOOK}, {name: 'myType', value: 'book', field: SupportType.BOOK},

@ -4,6 +4,7 @@ import {i18nHelper} from "../../lang/helper";
import {DoubanSettingTab} from "../setting/DoubanSettingTab"; import {DoubanSettingTab} from "../setting/DoubanSettingTab";
import SettingsManager from "../setting/SettingsManager"; import SettingsManager from "../setting/SettingsManager";
import {constructDoubanTokenSettingsUI} from "../setting/BasicSettingsHelper"; import {constructDoubanTokenSettingsUI} from "../setting/BasicSettingsHelper";
import StringUtil from "../../utils/StringUtil";
// Credits go to zhaohongxuan's Weread Plugin : https://github.com/zhaohongxuan/obsidian-weread-plugin // Credits go to zhaohongxuan's Weread Plugin : https://github.com/zhaohongxuan/obsidian-weread-plugin
@ -15,7 +16,7 @@ export default class DoubanLoginModel {
constructor(containerEl: HTMLElement, settingsManager: SettingsManager) { constructor(containerEl: HTMLElement, settingsManager: SettingsManager) {
this.containerEl = containerEl; this.containerEl = containerEl;
this.settingsManager = settingsManager; this.settingsManager = settingsManager;
this.settingsManager.debug(`配置界面:初始化登录界面`)
const { remote } = require('electron'); const { remote } = require('electron');
const { BrowserWindow: RemoteBrowserWindow } = remote; const { BrowserWindow: RemoteBrowserWindow } = remote;
this.modal = new RemoteBrowserWindow({ this.modal = new RemoteBrowserWindow({
@ -30,6 +31,7 @@ export default class DoubanLoginModel {
this.modal.show(); this.modal.show();
}); });
this.modal.on('closed', () => { this.modal.on('closed', () => {
this.showCloseMessage();
constructDoubanTokenSettingsUI(this.containerEl, this.settingsManager); constructDoubanTokenSettingsUI(this.containerEl, this.settingsManager);
}); });
@ -38,15 +40,21 @@ export default class DoubanLoginModel {
urls: ['https://www.douban.com/','https://accounts.douban.com/','https://accounts.douban.com/passport/login'] urls: ['https://www.douban.com/','https://accounts.douban.com/','https://accounts.douban.com/passport/login']
}; };
session.webRequest.onSendHeaders(filter, async (details:any) => { session.webRequest.onSendHeaders(filter, async (details:any) => {
this.settingsManager.debug(`配置界面:登录界面请求头检测:${details.url}`)
const cookies = details.requestHeaders['Cookie']; const cookies = details.requestHeaders['Cookie'];
const cookieArr = this.parseCookies(cookies); const cookieArr = this.parseCookies(cookies);
// const wr_name = cookieArr.find((cookie) => cookie.name == 'wr_name').value; // const wr_name = cookieArr.find((cookie) => cookie.name == 'wr_name').value;
if (cookieArr) { if (cookieArr) {
this.settingsManager.debug(`配置界面:登录界面请求检测获取到Cookie`)
let user = await settingsManager.plugin.userComponent.loginCookie(cookieArr); let user = await settingsManager.plugin.userComponent.loginCookie(cookieArr);
if (user && user.login) { if (user && user.login) {
this.settingsManager.debug(`配置界面:登录界面豆瓣登录成功, 信息:id:${StringUtil.confuse(user.id)}:, 用户名:${StringUtil.confuse(user.name)}`)
this.onClose(); this.onClose();
return;
} }
this.settingsManager.debug(`配置界面:登录界面豆瓣登录失败, cookies未能成功获取用户信息`)
} else { } else {
this.settingsManager.debug(`配置界面:登录界面请求检测没有获取到Cookie`)
this.onReload(); this.onReload();
} }
}); });
@ -58,6 +66,7 @@ export default class DoubanLoginModel {
async doLogin() { async doLogin() {
try { try {
this.settingsManager.debug(`配置界面:登录界面加载登录页面`)
await this.modal.loadURL('https://accounts.douban.com/passport/login'); await this.modal.loadURL('https://accounts.douban.com/passport/login');
} catch (error) { } catch (error) {
log.error(i18nHelper.getMessage('100101'), error) log.error(i18nHelper.getMessage('100101'), error)
@ -65,10 +74,20 @@ export default class DoubanLoginModel {
} }
onClose() { onClose() {
this.settingsManager.debug(`配置界面:登录界面关闭, 自动退出登录界面`)
this.modal.close(); this.modal.close();
} }
onReload() { onReload() {
this.settingsManager.debug(`配置界面:登录界面重新加载`)
this.modal.reload(); this.modal.reload();
} }
private showCloseMessage() {
if(this.settingsManager.plugin.userComponent.isLogin()) {
this.settingsManager.debug(`配置界面:登录界面关闭, 但未检测到登出, 登录失败`)
}else {
this.settingsManager.debug(`配置界面:登录界面关闭, 登录成功`)
}
}
} }

@ -13,6 +13,7 @@ export default class DoubanLogoutModel {
private containerEl: HTMLElement; private containerEl: HTMLElement;
constructor(containerEl: HTMLElement, settingsManager: SettingsManager) { constructor(containerEl: HTMLElement, settingsManager: SettingsManager) {
this.settingsManager = settingsManager; this.settingsManager = settingsManager;
this.settingsManager.debug(`配置界面:初始化登出界面`)
this.containerEl = containerEl; this.containerEl = containerEl;
const { remote } = require('electron'); const { remote } = require('electron');
const { BrowserWindow: RemoteBrowserWindow } = remote; const { BrowserWindow: RemoteBrowserWindow } = remote;
@ -27,6 +28,7 @@ export default class DoubanLogoutModel {
this.modal.show(); this.modal.show();
}); });
this.modal.on('closed', () => { this.modal.on('closed', () => {
this.showCloseMessage();
constructDoubanTokenSettingsUI(this.containerEl, this.settingsManager); constructDoubanTokenSettingsUI(this.containerEl, this.settingsManager);
}); });
const session = this.modal.webContents.session; const session = this.modal.webContents.session;
@ -35,20 +37,33 @@ export default class DoubanLogoutModel {
'https://www.douban.com/accounts/logout'] 'https://www.douban.com/accounts/logout']
}; };
session.webRequest.onSendHeaders(filter, (details:any) => { session.webRequest.onSendHeaders(filter, (details:any) => {
this.settingsManager.debug(`配置界面:登出界面请求头检测:${details.url}`)
const cookies = details.requestHeaders['Cookie']; const cookies = details.requestHeaders['Cookie'];
// const wr_name = cookieArr.find((cookie) => cookie.name == 'wr_name').value; // const wr_name = cookieArr.find((cookie) => cookie.name == 'wr_name').value;
if (cookies && cookies.indexOf('dbcl2') < 0) { if (cookies && cookies.indexOf('dbcl2') < 0) {
this.settingsManager.debug(`配置界面:登出界面退出登录请求检测成功,准备退出登录`)
this.settingsManager.plugin.userComponent.logout(); this.settingsManager.plugin.userComponent.logout();
this.settingsManager.debug(`配置界面:登出界面退出登录成功`)
this.onClose(); this.onClose();
} }
}); });
} }
async doLogout() { async doLogout() {
this.settingsManager.debug(`配置界面:登出界面加载登出页面`)
await this.modal.loadURL('https://www.douban.com/accounts/logout?source=main&ck=DfFJ'); await this.modal.loadURL('https://www.douban.com/accounts/logout?source=main&ck=DfFJ');
} }
onClose() { onClose() {
this.settingsManager.debug(`配置界面:登出界面关闭, 自动退出登出界面`)
this.modal.close(); this.modal.close();
} }
private showCloseMessage() {
if(this.settingsManager.plugin.userComponent.isLogin()) {
this.settingsManager.debug(`配置界面:登出界面关闭, 但未检测到登出, 退出登录失败`)
}else {
this.settingsManager.debug(`配置界面:登出界面关闭, 退出登录成功`)
}
}
} }

@ -0,0 +1,57 @@
import {i18nHelper} from "../../lang/helper";
import {Platform, Setting} from "obsidian";
import {DEFAULT_SETTINGS} from "../../constant/DefaultSettings";
import SettingsManager from "./SettingsManager";
import DoubanLoginModel from "../component/DoubanLoginModel";
import DoubanLogoutModel from "../component/DoubanLogoutModel";
import User from "../user/User";
import {createFolderSelectionSetting} from "./TemplateSettingHelper";
import { log } from "../../utils/Logutil";
export function constructAdvancedUI(containerEl: HTMLElement, manager: SettingsManager) {
containerEl.createEl('h3', { text: i18nHelper.getMessage('1250') });
containerEl.createEl('p', { text: i18nHelper.getMessage('1252') });
const settings:Setting = new Setting(containerEl);
const advancedSettings = containerEl.createDiv('advanced-settings');
settings.setDesc(i18nHelper.getMessage('1251')).addExtraButton((extraButton) => {
extraButton
.setIcon('reset')
.setTooltip(i18nHelper.getMessage('121905'))
.onClick(async () => {
resetAdvanced(manager);
await manager.plugin.saveSettings();
showAdvancedSettings(advancedSettings, manager)
});
})
showAdvancedSettings(advancedSettings, manager);
}
function showAdvancedSettings(containerEl: HTMLElement, manager: SettingsManager) {
containerEl.empty();
new Setting(containerEl)
.setName(i18nHelper.getMessage('125001'))
.setDesc(i18nHelper.getMessage('125002'))
.addToggle((toggleComponent) => {
toggleComponent
// .setTooltip(i18nHelper.getMessage('121403'))
.setValue(manager.plugin.settings.debugMode)
.onChange(async (value) => {
manager.plugin.settings.debugMode = value;
if (value) {
log.info("调试模式开启");
}else{
log.info("调试模式关闭");
}
await manager.plugin.saveSettings();
});
});
}
function resetAdvanced( manager: SettingsManager) {
log.info("调试模式关闭");
manager.plugin.settings.debugMode = false;
}

@ -6,6 +6,7 @@ import DoubanLoginModel from "../component/DoubanLoginModel";
import DoubanLogoutModel from "../component/DoubanLogoutModel"; import DoubanLogoutModel from "../component/DoubanLogoutModel";
import User from "../user/User"; import User from "../user/User";
import {createFolderSelectionSetting} from "./TemplateSettingHelper"; import {createFolderSelectionSetting} from "./TemplateSettingHelper";
import StringUtil from "../../utils/StringUtil";
export function constructBasicUI(containerEl: HTMLElement, manager: SettingsManager) { export function constructBasicUI(containerEl: HTMLElement, manager: SettingsManager) {
containerEl.createEl('h3', { text: i18nHelper.getMessage('1210') }); containerEl.createEl('h3', { text: i18nHelper.getMessage('1210') });
@ -102,6 +103,7 @@ export function constructBasicUI(containerEl: HTMLElement, manager: SettingsMana
export function constructDoubanTokenSettingsUI(containerEl: HTMLElement, manager: SettingsManager) { export function constructDoubanTokenSettingsUI(containerEl: HTMLElement, manager: SettingsManager) {
containerEl.empty(); containerEl.empty();
let login = manager.plugin.userComponent.isLogin(); let login = manager.plugin.userComponent.isLogin();
manager.debug(`配置界面:展示豆瓣状态:${login?'已登录':'未登录'}`)
if (Platform.isDesktopApp) { if (Platform.isDesktopApp) {
if(login) { if(login) {
constructHasLoginSettingsUI(containerEl, manager); constructHasLoginSettingsUI(containerEl, manager);
@ -121,12 +123,14 @@ export function constructDoubanTokenSettingsUI(containerEl: HTMLElement, manager
export function constructLoginSettingsUI(containerEl: HTMLElement, manager: SettingsManager) { export function constructLoginSettingsUI(containerEl: HTMLElement, manager: SettingsManager) {
manager.debug(`配置界面:未登录-展示登录按钮`)
new Setting(containerEl).setName(i18nHelper.getMessage('100131')).addButton((button) => { new Setting(containerEl).setName(i18nHelper.getMessage('100131')).addButton((button) => {
return button return button
.setButtonText(i18nHelper.getMessage('100130')) .setButtonText(i18nHelper.getMessage('100130'))
.setCta() .setCta()
.onClick(async () => { .onClick(async () => {
button.setDisabled(true); button.setDisabled(true);
manager.debug(`配置界面:点击登录按钮`)
const loginModel = new DoubanLoginModel(containerEl, manager); const loginModel = new DoubanLoginModel(containerEl, manager);
await loginModel.doLogin(); await loginModel.doLogin();
}); });
@ -141,7 +145,7 @@ export function constructHasLoginSettingsUI(containerEl: HTMLElement, manager: S
${i18nHelper.getMessage('100123')}: <a href="https://www.douban.com/people/${user.id}/">${user.id}</a><br> ${i18nHelper.getMessage('100123')}: <a href="https://www.douban.com/people/${user.id}/">${user.id}</a><br>
${i18nHelper.getMessage('100124')}: ${user.name}<br> ${i18nHelper.getMessage('100124')}: ${user.name}<br>
${i18nHelper.getMessage('100125')}`; ${i18nHelper.getMessage('100125')}`;
manager.debug(`配置界面:展示豆瓣登录信息:id:${StringUtil.confuse(user.id)}, 用户名:${StringUtil.confuse(user.name)}`)
new Setting(containerEl) new Setting(containerEl)
.setName(i18nHelper.getMessage('100126')) .setName(i18nHelper.getMessage('100126'))
.setDesc(userDom) .setDesc(userDom)
@ -151,6 +155,7 @@ ${i18nHelper.getMessage('100125')}`;
.setCta() .setCta()
.onClick(async () => { .onClick(async () => {
button.setDisabled(true); button.setDisabled(true);
manager.debug(`配置界面:点击退出登录按钮`)
const loginModel = new DoubanLogoutModel(containerEl, manager); const loginModel = new DoubanLogoutModel(containerEl, manager);
await loginModel.doLogout(); await loginModel.doLogout();
}); });

@ -11,6 +11,8 @@ import { constructTemplateUI } from "./TemplateSettingHelper";
import { constructBasicUI } from "./BasicSettingsHelper"; import { constructBasicUI } from "./BasicSettingsHelper";
import { constructTemplateVariablesUI } from "./TemplateVariableSettingsHelper"; import { constructTemplateVariablesUI } from "./TemplateVariableSettingsHelper";
import {constructCustomPropertySettingsUI, constructCustomPropertyUI} from "./CustomPropertySettingsHelper"; import {constructCustomPropertySettingsUI, constructCustomPropertyUI} from "./CustomPropertySettingsHelper";
import {log} from "../../utils/Logutil";
import { constructAdvancedUI } from "./AdvancedSettingsHelper";
/** /**
* *
@ -19,6 +21,7 @@ import {constructCustomPropertySettingsUI, constructCustomPropertyUI} from "./Cu
export class DoubanSettingTab extends PluginSettingTab { export class DoubanSettingTab extends PluginSettingTab {
plugin: DoubanPlugin; plugin: DoubanPlugin;
settingsManager: SettingsManager; settingsManager: SettingsManager;
constructor(app: App, plugin: DoubanPlugin) { constructor(app: App, plugin: DoubanPlugin) {
super(app, plugin); super(app, plugin);
this.plugin = plugin; this.plugin = plugin;
@ -35,5 +38,10 @@ export class DoubanSettingTab extends PluginSettingTab {
constructOutUI(containerEl, this.settingsManager); constructOutUI(containerEl, this.settingsManager);
constructCustomPropertySettingsUI(containerEl, this.settingsManager); constructCustomPropertySettingsUI(containerEl, this.settingsManager);
constructTemplateVariablesUI(containerEl, this.settingsManager); constructTemplateVariablesUI(containerEl, this.settingsManager);
constructAdvancedUI(containerEl, this.settingsManager);
}
hide(): void {
} }
} }

@ -1,6 +1,7 @@
import {App, Setting} from "obsidian"; import {App, Setting} from "obsidian";
import { DEFAULT_SETTINGS } from "src/org/wanxp/constant/DefaultSettings"; import { DEFAULT_SETTINGS } from "src/org/wanxp/constant/DefaultSettings";
import DoubanPlugin from "../../main"; import DoubanPlugin from "../../main";
import Logger from "../../utils/Logutil";
import { DoubanPluginSetting } from "./model/DoubanPluginSetting"; import { DoubanPluginSetting } from "./model/DoubanPluginSetting";
export default class SettingsManager { export default class SettingsManager {
@ -8,6 +9,7 @@ export default class SettingsManager {
plugin: DoubanPlugin; plugin: DoubanPlugin;
settings: DoubanPluginSetting; settings: DoubanPluginSetting;
cleanupFns: Array<() => void> = []; cleanupFns: Array<() => void> = [];
innerLogger: Logger = new Logger();
constructor(app: App, plugin: DoubanPlugin) { constructor(app: App, plugin: DoubanPlugin) {
this.app = app; this.app = app;
@ -33,4 +35,10 @@ export default class SettingsManager {
await this.plugin.saveSettings(); await this.plugin.saveSettings();
} }
debug(message:string) {
if(this.settings.debugMode) {
this.innerLogger.debug(message);
}
}
} }

@ -16,6 +16,7 @@ export interface DoubanPluginSetting {
dataFilePath: string, dataFilePath: string,
dataFileNamePath: string, dataFileNamePath: string,
statusBar: boolean, statusBar: boolean,
debugMode: boolean,
customProperties: CustomProperty[], customProperties: CustomProperty[],
loginCookiesContent: string, loginCookiesContent: string,
cacheImage: boolean, cacheImage: boolean,

@ -9,6 +9,7 @@ import {log} from "../../utils/Logutil";
import {i18nHelper} from "../../lang/helper"; import {i18nHelper} from "../../lang/helper";
import User from "./User"; import User from "./User";
import DoubanGameSubject from "../data/model/DoubanGameSubject"; import DoubanGameSubject from "../data/model/DoubanGameSubject";
import StringUtil from "../../utils/StringUtil";
export default class UserComponent { export default class UserComponent {
private settingsManager: SettingsManager; private settingsManager: SettingsManager;
@ -53,10 +54,13 @@ export default class UserComponent {
async loginByCookie():Promise<User> { async loginByCookie():Promise<User> {
let cookie = this.settingsManager.getSetting('loginCookiesContent'); let cookie = this.settingsManager.getSetting('loginCookiesContent');
if(!cookie) { if(!cookie) {
this.settingsManager.debug('主界面:loginByCookie:无豆瓣cookies信息获取用户信息失败');
return new User(); return new User();
} }
this.settingsManager.debug('主界面:loginByCookie:豆瓣cookies信息正常尝试获取用户信息');
await this.loadUserInfo(cookie).then(user => { await this.loadUserInfo(cookie).then(user => {
this.user = user; this.user = user;
this.settingsManager.debug(`主界面:loginByCookie:豆瓣cookies信息正常${user&&user.id?'获取用户信息成功id:'+ StringUtil.confuse(user.id) + ',用户名:'+ StringUtil.confuse(user.name) :'获取用户信息失败'}`);
}); });
return this.user; return this.user;
} }
@ -65,8 +69,10 @@ export default class UserComponent {
if(!cookie) { if(!cookie) {
return new User(); return new User();
} }
this.settingsManager.debug('配置界面:loginCookie:豆瓣cookies信息正常尝试获取用户信息');
await this.loadUserInfo(cookie).then(user => { await this.loadUserInfo(cookie).then(user => {
this.user = user; this.user = user;
this.settingsManager.debug(`配置界面:loginCookie:豆瓣cookies信息正常${user&&user.id?'获取用户信息成功id:'+ StringUtil.confuse(user.id) + ',用户名:'+ StringUtil.confuse(user.name) :'获取用户信息失败'}`);
}); });
this.settingsManager.updateSetting('loginCookiesContent', cookie); this.settingsManager.updateSetting('loginCookiesContent', cookie);
return this.user; return this.user;

@ -76,6 +76,10 @@ PS: This file could be delete if you want to.
'1230': `Usable Variables`, '1230': `Usable Variables`,
'1204': `Set template file path. If keep empty, it will use the default template file to create file. All the usable variables at the end.👇`, '1204': `Set template file path. If keep empty, it will use the default template file to create file. All the usable variables at the end.👇`,
'1205': `🧡Tip: You can click the 'Copy' button to copy default template content, then create and paste to your own template file. After that, back to select the file. `, '1205': `🧡Tip: You can click the 'Copy' button to copy default template content, then create and paste to your own template file. After that, back to select the file. `,
'1250': `Advanced Setting`,
'1252': `Some Debug or Other Settings`,
'1251': `☢The Advanced Setting only could be changed after you know what you are doing`,
'1240': `Custom Variable`, '1240': `Custom Variable`,
'1241': `To use the custom variables, you need to wrap them in double curly brackets. For example, {{myType}} will be replaced with the your custom type value. `, '1241': `To use the custom variables, you need to wrap them in double curly brackets. For example, {{myType}} will be replaced with the your custom type value. `,
'1242': `Add custom variable, so that you can use it in the template file or file name. `, '1242': `Add custom variable, so that you can use it in the template file or file name. `,
@ -185,9 +189,14 @@ PS: This file could be delete if you want to.
'121901': `Copy default template content to clipboard`, '121901': `Copy default template content to clipboard`,
'121902': `Reset to default value`, '121902': `Reset to default value`,
'121905': `Reset Advanced Settings to default value`,
'121903': `Copy default template content (that your state in object) to clipboard`, '121903': `Copy default template content (that your state in object) to clipboard`,
'125001': `Debug Mode`,
'125002': `Open Debug Mode, so that this plugin will log some message in console`,
//error //error
'130101': `Fetch Data Error, {0}`, '130101': `Fetch Data Error, {0}`,

@ -85,6 +85,16 @@ export default {
'1240': `自定义属性`, '1240': `自定义属性`,
'1241': `自定义参数使用时请用'{{}}'包裹, 举例: 参数myType, 则使用时为{{myType}}. `, '1241': `自定义参数使用时请用'{{}}'包裹, 举例: 参数myType, 则使用时为{{myType}}. `,
'1242': `添加自定义参数, 参数可用于模板中或者文件名中. `, '1242': `添加自定义参数, 参数可用于模板中或者文件名中. `,
'1250': `高级设置`,
'1252': `一些运行时的高级配置如开启debug模式`,
'1251': `☢高级设置只有当你知道修改此设置之后的影响才允许修改, 正常情况下请保持默认`,
'125001': `调试模式`,
'125002': `调试模式开启后,将会在控制台打印此插件的日志信息`,
'124101': `新增`, '124101': `新增`,
'124108': `新增一个自定义参数`, '124108': `新增一个自定义参数`,
'124102': `参数名称:`, '124102': `参数名称:`,

@ -266,10 +266,13 @@ export default class DoubanPlugin extends Plugin {
} }
async checkLogin(context: HandleContext):Promise<boolean> { async checkLogin(context: HandleContext):Promise<boolean> {
this.settingsManager.debug('主界面:同步时的登录状态检测');
if (!context.userComponent.needLogin()) { if (!context.userComponent.needLogin()) {
this.settingsManager.debug('主界面:同步时的登录状态检测完成: 无用户信息, 尝试使用cookie获取用户信息');
await context.userComponent.loginByCookie(); await context.userComponent.loginByCookie();
} }
if (!context.userComponent.isLogin()) { if (!context.userComponent.isLogin()) {
this.settingsManager.debug('主界面:同步时的登录状态检测完成: 尝试使用cookie获取用户信息失败');
new Notice(i18nHelper.getMessage('140303')); new Notice(i18nHelper.getMessage('140303'));
return false; return false;
} }

@ -1,7 +1,8 @@
import {Notice} from "obsidian"; import {moment, Notice} from "obsidian";
import {i18nHelper} from "src/org/wanxp/lang/helper"; import {i18nHelper} from "src/org/wanxp/lang/helper";
class Logger { export default class Logger {
public error(msg: any, e:any): any { public error(msg: any, e:any): any {
new Notice(msg); new Notice(msg);
@ -28,7 +29,7 @@ class Logger {
} }
public debug(e: any): any { public debug(e: any): any {
console.log(`OB-Douban:` + `${typeof e == 'string' ? e : JSON.stringify(e)}`); console.log(`OB-Douban:${moment(new Date()).format('YYYY-MM-DD HH:mm:SS')}:${typeof e == 'string' ? e : JSON.stringify(e)}`);
return e; return e;
} }

@ -23,4 +23,21 @@ export default class StringUtil {
return id; return id;
} }
public static confuse(text: string):string {
if (!text) {
return
}
let texts = Array.from(text);
const length = texts.length;
const newTexts = [];
for (let i = 0; i < length; i++) {
let val = text[i];
if (i >= length/3 && i <= length * 2/3) {
val = '*'
}
newTexts[i] = val;
}
return newTexts.join('');
}
} }