提交 171206c6 编写于 作者: AndroidLeaves's avatar AndroidLeaves

update

上级 7baf3981
......@@ -418,7 +418,7 @@ class Widget extends BaseWidget {
let response = undefined;
try {
//////
const html = await this.httpGet(`${this.defaultPreference.domain}/search?q=${encodeURIComponent(keyword)}`, { jsonFormat: false, headers: this.defaultPreference.phoneHeaders });
const html = await this.httpGet(`${this.defaultPreference.domain}/search?q=${encodeURIComponent(keyword)}`, { jsonFormat: false, useCache: false, headers: this.defaultPreference.phoneHeaders });
let webview = new WebView();
await webview.loadHTML(html);
// 通过dom操作把HTML里面的热榜内容提取出来
......
......@@ -711,35 +711,41 @@ class BaseWidget {
headers: null,
logable: false,
useICloud: false,
useCache: true,
scriptName: this.scriptName
};
options = {
...defaultOptions,
...options
};
const { jsonFormat, headers, logable, useICloud, scriptName } = options;
const { jsonFormat, headers, logable, useICloud, useCache, scriptName } = options;
// 根据URL进行md5生成cacheKey
const cacheFileName = this.md5(url);
const ufm = this.useFileManager({ useICloud, scriptName });
// 读取本地缓存
const localCache = ufm.readStringCache(cacheFileName);
// 判断是否需要刷新
const lastCacheTime = ufm.getCacheModifyDate(cacheFileName);
const timeInterval = Math.floor((this.getCurrentTimeStamp() - lastCacheTime) / 60);
const canUseCache = localCache != null && localCache.length > 0;
// 过时且有本地缓存则直接返回本地缓存数据
const { refreshInterval = '0' } = this.readWidgetSetting();
const shouldLoadCache = timeInterval <= Number(refreshInterval) && canUseCache;
console.log(`⏰ ${this.getDateStr(new Date(lastCacheTime * 1000), 'HH:mm')}加入缓存,已缓存 ${lastCacheTime > 0 ? timeInterval : 0}min,缓存${shouldLoadCache ? '未过期' : '已过期'}`);
if (shouldLoadCache) {
console.log(`🤖 Get读取缓存:${url}`);
// 是否打印响应数据
if (logable) {
console.log(`🤖 Get请求响应:${localCache}`);
if (useCache) {
// 判断是否需要刷新
const lastCacheTime = ufm.getCacheModifyDate(cacheFileName);
const timeInterval = Math.floor((this.getCurrentTimeStamp() - lastCacheTime) / 60);
const canUseCache = localCache != null && localCache.length > 0;
// 过时且有本地缓存则直接返回本地缓存数据
const { refreshInterval = '0' } = this.readWidgetSetting();
const shouldLoadCache = timeInterval <= Number(refreshInterval) && canUseCache;
console.log(`⏰ ${this.getDateStr(new Date(lastCacheTime * 1000), 'HH:mm')}加入缓存,已缓存 ${lastCacheTime > 0 ? timeInterval : 0}min,缓存${shouldLoadCache ? '未过期' : '已过期'}`);
if (shouldLoadCache) {
console.log(`🤖 Get读取缓存:${url}`);
// 是否打印响应数据
if (logable) {
console.log(`🤖 Get请求响应:${localCache}`);
}
this.logDivider();
return jsonFormat ? JSON.parse(localCache) : localCache;
}
this.logDivider();
return jsonFormat ? JSON.parse(localCache) : localCache;
}
console.log(`🚀 Get在线请求:${url}`);
let req = new Request(url);
req.method = 'GET';
......@@ -792,6 +798,7 @@ class BaseWidget {
headers: null,
logable: false,
useICloud: false,
useCache: true,
scriptName: Script.name()
};
options = {
......@@ -799,28 +806,33 @@ class BaseWidget {
...options
};
const { jsonFormat, headers, logable, useICloud, scriptName } = options;
// 根据URL进行md5生成cacheKey
const cacheFileName = this.md5(url);
const ufm = this.useFileManager({ useICloud, scriptName });
// 读取本地缓存
const localCache = ufm.readStringCache(cacheFileName);
// 判断是否需要刷新
const lastCacheTime = ufm.getCacheModifyDate(cacheFileName);
const timeInterval = Math.floor((this.getCurrentTimeStamp() - lastCacheTime) / 60);
const canUseCache = localCache != null && localCache.length > 0;
// 过时且有本地缓存则直接返回本地缓存数据
const { refreshInterval = '0' } = this.readWidgetSetting();
const shouldLoadCache = timeInterval <= Number(refreshInterval) && canUseCache;
console.log(`⏰ ${this.getDateStr(new Date(lastCacheTime * 1000), 'HH:mm')}加入缓存,已缓存 ${lastCacheTime > 0 ? timeInterval : 0}min,缓存${shouldLoadCache ? '未过期' : '已过期'}`);
if (shouldLoadCache) {
console.log(`🤖 Post读取缓存:${url}`);
// 是否打印响应数据
if (logable) {
console.log(`🤖 Post请求响应:${localCache}`);
if (useCache) {
// 判断是否需要刷新
const lastCacheTime = ufm.getCacheModifyDate(cacheFileName);
const timeInterval = Math.floor((this.getCurrentTimeStamp() - lastCacheTime) / 60);
const canUseCache = localCache != null && localCache.length > 0;
// 过时且有本地缓存则直接返回本地缓存数据
const { refreshInterval = '0' } = this.readWidgetSetting();
const shouldLoadCache = timeInterval <= Number(refreshInterval) && canUseCache;
console.log(`⏰ ${this.getDateStr(new Date(lastCacheTime * 1000), 'HH:mm')}加入缓存,已缓存 ${lastCacheTime > 0 ? timeInterval : 0}min,缓存${shouldLoadCache ? '未过期' : '已过期'}`);
if (shouldLoadCache) {
console.log(`🤖 Post读取缓存:${url}`);
// 是否打印响应数据
if (logable) {
console.log(`🤖 Post请求响应:${localCache}`);
}
this.logDivider();
return jsonFormat ? JSON.parse(localCache) : localCache;
}
this.logDivider();
return jsonFormat ? JSON.parse(localCache) : localCache;
}
console.log(`🚀 Post在线请求:${url}`);
let req = new Request(url);
req.method = 'POST';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册