mirror of
https://github.com/Gongxh0901/kunpolibrary
synced 2025-07-02 22:34:20 +00:00
修复cdn缓存导致检测不到更新的问题;发布1.0.32版本
This commit is contained in:
parent
0f912897f4
commit
fad4a70301
@ -12,3 +12,5 @@
|
|||||||
- 调整微信和抖音小游戏广告实现
|
- 调整微信和抖音小游戏广告实现
|
||||||
## 1.0.31
|
## 1.0.31
|
||||||
- 修改资源加载器,自定义加载批次,支持按加载批次释放资源,详情见 [资源管理](./docs/Asset.md)
|
- 修改资源加载器,自定义加载批次,支持按加载批次释放资源,详情见 [资源管理](./docs/Asset.md)
|
||||||
|
## 1.0.32
|
||||||
|
- 修复热更新manifest文件cdn缓存导致检测不到更新的问题
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "kunpocc",
|
"name": "kunpocc",
|
||||||
"version": "1.0.31",
|
"version": "1.0.32",
|
||||||
"description": "基于creator3.0+的kunpocc库",
|
"description": "基于creator3.0+的kunpocc库",
|
||||||
"main": "./dist/kunpocc.cjs",
|
"main": "./dist/kunpocc.cjs",
|
||||||
"module": "./dist/kunpocc.mjs",
|
"module": "./dist/kunpocc.mjs",
|
||||||
|
@ -8,6 +8,7 @@ import { game, native, sys } from "cc";
|
|||||||
import { ICheckUpdatePromiseResult, IPromiseResult } from "../interface/PromiseResult";
|
import { ICheckUpdatePromiseResult, IPromiseResult } from "../interface/PromiseResult";
|
||||||
import { ReadNetFile } from "../net/nettools/ReadNetFile";
|
import { ReadNetFile } from "../net/nettools/ReadNetFile";
|
||||||
import { debug, warn } from "../tool/log";
|
import { debug, warn } from "../tool/log";
|
||||||
|
import { Time } from "../tool/Time";
|
||||||
import { Utils } from "../tool/Utils";
|
import { Utils } from "../tool/Utils";
|
||||||
import { HotUpdateManager } from "./HotUpdateManager";
|
import { HotUpdateManager } from "./HotUpdateManager";
|
||||||
|
|
||||||
@ -222,7 +223,16 @@ export class HotUpdate {
|
|||||||
reject({ code: HotUpdateCode.LoadManifestFailed, message: "读取本地project.manifest文件失败" });
|
reject({ code: HotUpdateCode.LoadManifestFailed, message: "读取本地project.manifest文件失败" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let content = native.fileUtils.getStringFromFile(HotUpdateManager.getInstance().manifestUrl);
|
let writablePath = HotUpdateManager.getInstance().writablePath;
|
||||||
|
// 本地内容
|
||||||
|
let content = "";
|
||||||
|
let cacheManifestPath = writablePath + "project.manifest";
|
||||||
|
if (native.fileUtils.isFileExist(cacheManifestPath)) {
|
||||||
|
content = native.fileUtils.getStringFromFile(cacheManifestPath);
|
||||||
|
} else {
|
||||||
|
let manifestUrl = HotUpdateManager.getInstance().manifestUrl;
|
||||||
|
content = native.fileUtils.getStringFromFile(manifestUrl);
|
||||||
|
}
|
||||||
if (content) {
|
if (content) {
|
||||||
resolve({ code: HotUpdateCode.Succeed, message: "读取本地project.manifest文件成功", manifest: JSON.parse(content) });
|
resolve({ code: HotUpdateCode.Succeed, message: "读取本地project.manifest文件成功", manifest: JSON.parse(content) });
|
||||||
} else {
|
} else {
|
||||||
@ -262,8 +272,8 @@ export class HotUpdate {
|
|||||||
resolve({ code: HotUpdateCode.LatestVersion, message: "已是最新版本" });
|
resolve({ code: HotUpdateCode.LatestVersion, message: "已是最新版本" });
|
||||||
} else {
|
} else {
|
||||||
// 替换manifest中的内容
|
// 替换manifest中的内容
|
||||||
manifest.remoteManifestUrl = versionManifest.remoteManifestUrl;
|
manifest.remoteManifestUrl = Utils.addUrlParam(versionManifest.remoteManifestUrl, "timeStamp", `${Time.now()}`);
|
||||||
manifest.remoteVersionUrl = versionManifest.remoteVersionUrl;
|
manifest.remoteVersionUrl = Utils.addUrlParam(versionManifest.remoteVersionUrl, "timeStamp", `${Time.now()}`);
|
||||||
manifest.packageUrl = versionManifest.packageUrl;
|
manifest.packageUrl = versionManifest.packageUrl;
|
||||||
|
|
||||||
// 注册本地manifest根目录
|
// 注册本地manifest根目录
|
||||||
|
@ -5,18 +5,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Time } from "../../tool/Time";
|
import { Time } from "../../tool/Time";
|
||||||
|
import { Utils } from "../../tool/Utils";
|
||||||
import { HttpManager } from "../http/HttpManager";
|
import { HttpManager } from "../http/HttpManager";
|
||||||
import { IHttpResponse } from "../http/IHttpResponse";
|
import { IHttpResponse } from "../http/IHttpResponse";
|
||||||
|
|
||||||
export class ReadNetFile {
|
export class ReadNetFile {
|
||||||
constructor(res: { url: string, timeout: number, responseType: "text" | "json" | "arraybuffer", onComplete: (data: any) => void, onError: (code: number, message: string) => void }) {
|
constructor(res: { url: string, timeout: number, responseType: "text" | "json" | "arraybuffer", onComplete: (data: any) => void, onError: (code: number, message: string) => void }) {
|
||||||
// 地址上带时间戳参数 确保每次请求都到服务器上请求最新配置,而不是拿到上次请求的缓存数据
|
// 地址上带时间戳参数 确保每次请求都到服务器上请求最新配置,而不是拿到上次请求的缓存数据
|
||||||
let url = res.url;
|
let url = Utils.addUrlParam(res.url, "timeStamp", `${Time.now()}`);
|
||||||
if (url.indexOf("?") > -1) {
|
|
||||||
url += `&timeStamp=${Time.now()}`;
|
|
||||||
} else {
|
|
||||||
url += `?timeStamp=${Time.now()}`;
|
|
||||||
}
|
|
||||||
HttpManager.get(url, null, res.responseType, {
|
HttpManager.get(url, null, res.responseType, {
|
||||||
onComplete: (response: IHttpResponse) => {
|
onComplete: (response: IHttpResponse) => {
|
||||||
res.onComplete(response.data);
|
res.onComplete(response.data);
|
||||||
|
@ -47,4 +47,34 @@ export class Utils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取url参数
|
||||||
|
* @param url
|
||||||
|
*/
|
||||||
|
public static getUrlParam(url: string): { url: string, params: { [key: string]: string } } {
|
||||||
|
let result = { url: "", params: {} as { [key: string]: string } };
|
||||||
|
let urlArr = url.split('?');
|
||||||
|
result.url = urlArr[0];
|
||||||
|
if (urlArr.length > 1) {
|
||||||
|
let paramsArr = urlArr[1].split("&");
|
||||||
|
for (let i = 0; i < paramsArr.length; i++) {
|
||||||
|
let item = paramsArr[i];
|
||||||
|
let [key, value] = item.split("=");
|
||||||
|
result.params[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 给url添加参数
|
||||||
|
* @param url
|
||||||
|
* @returns 新的url
|
||||||
|
*/
|
||||||
|
public static addUrlParam(url: string, key: string, value: string): string {
|
||||||
|
let urlData = this.getUrlParam(url);
|
||||||
|
urlData.params[key] = value;
|
||||||
|
return urlData.url + "?" + Object.entries(urlData.params).map(([key, value]) => `${key}=${value}`).join("&");
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user