MCPcopy Create free account
hub / github.com/chavyleung/scripts / reloadAppSubCache

Function reloadAppSubCache

box/chavy.boxjs.js:1023–1050  ·  view source on GitHub ↗

* =================================== * 工具类函数 * ===================================

(url)

Source from the content-addressed store, hash-verified

1021 */
1022
1023function reloadAppSubCache(url) {
1024 // 仅刷新 http(s) 远程订阅;粘贴导入的订阅无远程地址,跳过刷新保留已有缓存
1025 if (!url || !/^https?:\/\//i.test(url)) {
1026 return Promise.resolve()
1027 }
1028 // 地址后面拼时间缀, 避免 GET 缓存
1029 const requrl = `${url}${
1030 url.includes('?') ? '&' : '?'
1031 }_=${new Date().getTime()}`
1032 return $.http.get(requrl).then((resp) => {
1033 try {
1034 const subcaches = getAppSubCaches()
1035 subcaches[url] = $.toObj(resp.body)
1036 subcaches[url].updateTime = new Date()
1037 // 仅缓存存在 id 的订阅
1038 Object.keys(subcaches).forEach((key) => {
1039 if (!subcaches[key].hasOwnProperty('id')) {
1040 delete subcaches[key]
1041 }
1042 })
1043 $.setjson(subcaches, $.KEY_app_subCaches)
1044 $.log(`更新订阅, 成功! ${url}`)
1045 } catch (e) {
1046 $.logErr(e)
1047 $.log(`更新订阅, 失败! ${url}`)
1048 }
1049 })
1050}
1051
1052function update(obj, path, value) {
1053 const keys = path.split('.')

Callers 3

apiAddAppSubFunction · 0.70
apiReloadAppSubFunction · 0.70
reloadAppSubCachesFunction · 0.70

Calls 6

getAppSubCachesFunction · 0.70
getMethod · 0.45
toObjMethod · 0.45
setjsonMethod · 0.45
logMethod · 0.45
logErrMethod · 0.45

Tested by

no test coverage detected