修复cdn缓存导致检测不到更新的问题;发布1.0.32版本

This commit is contained in:
gongxh 2025-05-08 15:01:43 +08:00
parent 0f912897f4
commit fad4a70301
5 changed files with 48 additions and 10 deletions

View File

@ -12,3 +12,5 @@
- 调整微信和抖音小游戏广告实现
## 1.0.31
- 修改资源加载器,自定义加载批次,支持按加载批次释放资源,详情见 [资源管理](./docs/Asset.md)
## 1.0.32
- 修复热更新manifest文件cdn缓存导致检测不到更新的问题

View File

@ -1,6 +1,6 @@
{
"name": "kunpocc",
"version": "1.0.31",
"version": "1.0.32",
"description": "基于creator3.0+的kunpocc库",
"main": "./dist/kunpocc.cjs",
"module": "./dist/kunpocc.mjs",

View File

@ -8,6 +8,7 @@ import { game, native, sys } from "cc";
import { ICheckUpdatePromiseResult, IPromiseResult } from "../interface/PromiseResult";
import { ReadNetFile } from "../net/nettools/ReadNetFile";
import { debug, warn } from "../tool/log";
import { Time } from "../tool/Time";
import { Utils } from "../tool/Utils";
import { HotUpdateManager } from "./HotUpdateManager";
@ -222,7 +223,16 @@ export class HotUpdate {
reject({ code: HotUpdateCode.LoadManifestFailed, message: "读取本地project.manifest文件失败" });
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) {
resolve({ code: HotUpdateCode.Succeed, message: "读取本地project.manifest文件成功", manifest: JSON.parse(content) });
} else {
@ -262,8 +272,8 @@ export class HotUpdate {
resolve({ code: HotUpdateCode.LatestVersion, message: "已是最新版本" });
} else {
// 替换manifest中的内容
manifest.remoteManifestUrl = versionManifest.remoteManifestUrl;
manifest.remoteVersionUrl = versionManifest.remoteVersionUrl;
manifest.remoteManifestUrl = Utils.addUrlParam(versionManifest.remoteManifestUrl, "timeStamp", `${Time.now()}`);
manifest.remoteVersionUrl = Utils.addUrlParam(versionManifest.remoteVersionUrl, "timeStamp", `${Time.now()}`);
manifest.packageUrl = versionManifest.packageUrl;
// 注册本地manifest根目录

View File

@ -5,18 +5,14 @@
*/
import { Time } from "../../tool/Time";
import { Utils } from "../../tool/Utils";
import { HttpManager } from "../http/HttpManager";
import { IHttpResponse } from "../http/IHttpResponse";
export class ReadNetFile {
constructor(res: { url: string, timeout: number, responseType: "text" | "json" | "arraybuffer", onComplete: (data: any) => void, onError: (code: number, message: string) => void }) {
// 地址上带时间戳参数 确保每次请求都到服务器上请求最新配置,而不是拿到上次请求的缓存数据
let url = res.url;
if (url.indexOf("?") > -1) {
url += `&timeStamp=${Time.now()}`;
} else {
url += `?timeStamp=${Time.now()}`;
}
let url = Utils.addUrlParam(res.url, "timeStamp", `${Time.now()}`);
HttpManager.get(url, null, res.responseType, {
onComplete: (response: IHttpResponse) => {
res.onComplete(response.data);

View File

@ -47,4 +47,34 @@ export class Utils {
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("&");
}
}