From 81004b3fea22e2fd3d67e740363c346c93304f71 Mon Sep 17 00:00:00 2001 From: maxgithubprofile <21055122+maxgithubprofile@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:00:34 +0300 Subject: [PATCH] fix: rm local apps (#1333) * v * Update satolist.js * v --- js/functions.js | 29 +++++++++++++++--- js/lib/apps/index.js | 11 +++++-- js/lib/client/sdk.js | 71 +++++++++++++++++++++++++++++++++++++++++++- package.json | 4 +-- 4 files changed, 105 insertions(+), 10 deletions(-) diff --git a/js/functions.js b/js/functions.js index b7f3da837..f6f0e7bd2 100644 --- a/js/functions.js +++ b/js/functions.js @@ -9802,6 +9802,31 @@ checkConnection = function () { } } +localSearch = function(s1 = '', s2 = '', level = 0.6){ + + if(!s1) return 0 + if(!s2) return 1 + + s1 = s1.toLowerCase() + s2 = s2.toLowerCase() + + if (s1.indexOf(s2) > -1) return 1 + + var parts = s1.split(/[ \t\v\r\n\f,.]+/) + + var m = 0 + + _.each(parts, (part) => { + var eq = stringEqTrig(part, s2) + + if (eq > level && eq > m) m = eq + }) + + if(m < 0 || !m) m = 0 + + return m +} + stringEqTrig = function (s1, s2) { if (!s1) s1 = '' @@ -9818,8 +9843,6 @@ stringEqTrig = function (s1, s2) { return ps.toLowerCase().replace(/[^a-zа-я0-9&]*/g, ''); } - - var makeTr = function (w) { var trs = {}; @@ -9830,8 +9853,6 @@ stringEqTrig = function (s1, s2) { else c = w[index]; - - return c; } diff --git a/js/lib/apps/index.js b/js/lib/apps/index.js index 35ff97f21..15bf152bc 100644 --- a/js/lib/apps/index.js +++ b/js/lib/apps/index.js @@ -1233,6 +1233,8 @@ var BastyonApps = function (app) { _.each(localdata, (info, id) => { + if(!id || id == 'undefined') return + var saving = { id, cached: {}, @@ -1606,6 +1608,9 @@ var BastyonApps = function (app) { } var loadAllAppsFromLocalhost = function () { + + return [] + let apps = []; for (let i = 0; i < localStorage.length; i++) { const key = localStorage.key(i); @@ -1788,7 +1793,7 @@ var BastyonApps = function (app) { var promises = [] const developApps = app.developapps || []; - const localApps = loadAllAppsFromLocalhost() || []; + const localApps = [] //loadAllAppsFromLocalhost() || []; const allApps = [...developApps, ...localApps]; if (allApps.length > 0) { @@ -1839,9 +1844,9 @@ var BastyonApps = function (app) { console.log("INSTALLED LOCAL", installedLocal) - _.forEach(installedLocal, (info) => { + /*_.forEach(installedLocal, (info) => { info?.id && install(info.data, info.cached) - }) + })*/ promises.push(Promise.all(_.map(installedLocal, (info) => { diff --git a/js/lib/client/sdk.js b/js/lib/client/sdk.js index ca2dc316c..8010168ed 100644 --- a/js/lib/client/sdk.js +++ b/js/lib/client/sdk.js @@ -32,7 +32,7 @@ var pSDK = function ({ app, api, actions }) { }, userInfoLight: { - time: 30000 + time: 120000 }, userState: { @@ -759,6 +759,17 @@ var pSDK = function ({ app, api, actions }) { self.userInfo = { keys: ['userInfoFull', 'userInfoLight'], + objkey : 'address', + + searchIndex : function(obj){ + var sobj = { + name : {v : (obj.n || obj.name), c : 5}, + about : {v : (obj.a || obj.about), c : 1} + } + + return sobj + }, + cleanData: function (rawinfo) { return _.filter(_.map(rawinfo, (c) => { @@ -1861,6 +1872,18 @@ var pSDK = function ({ app, api, actions }) { self.share = { keys: ['share'], + objkey : 'txid', + + searchIndex : function(obj){ + var sobj = { + caption : {v : (obj.c || obj.caption), c : 2}, + message : {v : (obj.b || obj.message), c : 1}, + tags : {v : (obj.t || obj.tags || []).join(' '), c : 1} + } + + return sobj + }, + request: function (executor, hash, cacheIndex) { return request('share', hash, (data) => { @@ -3039,6 +3062,52 @@ var pSDK = function ({ app, api, actions }) { prepareStorages() } + self.search = function(type, str = ''){ + if(!self[type]) return [] + + var meta = self[type] + + var objs = [] + + _.each(meta.keys, (key) => { + objs = objs.concat(_.toArray(objects[key])) + }) + + if (meta.objkey){ + objs = _.uniq(objs, (o) => { + return o[meta.objkey] + }) + } + + var si = meta.searchIndex + + var executor = function(obj){ + var ind = si(obj) + var value = 0 + + _.each(ind, ({v = '', c = 1}) => { + + console.log('localSearch(v, str)', localSearch(v, str), v, str, c) + + value += localSearch(v, str) * c + }) + + return value + } + + console.log('objs', objs) + + var resultObjects = _.map(objs, (obj) => { + var value = executor(obj) + + return { + obj, value + } + }) + + return Promise.resolve(resultObjects) + } + self.ws = { update : function(type, wsdata){ diff --git a/package.json b/package.json index 6cd2bb19f..17e6c00bc 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,9 @@ "version": "0.9.105", - "versionsuffix": "3", + "versionsuffix": "4", "cordovaversion": "1.8.105", - "cordovaversioncode": "1801053", + "cordovaversioncode": "1801054", "description": "Bastyon desktop application", "author": "Pocketnet Community ",