UNPKG

wfinder

Version:

A local file indexing and searching tool.

2 lines 122 kB
#!/usr/bin/env node exports.id=322,exports.ids=[322],exports.modules={97021:e=>{function webpackEmptyContext(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}webpackEmptyContext.keys=()=>[],webpackEmptyContext.resolve=webpackEmptyContext,webpackEmptyContext.id=97021,e.exports=webpackEmptyContext},18967:e=>{function webpackEmptyContext(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}webpackEmptyContext.keys=()=>[],webpackEmptyContext.resolve=webpackEmptyContext,webpackEmptyContext.id=18967,e.exports=webpackEmptyContext},95601:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SUB_DATABASE_PREFIX=t.APP_DATA_FOLDER_NAME=t.STR_FINDER_CORE_INFO=t.EVENT_TRANSFER_WEBSOCKET_ROUTE=t.EVENT_ORM_METHOD_WEBSOCKET_ROUTE=t.EVENT_WEBSOCKET_ROUTE=t.localhost=void 0,t.localhost="localhost",t.EVENT_WEBSOCKET_ROUTE="/event_websocket",t.EVENT_ORM_METHOD_WEBSOCKET_ROUTE="/event_orm_method",t.EVENT_TRANSFER_WEBSOCKET_ROUTE="/event_transfer",t.STR_FINDER_CORE_INFO="FINDER_CORE_INFO",t.APP_DATA_FOLDER_NAME="wfinder",t.SUB_DATABASE_PREFIX="sub-"},22392:function(e,t,n){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.execRoot=void 0;const o=i(n(85622));t.execRoot=o.default.resolve(__dirname)},39778:function(e,t,n){"use strict";var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&i(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.isDev=t.DEFAULT_QUERY_LIMIT=t.entityChangeWatchingSubjectMap=t.MAX_PATH_DEPTH=t.Config=t.genConfig=void 0;const a=r(n(85622));t.genConfig=e=>{const t="wfinder.db";return{finderRoot:e,dbName:t,dbPath:a.join(e,t),readOnly:!1}},t.Config=t.genConfig(a.resolve("./")),t.MAX_PATH_DEPTH=1e3,t.entityChangeWatchingSubjectMap=new Map,t.DEFAULT_QUERY_LIMIT={dbThumbnailStack:[],remoteLimit:10},t.isDev=!1},39370:function(e,t,n){"use strict";var i,o,r=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return a(t,e),t},l=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function fulfilled(e){try{step(i.next(e))}catch(e){r(e)}}function rejected(e){try{step(i.throw(e))}catch(e){r(e)}}function step(e){e.done?o(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))},c=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.removeDbFiles=t.getFinderCoreInfo=t.getThumbnail=t.getDbFlags=t.getConfig=t.switchDb=t.postCreate=t.releaseConnection=t.getCachedConnection=t.getConnection=t.AUTO_CONNECT_ENTITIES=t.initDb=t.checkCompleteDb=t.getDbTriggerNames=t.createFtsTable=void 0;const d=n(39562),u=s(n(35747)),f=c(n(96062)),v=c(n(85622)),h=n(20025),m=n(95601),g=n(11169),p=n(85648),y=n(39778),b=n(28962),E=n(10546),C=n(42276),S=n(21076),w=n(40811),x=n(4971),_=n(14706),O=n(57398);t.createFtsTable=e=>l(void 0,void 0,void 0,(function*(){const{tableName:n}=e.getMetadata(_.FileInfo);try{yield e.query(`CREATE VIRTUAL TABLE ${_.IndexTableName} USING fts4(content="${n}",\n tokenize=porter unicode61 "separators=/",\n name);`),yield t.checkCompleteDb(e)}catch(e){throw console.log("Failed to create fts table: ",e),new Error("Failed to create fts table: "+e)}}));t.getDbTriggerNames=e=>l(void 0,void 0,void 0,(function*(){return(yield e.query("select type,name from sqlite_master;")).filter((e=>"trigger"===e.type)).map((e=>e.name))}));t.checkCompleteDb=e=>l(void 0,void 0,void 0,(function*(){try{const{tableName:n}=e.getMetadata(_.FileInfo),i=`${n}_${_.IndexTableName}`;if(!(yield t.getDbTriggerNames(e)).includes(`${i}_bu`)){const t=[`CREATE TRIGGER ${i}_bu BEFORE UPDATE ON ${n} BEGIN\n DELETE FROM ${_.IndexTableName} WHERE docid=old.rowid;\n END;`,`CREATE TRIGGER ${i}_bd BEFORE DELETE ON ${n} BEGIN\n DELETE FROM ${_.IndexTableName} WHERE docid=old.rowid;\n END;`,`CREATE TRIGGER ${i}_au AFTER UPDATE ON ${n} BEGIN\n INSERT INTO ${_.IndexTableName}(docid, name) VALUES(new.rowid, new.name);\n END;`,`CREATE TRIGGER ${i}_ai AFTER INSERT ON ${n} BEGIN\n INSERT INTO ${_.IndexTableName}(docid, name) VALUES(new.rowid, new.name);\n END;\n `];for(const n of t)yield e.query(n)}}catch(e){throw console.log("Failed to create triggers: ",e),new Error("Failed to create triggers: "+e)}}));const P="better-sqlite3";t.initDb=(e,n,i=!1)=>l(void 0,void 0,void 0,(function*(){const{dbPath:o}=e;if(!v.default.isAbsolute(o))throw new Error("dbPath should be absolute: "+JSON.stringify(e));let r;if(u.existsSync(e.dbPath)){if(!i)return;yield t.removeDbFiles(e.dbPath)}try{r=yield h.createConnection({type:P,database:o,synchronize:!0,entities:[_.FileInfo,w.ConfigLine],name:o+Math.random().toString(36)}),yield t.createFtsTable(r),yield r.close(),r=void 0;const postCreateConnection=()=>l(void 0,void 0,void 0,(function*(){clearTimeout(i),t.postCreate.delete(o,postCreateConnection);const r=n&&n!==e?yield t.switchDb(n,(()=>l(void 0,void 0,void 0,(function*(){return yield w.ConfigLine.find({where:{type:h.In([S.ConfigLineType.excludeChildrenFolderName,S.ConfigLineType.excludeFileName])}})})))):[];yield t.switchDb(e,(()=>l(void 0,void 0,void 0,(function*(){n&&n!==e?(r.forEach((t=>{t.dbInfo=e,t.id=void 0})),yield w.ConfigLine.save(r)):yield new w.ConfigLine("^node_modules$",S.ConfigLineType.excludeChildrenFolderName).save()}))))})),i=setTimeout(postCreateConnection,10);t.postCreate.add(o,postCreateConnection)}catch(n){if(u.existsSync(o)&&Date.now()-u.statSync(o).ctime.valueOf()<2e4&&(yield t.removeDbFiles(o)),console.error(n),null==r||r.close(),e.isSubDb||Object.values(E.EvUiLaunched.value).some((e=>e)))throw n;g.exit("Create database failed.")}})),t.AUTO_CONNECT_ENTITIES=[_.FileInfo,O.ScanPath,x.DbIncluded,w.ConfigLine],y.entityChangeWatchingSubjectMap.set(_.FileInfo,E.EvFileInfoChange),y.entityChangeWatchingSubjectMap.set(w.ConfigLine,b.cEvConfigLineChange),y.entityChangeWatchingSubjectMap.set(O.ScanPath,b.cEvScanPathChange),y.entityChangeWatchingSubjectMap.set(x.DbIncluded,b.cEvDbIncludedChange),b.cEvFinderState.next({remoteMethodServeEntityMap:{FileInfo:_.FileInfo}});const I="fakePath";let D;i=(()=>{const e=new Map;let n=0;const i=new Map,o=new Map,r=new Map;return{getCachedConnection:(n=t.getConfig())=>e.get(n.dbPath),postCreate:{add:(e,t)=>{r.set(e,(r.get(e)||[]).concat(t))},delete:(e,t)=>{var n;const i=null===(n=r.get(e))||void 0===n?void 0:n.filter((e=>e!==t));(null==i?void 0:i.length)?r.set(e,i):r.delete(e)}},releaseConnection:t=>l(void 0,void 0,void 0,(function*(){if(o.has(t)||i.has(t))throw new Error("Database busy now.");const n=e.get(t);n&&(e.delete(t),yield n.close())})),getConnection:(a=t.getConfig(),s=!1,c=!1)=>l(void 0,void 0,void 0,(function*(){var d;const{dbPath:m}=a;if(!v.default.isAbsolute(m)&&m.slice(0,I.length)!==I)throw new Error("dbPath used in getConnection should be absolute: "+m);let p=e.get(m);if(p)return p;if(o.get(m)&&!c)return new Promise((e=>{const t=i.get(m)||[];t.push(e),i.set(m,t)}));o.set(m,!0);try{if(!u.existsSync(m)){if(a.readOnly||E.EvUiLaunched.value.ink)throw new Error("DbPath not exist: "+m);if(!s&&!a.isSubDb||!g.pathPem.canWrite(v.default.parse(m).dir)){if(a!==y.Config)throw new Error("Failed to create connection to config: "+JSON.stringify(a));if(E.EvUiLaunched.value.electron||E.EvUiLaunched.value.web){let e;if(E.EvUiLaunched.value.electron)try{e=(yield C.executeUiCmd("queryUserDataDir",{cmd:"queryUserDataDir"})).result}catch(e){console.error("queryUserDataDir failed: ",e)}let n="";if(e&&g.pathPem.canWrite(v.default.join(e,a.dbName)))n=e;else{let t="";for(;;)try{const i=yield C.executeUiCmd("requestChooseFinderRoot",{cmd:"requestChooseFinderRoot",tag:Math.random(),data:{cwd:process.cwd(),userDataDir:e,currentDatabaseDir:v.default.parse(m).dir,message:t}},1/0),{finderRoot:o}=i.result,r=v.default.resolve(o);if(o!==e||u.existsSync(e)||u.mkdirSync(e),u.existsSync(r)){if(g.pathPem.canWrite(r)){n=r;break}t=`Error: path "${r}" is not writable.`}else t=`Error: path "${r}" dosen't exist.`}catch(e){console.error("requestChooseFinderRoot failed: ",e)}}const i=y.genConfig(n),o=b.cEvFinderState.value.configStack.find((e=>e.dbPath===y.Config.dbPath));return o&&(Object.assign(o,i),b.cEvFinderState.next({configStack:[...b.cEvFinderState.value.configStack]})),Object.assign(y.Config,i),yield t.getConnection(y.Config,!0,i.dbPath===m)}(yield f.default.prompt({name:"dbCreate",message:"Index database dosent exist, create it now?",type:"confirm"})).dbCreate||g.exitNthTodo()}console.log("Creating index database..."),yield t.initDb(a,t.getConfig())}if(p=yield h.createConnection({type:P,name:m===y.Config.dbPath?"default":"connection-"+n++,synchronize:!0,database:m,entities:t.AUTO_CONNECT_ENTITIES}),yield t.checkCompleteDb(p),!a.thumbnail){const i=Object.assign(Object.assign({},a),{dbPath:I+(n+1)+Date.now().toString(36)+Math.random().toString(36)});e.set(i.dbPath,p);try{const n=yield t.switchDb(i,(()=>l(void 0,void 0,void 0,(function*(){return yield t.getFinderCoreInfo(void 0,i)}))));a.thumbnail=n.thumbnail}catch(e){console.warn("Failed to get thumbnail of database",a,e)}finally{e.delete(i.dbPath)}}e.set(m,p);const c=p.close.bind(p);p.close=()=>l(void 0,void 0,void 0,(function*(){e.delete(m),yield c()}));const S=p;return null===(d=i.get(m))||void 0===d||d.forEach((e=>e(S))),i.delete(m),p}finally{o.delete(m),yield Promise.all((r.get(m)||[]).map((e=>e().catch((e=>{E.EvLogError(`Error of postCreateConnection callback, dbpath: ${m},error: ${e}`)})))))}}))}})(),t.getConnection=i.getConnection,t.getCachedConnection=i.getCachedConnection,t.releaseConnection=i.releaseConnection,t.postCreate=i.postCreate,o=(()=>{const e=(()=>{const e=d.createNamespace("wfinderDbSession"),n="key_config",i="key_flags",o={willChange:!0};return{get:()=>e.get(n)||y.Config,flags:()=>e.get(i)||o,run:(o,r,a)=>l(void 0,void 0,void 0,(function*(){return o.isSubDb&&o.dbPath.slice(0,I.length)!==I&&!u.existsSync(o.dbPath)&&(yield t.initDb(o,t.getConfig())),yield t.getConnection(o),e.runAndReturn((()=>l(void 0,void 0,void 0,(function*(){return e.set(n,o),a&&e.set(i,a),yield r()}))))}))}})();return{switchDb:e.run,getConfig:e.get,getDbFlags:e.flags,getThumbnail:e=>l(void 0,void 0,void 0,(function*(){return(yield t.getFinderCoreInfo(!1,{finderRoot:"",dbName:"",dbPath:e})).thumbnail}))}})(),t.switchDb=o.switchDb,t.getConfig=o.getConfig,t.getDbFlags=o.getDbFlags,t.getThumbnail=o.getThumbnail;let R="";t.getFinderCoreInfo=(e=!1,n)=>l(void 0,void 0,void 0,(function*(){const i=n||(e?b.cEvFinderState.value.configStack.slice(0,b.cEvFinderState.value.configIndex).reverse().find((e=>!e.isSubDb)):y.Config)||y.Config;return D&&(null==i?void 0:i.dbPath)===R||(D=yield t.switchDb(i||y.Config,(()=>l(void 0,void 0,void 0,(function*(){const e=(yield w.ConfigLine.find({where:{type:S.ConfigLineType.coreInfo}}))[0]||new w.ConfigLine(m.STR_FINDER_CORE_INFO,S.ConfigLineType.coreInfo);let t;return e.jsonStr&&(t=p.JsonMore.parse(e.jsonStr)),(null==t?void 0:t.thumbnail)||(t=Object.assign(Object.assign({},t||{}),{thumbnail:yield g.genDbThumbnail(y.Config.dbPath)}),e.jsonStr=p.JsonMore.stringify(t),yield e.save()),t})))),R=i.dbPath),D}));t.removeDbFiles=e=>l(void 0,void 0,void 0,(function*(){u.existsSync(e)&&(yield t.releaseConnection(e),["","-shm","-wal"].forEach((t=>{const n=e+t;u.existsSync(n)&&u.unlinkSync(n)})))}))},92788:function(e,t,n){"use strict";var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function fulfilled(e){try{step(i.next(e))}catch(e){r(e)}}function rejected(e){try{step(i.throw(e))}catch(e){r(e)}}function step(e){e.done?o(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))},o=this&&this.__await||function(e){return this instanceof o?(this.v=e,this):new o(e)},r=this&&this.__asyncGenerator||function(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i,r=n.apply(e,t||[]),a=[];return i={},verb("next"),verb("throw"),verb("return"),i[Symbol.asyncIterator]=function(){return this},i;function verb(e){r[e]&&(i[e]=function(t){return new Promise((function(n,i){a.push([e,t,n,i])>1||resume(e,t)}))})}function resume(e,t){try{!function step(e){e.value instanceof o?Promise.resolve(e.value.v).then(fulfill,reject):settle(a[0][2],e)}(r[e](t))}catch(e){settle(a[0][3],e)}}function fulfill(e){resume("next",e)}function reject(e){resume("throw",e)}function settle(e,t){e(t),a.shift(),a.length&&resume(a[0][0],a[0][1])}},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getEntityTableName=t.BaseDbInfoEntity=t.SubDatabaseIterators=void 0;const s=n(20025),l=n(85648),c=n(39778),d=n(39370),u=n(28962),f=n(10546),v=n(39778),h=a(n(35747));t.SubDatabaseIterators=[];class BaseDbInfoEntity extends s.BaseEntity{constructor(...e){super(),this.dbInfo=d.getConfig()}static queryAllDbIncluded(e,t=!0){return i(this,void 0,void 0,(function*(){return yield this._queryAllDbIncluded(new Set,e,t)}))}static _queryAllDbIncluded(e,n,o=!0){return i(this,void 0,void 0,(function*(){e.add(h.default.realpathSync(d.getConfig().dbPath));let r=o?yield n(this):[];for(const a of t.SubDatabaseIterators)yield a((()=>i(this,void 0,void 0,(function*(){yield l.interactYield();const t=h.default.realpathSync(d.getConfig().dbPath);e.has(t)||(e.add(t),r=r.concat(yield this._queryAllDbIncluded(e,n,o)))}))));return o||(r=r.concat(yield n(this))),r}))}save(e){const t=Object.create(null,{save:{get:()=>super.save}});var n;return i(this,void 0,void 0,(function*(){const i=yield t.save.call(this,e);return null===(n=c.entityChangeWatchingSubjectMap.get(this.constructor))||void 0===n||n.next(d.getConfig()),i}))}remove(e){const t=Object.create(null,{remove:{get:()=>super.remove}});var n;return i(this,void 0,void 0,(function*(){const i=yield t.remove.call(this,e);return null===(n=c.entityChangeWatchingSubjectMap.get(this.constructor))||void 0===n||n.next(d.getConfig()),i}))}static remove(e,t){const n=Object.create(null,{remove:{get:()=>super.remove}});var o;return i(this,void 0,void 0,(function*(){const i=yield n.remove.call(this,e,t);return null===(o=c.entityChangeWatchingSubjectMap.get(this))||void 0===o||o.next(d.getConfig()),i}))}static save(e,t){const n=Object.create(null,{save:{get:()=>super.save}});var o;return i(this,void 0,void 0,(function*(){const i=yield n.save.call(this,e,t);return null===(o=c.entityChangeWatchingSubjectMap.get(this))||void 0===o||o.next(d.getConfig()),i}))}static delete(e,t){const n=Object.create(null,{delete:{get:()=>super.delete}});var o;return i(this,void 0,void 0,(function*(){const i=yield n.delete.call(this,e,t);return null===(o=c.entityChangeWatchingSubjectMap.get(this))||void 0===o||o.next(null),i}))}static callRemoteStaticMethod(e,t,n){return r(this,arguments,(function*callRemoteStaticMethod_1(){if(n.remoteLimit<1)return yield o(void 0);const i={dbThumbnailStack:[...n.dbThumbnailStack,(yield o(d.getFinderCoreInfo())).thumbnail],remoteLimit:n.remoteLimit-1};if("function"!=typeof this[e])throw new Error(`Method not found in entity ${this.name}`);for(const[n,r]of Object.entries(u.cEvFinderState.value.linkedRemote))if(r.caller)try{const a=yield o(r.caller.call({cmd:"callOrmMethod",data:{entityName:this.name,method:e,args:t,queryLimit:i}}));yield yield o({url:n,rRes:a})}catch(e){f.EvLogError(`Error: query remote failed, method: countByMatchName, args: ${t},remote: ${n} error: `,e)}}))}}t.BaseDbInfoEntity=BaseDbInfoEntity;const m=new Set(["save","remove","softRemove","insert","update","delete","query","clear"]);["save","remove","softRemove","reload","recover"].forEach((e=>{const t=BaseDbInfoEntity.prototype[e];"function"==typeof t&&(BaseDbInfoEntity.prototype[e]=function(...e){return d.getCachedConnection(d.getConfig())&&this.constructor.useConnection(d.getCachedConnection(d.getConfig())),t.apply(this,e)},m.has(e)&&(BaseDbInfoEntity.prototype[e]=function(...e){var n;return i(this,void 0,void 0,(function*(){d.getCachedConnection(d.getConfig())&&this.constructor.useConnection(d.getCachedConnection(d.getConfig()));const i=yield t.apply(this,e);return d.getDbFlags().willChange&&(null===(n=c.entityChangeWatchingSubjectMap.get(this.constructor))||void 0===n||n.next(d.getConfig())),i}))}))})),["getRepository","createQueryBuilder","create","preload","save","remove","softRemove","insert","update","delete","count","find","findAndCount","findByIds","findOne","findOneOrFail","query","clear"].forEach((e=>{const t=BaseDbInfoEntity[e];"function"==typeof t&&(BaseDbInfoEntity[e]=function(...e){const n=d.getCachedConnection(d.getConfig());return n&&this.useConnection(n),t.apply(this,e)},m.has(e)&&(BaseDbInfoEntity[e]=function(...e){var n;const i=d.getCachedConnection(d.getConfig());i&&this.useConnection(i);const o=t.apply(this,e);return d.getDbFlags().willChange&&(null===(n=c.entityChangeWatchingSubjectMap.get(this))||void 0===n||n.next(d.getConfig())),o}))}));const g=new Map;t.getEntityTableName=e=>{let t=g.get(e);if(t)return t;const n=d.getCachedConnection(v.Config);if(!n)throw new Error("getEntityTableName cached connection not found.");return t=n.getMetadata(e).tableName,g.set(e,t),t}},40811:function(e,t,n){"use strict";var i=this&&this.__decorate||function(e,t,n,i){var o,r=arguments.length,a=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,n,a):o(t,n))||a);return r>3&&a&&Object.defineProperty(t,n,a),a},o=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigLine=void 0;const r=n(20025),a=(n(21076),n(92788));let s=class ConfigLine extends a.BaseDbInfoEntity{constructor(e,t){super(),this.content="",this.content=e,this.type=t}toItem(){const{id:e,updatedAt:t,createdAt:n,content:i,type:o,dbInfo:r,disabled:a,jsonStr:s}=this;return{id:e,updatedAt:t,createdAt:n,content:i,type:o,dbInfo:r,disabled:a,jsonStr:s}}};i([r.PrimaryGeneratedColumn(),o("design:type",Number)],s.prototype,"id",void 0),i([r.Column({type:"text"}),o("design:type",Object)],s.prototype,"content",void 0),i([r.Column(),o("design:type",Number)],s.prototype,"type",void 0),i([r.Column({nullable:!0}),o("design:type",Boolean)],s.prototype,"disabled",void 0),i([r.Column({type:"text",nullable:!0}),o("design:type",String)],s.prototype,"jsonStr",void 0),i([r.UpdateDateColumn(),o("design:type",Date)],s.prototype,"updatedAt",void 0),i([r.CreateDateColumn(),o("design:type",Date)],s.prototype,"createdAt",void 0),s=i([r.Entity(),o("design:paramtypes",[String,Number])],s),t.ConfigLine=s},4971:function(e,t,n){"use strict";var i,o=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__decorate||function(e,t,n,i){var o,r=arguments.length,a=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,n,a):o(t,n))||a);return r>3&&a&&Object.defineProperty(t,n,a),a},s=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&o(t,e,n);return r(t,e),t},l=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},c=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function fulfilled(e){try{step(i.next(e))}catch(e){r(e)}}function rejected(e){try{step(i.throw(e))}catch(e){r(e)}}function step(e){e.done?o(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.DbIncluded=void 0;const d=s(n(35747)),u=s(n(85622)),f=n(20025),v=n(85648),h=n(39370),m=n(10546),g=n(39778),p=n(92788);let y=i=class DbIncluded extends p.BaseDbInfoEntity{constructor(e,t=g.Config.dbName){super(),this.path=e,this.dbName=t}static mark(e,t=g.Config.dbName){return c(this,void 0,void 0,(function*(){const n=(yield i.findOne(e))||(yield new this(e,t).save());return n.dbName!==t&&(n.dbName=t,yield n.save()),n}))}static removeUnexists(){return c(this,void 0,void 0,(function*(){const{finderRoot:e}=h.getConfig(),t=yield this.find();for(const n of t)d.existsSync(u.join(e,n.path,n.dbName))||(yield n.remove())}))}};a([f.PrimaryColumn(),l("design:type",String)],y.prototype,"path",void 0),a([f.Column(),l("design:type",String)],y.prototype,"dbName",void 0),y=i=a([f.Entity(),l("design:paramtypes",[String,Object])],y),t.DbIncluded=y,p.SubDatabaseIterators.push((e=>c(void 0,void 0,void 0,(function*(){const t=yield y.find(),n=h.getConfig();for(const i of t){const t=u.join(n.finderRoot,i.path);if(!v.isPathEqual(n.finderRoot,t))try{const n=u.join(t,i.dbName);d.existsSync(n)?yield h.switchDb({dbName:i.dbName,finderRoot:t,dbPath:n,readOnly:!0,isSubDb:!0,thumbnail:yield h.getThumbnail(n)},e):m.EvFinderStatus.value.scanAbsPathContexIdtMap.size||m.EvLogWarn(`It's time to rescan, sub database file not exist: ${n}.`)}catch(e){console.error("Query sub database failed: ",t,e)}}}))))},14706:function(e,t,n){"use strict";var i,o=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__decorate||function(e,t,n,i){var o,r=arguments.length,a=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,n,a):o(t,n))||a);return r>3&&a&&Object.defineProperty(t,n,a),a},s=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&o(t,e,n);return r(t,e),t},l=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},c=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function fulfilled(e){try{step(i.next(e))}catch(e){r(e)}}function rejected(e){try{step(i.throw(e))}catch(e){r(e)}}function step(e){e.done?o(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))},d=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.restoreText=t.processText=t.FileInfo=t.IndexTableName=void 0;const u=n(96486),f=s(n(85622)),v=d(n(69887)),h=n(20025),m=n(85648),g=n(85648),p=n(39370),y=(n(21076),n(39778)),b=n(39370),E=n(10546),C=n(92788),S=n(4971);t.IndexTableName="fileindex";let w=i=class FileInfo extends C.BaseDbInfoEntity{constructor(e,n,i,o=-1,r=0,a,s=!1){super(),this.absPath="",this.name=s?e:t.processText(e||""),this.type=n,this.ctime=i,this.parentId=o,this.size=r,this.nameHash=a||v.default(this.name)}getName(){return t.restoreText(this.name)}static processAndHashName(e){const n=t.processText(e);return[n,v.default(n)]}save(){const e=Object.create(null,{save:{get:()=>super.save}});return c(this,void 0,void 0,(function*(){return yield e.save.call(this)}))}static save(e,t,n){const i=Object.create(null,{save:{get:()=>super.save}});return c(this,void 0,void 0,(function*(){const o=[...e];let r=[];const a=b.getConfig();for(;o.length&&!(null==n?void 0:n.value);){(yield g.interactYield(5,2e3))&&E.EvFileInfoChange.next(a);const e=o.splice(0,200);r=r.concat(yield i.save.call(this,e,t))}return r}))}remove(e){const t=Object.create(null,{remove:{get:()=>super.remove}});return c(this,void 0,void 0,(function*(){yield i.removeNameIndexs([this]);return yield t.remove.call(this,e)}))}static remove(e,t){const n=Object.create(null,{remove:{get:()=>super.remove}});return c(this,void 0,void 0,(function*(){const o=r.filter((e=>e instanceof i));o.length&&(yield i.removeNameIndexs(o));const r=yield n.remove.call(this,e,t);return r}))}getPath(){return c(this,void 0,void 0,(function*(){let e=this.getName(),t=this;for(;t=yield i.findOne(t.parentId),t;)e=f.join(t.getName(),e);return e}))}static removeAllIndexedData(){return c(this,void 0,void 0,(function*(){yield this.queryAllDbIncluded((e=>c(this,void 0,void 0,(function*(){yield e.clear().catch((e=>{console.error("Clear FileInfo table failed: ",e)})),yield e.query(`drop table ${t.IndexTableName}`).catch((e=>{console.error("Clear fts table failed: ",e)})),yield p.createFtsTable(yield p.getConnection()).catch((e=>{console.error("Create fts table failed: ",e)})),yield S.DbIncluded.clear().catch((e=>{console.error("Clear DbIncluded table failed: ",e)}));const n=p.getCachedConnection(b.getConfig());if(n){const i=(yield p.getDbTriggerNames(n)).filter((e=>e.includes(t.IndexTableName)));for(const t of i)yield e.query(`drop trigger ${t}`);yield p.checkCompleteDb(n)}return[]}))),!1)}))}static countAllSubDatabases(){return c(this,void 0,void 0,(function*(){const e=yield this.queryAllDbIncluded((e=>e.count().then((e=>[e]))));return u.sum(e)}))}static countAllDatabases(e=y.DEFAULT_QUERY_LIMIT){return c(this,void 0,void 0,(function*(){const t=yield this.countAllSubDatabases();let n=0;if(!b.getConfig().isSubDb){const t=this.callRemoteStaticMethod("countAllDatabases",[],e);let i=yield t.next();for(;!i.done;){const{result:e}=i.value.rRes;e instanceof Array?n+=e[0]:E.EvLogError("Error: remote call countByMatchName return invalid value: ",e),i=yield t.next()}}return[t+n,t,n]}))}static countByMatchName(e,t,n,i=!1,o=y.DEFAULT_QUERY_LIMIT){return c(this,void 0,void 0,(function*(){if(!e.every((e=>e))&&!t&&!n)return 0;const r=n?yield(()=>c(this,void 0,void 0,(function*(){const{queryStr:i,queryParams:o}=yield genComplexQuery((e=>`select ${e?"rowid":"id"} as id `),e,t);return e=>c(this,void 0,void 0,(function*(){let t=(yield e.query(i,o)).map((e=>e.id));return t=yield e.regexpMatch(t,n),[{count:t.length}]}))})))():yield(()=>c(this,void 0,void 0,(function*(){const{queryStr:n,queryParams:i}=yield genComplexQuery((()=>"select count(1) as count"),e,t);return e=>e.query(n,i)})))(),a=yield i?r(this):this.queryAllDbIncluded(r);let s=0;if(!i&&!b.getConfig().isSubDb){const r=this.callRemoteStaticMethod("countByMatchName",[e,t,n,i],o);let a=yield r.next();for(;!a.done;){const{result:e}=a.value.rRes;"number"==typeof e?s+=e:E.EvLogError("Error: remote call countByMatchName return invalid value: ",e),a=yield r.next()}}return u.sumBy(a,"count")+s}))}static findByMatchName(e,t,n,i=100,o=0,r=y.DEFAULT_QUERY_LIMIT){var a;return c(this,void 0,void 0,(function*(){if(!e.every((e=>e))&&!t&&!n)return[];const s=i+o;let l=0,d=yield this.queryAllDbIncluded((i=>c(this,void 0,void 0,(function*(){if(l>s)return[];let r=[];if(n){const{queryStr:o,queryParams:a}=yield genComplexQuery((e=>`select ${e?"rowid":"id"} as id `),e,t);r=(yield i.query(o,a)).map((e=>e.id)),r=yield i.regexpMatch(r,n)}const a=n?r.length:yield i.countByMatchName(e,t,n,!0),d=Math.max(0,o-l),u=Math.min(s-l,a),f=Math.max(0,u-d);if(l+=a,!f)return[];n&&(r=yield i.regexpMatch(r,n),r=r.slice(d,d+f));let v=r;if(!n){const{queryStr:n,queryParams:o}=yield genComplexQuery((e=>`select ${e?"rowid":"id"} as id `),e,t,d,f);v=(yield i.query(n,o)).map((e=>e.id))}return i.findByIds(v).then((e=>Promise.all(e.map((e=>c(this,void 0,void 0,(function*(){return e.absPath=yield i.getPath(e.id),e})))))))}))));if(l<s&&!b.getConfig().isSubDb){const i=this.callRemoteStaticMethod("findByMatchName",[e,t,n,s-Math.max(l,o),Math.max(0,o-l)],r);let c=yield i.next();for(;!c.done;){const e=c.value;if(void 0!==e&&(null===(a=e.rRes.result)||void 0===a?void 0:a.constructor)===Array){const t=c.value.rRes.result;t.forEach((t=>t.dbInfo.remoteUrls=[e.url,...t.dbInfo.remoteUrls||[]])),d=d.concat(t)}c=yield i.next()}}return d}))}static regexpMatch(e,n){return c(this,void 0,void 0,(function*(){const i=new RegExp(n);let o=[];const r=(yield p.getConnection()).getMetadata(this).tableName;for(;e.length;){const n=e.splice(-1e3),a=yield this.query(`select id, name from ${r} where id in (${n.join(",")})`);o=o.concat(a.filter((e=>i.test(t.restoreText(e.name)))).map((e=>e.id)))}return o}))}static removeNameIndexs(e){return c(this,void 0,void 0,(function*(){}))}static removeChildren(e,n,i,o=!1){return c(this,void 0,void 0,(function*(){let r=0;let a=[];for(;!(null==i?void 0:i.value);){const i=yield this.find({where:Object.assign({parentId:e},n?{name:h.In(n.map((e=>t.processText(e))))}:{}),skip:r,take:100});if(r+=100,!i.length)break;const o=[];for(const e of i)yield this.removeChildren(e.id),o.push(e);yield this.removeNameIndexs(o),a=a.concat(o.map((e=>e.id))),yield g.interactYield()}(null==i?void 0:i.value)||(o&&a.concat(e),a.length&&(yield this.delete(a)))}))}static removeUnexistChildren(e,n,i){return c(this,void 0,void 0,(function*(){let o=0;const r=new Set(n.map((e=>t.processText(e))));let a=[];for(;!(null==i?void 0:i.value);){const t=yield this.find({where:{parentId:e},skip:o,take:100});if(o+=100,!t.length)break;const n=[];for(const e of t)yield g.interactYield(),r.has(e.name)||(yield this.removeUnexistChildren(e.id,[]),n.push(e));yield this.removeNameIndexs(n),a=a.concat(n.map((e=>e.id)))}!(null==i?void 0:i.value)&&a.length&&(yield this.delete(a))}))}static removePath(e){var n;return c(this,void 0,void 0,(function*(){const o=m.splitPath(e),r=[];for(const e of o){const t=(null===(n=u.last(r))||void 0===n?void 0:n.id)||-1,o=yield i.findByNameWhere(e,{parentId:t});if(o.length>1)throw new Error(`Faile to remove path, more than one file have thesame name in folder(ID: ${t}): ${e}`);if(!o.length)break;r.push(o[0])}const a=u.last(r);if(a){t.restoreText(a.name)===u.last(o)&&(yield i.removeChildren(a.id)),r.reverse();for(const e of r)(yield i.find({where:{parentId:e.id}})).length||(yield e.remove())}}))}static findOneByPath(e,t=b.getConfig()){return c(this,void 0,void 0,(function*(){return yield b.switchDb(t,(()=>c(this,void 0,void 0,(function*(){const n=m.splitPath(f.relative(t.finderRoot,e));let o;for(;;){const e=n.pop();if(!e)return o;if(o=(yield i.findByNameWhere(e,{parentId:(null==o?void 0:o.id)||-1}))[0],!o)return o}}))))}))}static getPath(e,n=b.getConfig()){return c(this,void 0,void 0,(function*(){return yield b.switchDb(n,(()=>c(this,void 0,void 0,(function*(){let i=yield this.findOne(e);if(!i)throw new Error("FileInfo id not exist");const o=[i];for(;i&&-1!==i.parentId;){if(i=yield this.findOne(null==i?void 0:i.parentId),!i)throw new Error("Get FileInfo path failed, broken parentId chain.");o.push(i)}return o.reverse().reduce(((e,n)=>f.join(e,t.restoreText(n.name))),n.finderRoot)}))))}))}static getOrInsert(e,t,n,o=-1,r=0){return c(this,void 0,void 0,(function*(){const[a,s]=i.processAndHashName(e);return(yield this.find({where:{parentId:o,nameHash:s,name:a}}))[0]||(yield new this(a,t,n,o,r,s,!0).save())}))}static findByNameWhere(e,t){const[n,o]=this.processAndHashName(e),r=Object.assign(Object.assign({},t||{}),{nameHash:o,name:n});return i.find({where:r})}};a([h.PrimaryGeneratedColumn(),l("design:type",Number)],w.prototype,"id",void 0),a([h.Index(),h.Column(),l("design:type",Number)],w.prototype,"parentId",void 0),a([h.Column({type:"text"}),l("design:type",String)],w.prototype,"name",void 0),a([h.Index(),h.Column({default:0}),l("design:type",Number)],w.prototype,"nameHash",void 0),a([h.Column({type:"float"}),l("design:type",Number)],w.prototype,"size",void 0),a([h.Column(),l("design:type",Number)],w.prototype,"type",void 0),a([h.Column({default:0}),l("design:type",Date)],w.prototype,"ctime",void 0),w=i=a([h.Entity(),l("design:paramtypes",[String,Number,Date,Object,Object,Number,Object])],w),t.FileInfo=w;const genComplexQuery=(e,n,i,o,r)=>c(void 0,void 0,void 0,(function*(){let a="",s=[];const l=(yield p.getConnection()).getMetadata(w).tableName;return n.every((e=>e))&&!i&&(a=`${e(!0)} from ${t.IndexTableName} where name match ?`,s=[processQueryText(n.join(" "))]),i&&(a=`${e(!1)} from ${l} where ${n.every((e=>e))?`id in (select rowId from ${t.IndexTableName} where name match ?) and `:""}${i?"name like ? and ":""}`.replace(/and\s?$/,""),s=[],n.every((e=>e))&&s.push(processQueryText(n.join(" "))),i&&s.push(t.processText(`%${i}%`))),a||(a=`${e(!1)} from ${l}`),void 0!==r&&(a+=" limit ?",s.push(r)),void 0!==o&&(a+=" offset ?",s.push(o)),{queryStr:a,queryParams:s}}));t.processText=(()=>{const e=[/([^\d/ ])(\d+)/g,/(\d+)([^\d/ ])/g,/([a-z])([A-Z])/g,/([A-Z]{2,})([a-z])/g,/([^/ ])([^\x00-\xff])/g,/([^\x00-\xff])([^/ ])/g,/([^/ ])([_])/g,/([_])([^/ ])/g];return(t,n="/")=>{const i=`$1${n}$2`;return e.reduce(((e,t)=>e.replace(t,i)),t)}})();const processQueryText=e=>t.processText(e," ");t.restoreText=e=>e.replace(/\//g,"")},57398:function(e,t,n){"use strict";var i=this&&this.__decorate||function(e,t,n,i){var o,r=arguments.length,a=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,n,a):o(t,n))||a);return r>3&&a&&Object.defineProperty(t,n,a),a},o=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},r=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function fulfilled(e){try{step(i.next(e))}catch(e){r(e)}}function rejected(e){try{step(i.throw(e))}catch(e){r(e)}}function step(e){e.done?o(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.ScanPath=void 0;const s=a(n(35747)),l=n(20025),c=n(85648),d=n(39370),u=n(10546),f=n(92788);let v=class ScanPath extends f.BaseDbInfoEntity{constructor(e){super(),this.path=e}};i([l.PrimaryGeneratedColumn(),o("design:type",Number)],v.prototype,"id",void 0),i([l.Column(),o("design:type",String)],v.prototype,"path",void 0),i([l.Column({nullable:!0}),o("design:type",String)],v.prototype,"dbPath",void 0),i([l.CreateDateColumn(),o("design:type",Date)],v.prototype,"createdAt",void 0),i([l.Column({nullable:!0}),o("design:type",Date)],v.prototype,"lastScanedAt",void 0),i([l.Column({nullable:!0,type:"text"}),o("design:type",String)],v.prototype,"lastMessage",void 0),i([l.Column({nullable:!0}),o("design:type",Number)],v.prototype,"lastSuccessCost",void 0),v=i([l.Entity(),o("design:paramtypes",[String])],v),t.ScanPath=v,f.SubDatabaseIterators.push((e=>r(void 0,void 0,void 0,(function*(){const t=d.getConfig(),n=yield v.find();for(const i of n){if(!i.dbPath)continue;const n=c.joinToAbsolute(t.finderRoot,i.dbPath),o=c.joinToAbsolute(t.finderRoot,i.path);if(s.default.existsSync(n)){if(!c.isPathInclude(t.finderRoot,o))try{yield d.switchDb({dbName:t.dbName,finderRoot:o,dbPath:n,readOnly:!0,isSubDb:!0,thumbnail:yield d.getThumbnail(n)},e)}catch(e){console.error("Query external scan path failed: ",o,e)}}else u.EvFinderStatus.value.scanAbsPathContexIdtMap.size||u.EvLogWarn(`It's time to rescan, database file of scan path not exist: ${n}.`)}}))))},28962:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.cEvRefreshRemote=t.cEvDbIncludedChange=t.cEvScanPathChange=t.cEvConfigLineChange=t.cEvFinderState=t.cEvScanBrake=void 0;const i=n(72872),o=n(85648),r=n(42276),a=n(80635);t.cEvScanBrake=new i.BehaviorSubject({});r.genRemoteCaller((()=>{}),a.JsonMoreEntity),r.genRemoteExector((()=>{}),a.JsonMoreEntity);t.cEvFinderState=new o.ShallowBehaviorSubject({configStack:[],configIndex:0,remoteMethodsServe:!0,linkedRemote:{},remoteMethodServeEntityMap:{},serverState:{}}),t.cEvConfigLineChange=new o.JsonSubject,t.cEvScanPathChange=new o.JsonSubject,t.cEvDbIncludedChange=new o.JsonSubject,t.cEvRefreshRemote=new i.Subject},33296:function(e,t,n){"use strict";var i,o=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function fulfilled(e){try{step(i.next(e))}catch(e){r(e)}}function rejected(e){try{step(i.throw(e))}catch(e){r(e)}}function step(e){e.done?o(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.watchAutoRescan=t.unlinkRemotes=t.linkRemotes=t.waitWsConnected=t.clsRootTrigger=void 0;const a=n(96486),s=n(14857),l=n(85648),c=r(n(8777)),d=n(95601),u=n(39778),f=n(39370),v=n(40811),h=n(4971),m=n(13681),g=n(21076),p=n(10546),y=n(42276),b=n(28962),E=n(80635);function waitWsConnected(e,t,n,i=y.uiMsgTimeout){return new Promise(((o,r)=>{let a;const s=setTimeout((()=>{onFailed({error:"waitWsConnected timeout"})}),i),onFailed=e=>{clearTimeout(s);const i=e.error||`waitWsConnected websocket closed: ${e.reason}`;t&&r(i),n||console.warn(i),o(!1),a&&a.readyState!==a.CLOSED&&a.readyState!==a.CLOSING&&a.close()};try{a=new c.default(e)}catch(e){onFailed({error:`Create websocket failed: ${e}`})}if(!a)return void o(!1);const l=a;l.addEventListener("error",onFailed),l.addEventListener("close",onFailed),l.once("open",(()=>{null==l||l.removeEventListener("error",onFailed),null==l||l.removeEventListener("close",onFailed),clearTimeout(s),o(l)}))}))}t.clsRootTrigger=(()=>{let e=[];return setInterval((()=>{e.forEach((e=>e())),e=[]}),500),t=>new Promise(((n,i)=>{e.push((()=>o(void 0,void 0,void 0,(function*(){const e=yield t().catch(i);e&&n(e)}))))}))})(),t.waitWsConnected=waitWsConnected,i=(()=>{let e,t;const doClear=()=>{e&&(clearInterval(e),e=void 0),t&&(t.forEach((e=>e.unsubscribe())),t=void 0)},linkRemotes=(n=6e4)=>{doClear();const sync=(e=!1)=>o(void 0,void 0,void 0,(function*(){const{linkedRemote:t}=b.cEvFinderState.value,n=Object.assign({},linkRemotes),i=yield v.ConfigLine.find({where:{type:g.ConfigLineType.remoteUrl}}),r=i.filter((n=>!n.disabled&&(!t[n.content]||e&&t[n.content].unavailable||t[n.content].broken))),s=new Map(i.map((e=>[e.content,e]))),c=Object.entries(t).filter((([e])=>{var t;return!s.get(e)||(null===(t=s.get(e))||void 0===t?void 0:t.disabled)}));if(r.length||c.length){c.forEach((([e,n])=>{var i;delete t[e],n.reconnectTimeout&&(clearTimeout(n.reconnectTimeout),n.reconnectTimeout=void 0),n.broken=!0,n.caller=void 0,null===(i=n.socket)||void 0===i||i.close()}));const doLink=(t,i=n)=>o(void 0,void 0,void 0,(function*(){const n=yield waitWsConnected(l.concatUrls(t.content,d.EVENT_ORM_METHOD_WEBSOCKET_ROUTE),!1,e);if(n){const e=y.genRemoteCaller((e=>n.send(e)),E.JsonMoreEntity);n.on("message",(t=>e.recieve(String(t)))),n.on("close",(()=>{if(!o.broken){if(o.broken=!0,o.caller=void 0,o.reconnectTimeout&&clearTimeout(o.reconnectTimeout),!b.cEvFinderState.value.linkedRemote[t.content])return;o.reconnectTimeout=setTimeout((()=>{doLink(t,b.cEvFinderState.value.linkedRemote).then((()=>{b.cEvFinderState.next({linkedRemote:Object.assign({},b.cEvFinderState.value.linkedRemote)}),p.EvLog("Reconnect to remote : "+t.content)}))}),1e4),b.cEvFinderState.next({linkedRemote:Object.assign({},b.cEvFinderState.value.linkedRemote)}),p.EvLogWarn("Remote connection broken: "+t.content)}}));const o={socket:n,caller:e};i[t.content]=o}else i[t.content]={unavailable:!0}}));yield Promise.all(r.map((e=>doLink(e)))),a.isEqual(linkRemotes,n)||b.cEvFinderState.next({linkedRemote:Object.assign(Object.assign({},b.cEvFinderState.value.linkedRemote),n)})}}));t=[b.cEvConfigLineChange.pipe(s.debounceTime(500)).subscribe((()=>sync())),b.cEvRefreshRemote.subscribe((()=>sync(!0)))],e=setInterval((()=>sync(!0)),n),sync()};return{linkRemotes,unlinkRemotes:()=>{doClear();const{linkedRemote:e}=b.cEvFinderState.value;b.cEvFinderState.next({linkedRemote:{}}),Object.values(e).forEach((e=>{var t;return null===(t=e.socket)||void 0===t?void 0:t.close()}))}}})(),t.linkRemotes=i.linkRemotes,t.unlinkRemotes=i.unlinkRemotes,t.watchAutoRescan=(()=>{const e=new Map,refreshWatcher=()=>{f.switchDb(u.Config,(()=>o(void 0,void 0,void 0,(function*(){const n=yield h.DbIncluded.queryAllDbIncluded((()=>o(void 0,void 0,void 0,(function*(){return[f.getConfig()]})))),i=new Set(n.map((e=>e.finderRoot)));i.add(u.Config.finderRoot),Array.from(e.entries()).forEach((([e,t])=>{i.has(e)||t()})),n.concat(u.Config).forEach((n=>{e.has(n.finderRoot)||(n=>{var i;let r,s=Date.now(),c=1/0;const doWatch=()=>t.clsRootTrigger((()=>o(void 0,void 0,void 0,(function*(){g.isScanDurationAvailable(c)&&(Date.now()-s>c&&(s=Date.now(),p.EvLog("Auto scan context: "+n.finderRoot),yield f.switchDb(n,(()=>o(void 0,void 0,void 0,(function*(){yield m.doScan(void 0,void 0,void 0,void 0,void 0,void 0,c)})))).catch((e=>{p.EvLogWarn("Auto scan failed, context: "+n.finderRoot,e)})),s=Date.now()),r&&clearTimeout(r),g.isScanDurationAvailable(c)&&(r=setTimeout(doWatch,c)))})))),d=p.EvUiCmdResult.subscribe((e=>{if("listConfig"===e.cmd&&!e.result.error&&(e.result.oriData.type===g.ConfigLineType.autoRescan||a.isEmpty(e.result.oriData))&&g.getDbInfoId(e.context)===g.getDbInfoId(n)){const t=e.result.results.find((e=>e.type===g.ConfigLineType.autoRescan));try{let e=g.defaultAutoScanSetting;(null==t?void 0:t.jsonStr)&&(e=Object.assign(Object.assign({},g.defaultAutoScanSetting),l.JsonMore.parse(t.jsonStr))),c=g.isScanDurationAvailable(e.duration)?3600*e.duration*1e3:1/0,s=Date.now(),doWatch()}catch(e){p.EvLogWarn("Failed to parse autoRescan config: "+(null==t?void 0:t.jsonStr))}}}));null===(i=e.get(n.finderRoot))||void 0===i||i(),e.set(n.finderRoot,(()=>{d.unsubscribe(),r&&clearTimeout(r),c=1/0,e.delete(n.finderRoot)})),p.EvUiCmd.next({cmd:"listConfig",data:{type:g.ConfigLineType.autoRescan},context:n})})(n)}))}))))};return()=>{b.cEvDbIncludedChange.pipe(s.debounceTime(500)).subscribe(refreshWatcher),refreshWatcher()}})()},80635:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.JsonMoreEntity=void 0;const i=n(14706),o=n(85648);t.JsonMoreEntity=o.buildJsonMoreWithDefaultPackers([{constructor:i.FileInfo,pack:e=>o.JsonMore.stringify(o.removeFunctionProperties(e)),unpack:e=>{if("string"!=typeof e)throw new o.ErrorSpecialDataUnpack;return Object.assign(new i.FileInfo,o.JsonMore.parse(e))}}])},58503:function(e,t,n){"use strict";var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function fulfilled(e){try{step(i.next(e))}catch(e){r(e)}}function rejected(e){try{step(i.throw(e))}catch(e){r(e)}}function step(e){e.done?o(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))},o=this&&this.__rest||function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}return n};Object.defineProperty(t,"__esModule",{value:!0});const r=n(96486),a=n(11169),s=n(39778),l=n(39370),c=n(14706),d=n(7060),u=n(28962),f=n(10546),v=n(44204),h=n(162),m=n(72872),g=n(14857),p=n(96486);u.cEvScanPathChange.subscribe((e=>f.EvFileInfoChange.next(e))),u.cEvDbIncludedChange.subscribe((e=>f.EvFileInfoChange.next(e)));const y=m.merge(f.EvFileInfoChange,f.EvFinderState.pipe(g.map((e=>e.remotes))).pipe(g.distinctUntilChanged(p.isEqual)));m.merge(y.pipe(g.debounceTime(500)),y.pipe(g.throttleTime(500))).subscribe((()=>i(void 0,void 0,void 0,(function*(){const[e,t,n]=yield l.switchDb(s.Config,(()=>c.FileInfo.countAllDatabases()));f.EvDatabaseInfos.next({totalFileInfoCount:e,localFileInfoCount:t,remoteFileInfoCount:n})})))),u.cEvFinderState.subscribe((e=>{f.EvFinderState.next({config:r.last(e.configStack),remotes:Object.entries(e.linkedRemote).reduce(((e,[t,n])=>(e[t]=r.pick(n,v.LinkedRemoteItemKeys),e)),{}),servers:Object.entries(e.serverState).reduce(((e,[t,n])=>{const{server:i}=n,r=o(n,["server"]);return e[t]=r,e}),{}),osInfo:{systemIps:a.getIpAddressList()}})})),u.cEvConfigLineChange.subscribe((e=>{h.uiCmdExecutor({cmd:"listConfig",data:{},context:e||s.Config})})),u.cEvDbIncludedChange.subscribe((e=>{h.uiCmdExecutor({cmd:"listDbIncluded",context:e||s.Config})})),u.cEvScanPathChange.subscribe((e=>{h.uiCmdExecutor({cmd:"listPath",data:[],context:e||s.Config})}));const b=f.EvUiLaunched.subscribe((e=>{e.electron&&process.nextTick((()=>{b.unsubscribe(),d.watchServerSettings()}))}))},69922:function(e,t,n){"use strict";var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&i(t,e,n);return o(t,e),t},a=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function fulfilled(e){try{step(i.next(e))}catch(e){r(e)}}function rejected(e){try{step(i.throw(e))}catch(e){r(e)}}function step(e){e.done?o(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))},s=this&&this.__rest||function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}return n};Object.defineProperty(t,"__esModule",{value:!0}),t.joinContextPipe=t.switchEvent=void 0;const l=n(85648),c=n(85648),d=r(n(10546)),u=n(42276),f=n(44204);t.switchEvent=l.switchEventInSubjects(d,l.JsonMore);t.joinContextPipe=function joinContextPipe(e){let t=!1;const{isStartJoint:n,onData:i,forward:o}=e,{sendToClient:r,switchContext:d}=Object.assign({sendToClient:()=>{},switchContext:()=>{}},e);let v=new c.ComsumableEvent,h=new c.ComsumableEvent,m=[],g=!1;const p={recieveFromNext:e=>a(this,void 0,void 0,(function*(){if(t)console.warn(" JoinContextPipe recieveFromNext after destoried");else try{const t=l.JsonMore.parse(e);if(!t||h.next(t))return;if("ContextWrappedMsg"!==t.label)return void console.warn("Unknown message recieveFromNext: ",e);if(f.isCommonMsgResult(t)){if("switchContext"===t.cmd||"tran"===t.cmd)throw new Error(`Unexpected joinContextPipe packet from next: ${l.JsonMore.stringify(t)}`);n||r(e)}else{const e=u.keepHeartBeat(o,t.tag),a=v.split((e=>e));try{let c;if("tran"!==t.cmd)throw"switchContext"===t.cmd?new Error(`Unexpected joinContextPipe packet from next: ${l.JsonMore.stringify(t)}`):new Error(`Unhandled joinContextPipe packet: ${l.JsonMore.stringify(t)}`);{const{data:e}=t,o=s(t,["data"]);c=Object.assign(Object.assign({},o),{result:{data:n?yield i(e):l.JsonMore.stringify(yield u.executeRemoteMsg(t,r,a,l.JsonMore,!0))}})}o(l.JsonMore.stringify(c))}catch(e){const{data:n}=t,i=s(t,["data"]);try{o(l.JsonMore.stringify(Object.assign(Object.assign({},i),{result:{error:{msg:String(e),context:m}}})))}catch(e){console.error("Send error to next failed",e)}}finally{e.stop(),a.destory()}}}catch(t){console.error("Invalid ContextPipe message from client: ",e)}})),sendData:e=>a(this,void 0,void 0,(function*(){const t={label:"ContextWrappedMsg",cmd:"tran",data:e,tag:Date.now().toString(36)+Math.random().toString(36)};if(n){const e=h.split((e=>e));return yield u.executeRemoteMsg(t,o,e,l.JsonMore,!0).finally(e.destory.bind(e))}{const e=v.split((e=>e));return yield u.executeRemoteMsg(t,r,e,l.JsonMore,!0).finally(e.destory.bind(e))}})),destory:()=>{t=!0,v.destory(),h.destory()}};return(e=>!e.isStartJoint)(e)?Object.assign(Object.assign({},p),{recieveFromClient:n=>a(this,void 0,void 0,(function*(){if(t)console.warn(" JoinContextPipe recieveFromClient after destoried");else try{const t=l.JsonMore.parse(n);if(!t||v.next(t))return;if("ContextWrappedMsg"!==t.label)return void console.warn("Unknown message recieveFromClient: ",n);if(f.is