feat: CombManager缓存
This commit is contained in:
parent
10325df72d
commit
5b617a67d5
|
@ -14,23 +14,26 @@ struct Index {
|
||||||
async aboutToAppear() {
|
async aboutToAppear() {
|
||||||
const ver = await CombNetTools.getVer()
|
const ver = await CombNetTools.getVer()
|
||||||
console.log(this.TAG, 'ver', JSON.stringify(ver))
|
console.log(this.TAG, 'ver', JSON.stringify(ver))
|
||||||
const cfg = await CombNetTools.getConfigFile(ver?.full_url ?? '')
|
const cfg = await CombNetTools.getConfigFile(ver?.diff_url ?? '')
|
||||||
console.log(this.TAG, 'full_config', JSON.stringify(cfg))
|
if (cfg) {
|
||||||
|
console.log(this.TAG, 'full_config', 'cfg', JSON.stringify(cfg.data))
|
||||||
|
console.log(this.TAG, 'full_config', 'etag', JSON.stringify(cfg.etag))
|
||||||
|
}
|
||||||
|
|
||||||
// KOnlineParamsUtil.init(getContext())
|
KOnlineParamsUtil.init(getContext())
|
||||||
// KOnlineParamsUtil.requestAsync()
|
KOnlineParamsUtil.requestAsync() // 首次启动拉取数据
|
||||||
// KOnlineParamsUtil.run()
|
KOnlineParamsUtil.run()
|
||||||
//
|
|
||||||
// let time = 1
|
let time = 1
|
||||||
// KOnlineParamsManager.getInstance().registerOnParamsChangeListener(() => {
|
KOnlineParamsManager.registerOnParamsChangeListener(() => {
|
||||||
// console.log(this.TAG, 'CombData is changed! times: ' + time++);
|
console.log(this.TAG, 'CombData is changed! times: ' + time++);
|
||||||
// })
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async getModule(id: string) {
|
async getModule(id: string) {
|
||||||
const begin = Date.now()
|
const begin = Date.now()
|
||||||
|
|
||||||
const modules = await KOnlineParamsManager.getInstance().getProjectConfig().getMaxPriorityModuleFromMG(id)
|
const modules = await KOnlineParamsManager.getParams(id)
|
||||||
if (!modules) return 'not found'
|
if (!modules) return 'not found'
|
||||||
|
|
||||||
console.log(this.TAG, `${modules.getAllParams().length}`);
|
console.log(this.TAG, `${modules.getAllParams().length}`);
|
||||||
|
@ -75,9 +78,7 @@ struct Index {
|
||||||
TextInput({ placeholder: 'input' }).width(200).onChange(value => this.key1 = value)
|
TextInput({ placeholder: 'input' }).width(200).onChange(value => this.key1 = value)
|
||||||
Text(this.value1 === '' ? 'test' : this.value1).width(200)
|
Text(this.value1 === '' ? 'test' : this.value1).width(200)
|
||||||
Button("get").onClick(async () => {
|
Button("get").onClick(async () => {
|
||||||
const mParams = await KOnlineParamsManager.getInstance()
|
const mParams = await KOnlineParamsManager.getParams(this.input)
|
||||||
.getProjectConfig()
|
|
||||||
.getMaxPriorityModuleFromMG(this.input)
|
|
||||||
if (mParams) {
|
if (mParams) {
|
||||||
this.value1 = String(mParams.getValue(this.key1, ''))
|
this.value1 = String(mParams.getValue(this.key1, ''))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { CombConfigManager } from './comb/CombConfigManager'
|
import { CombConfigManager } from './comb/CombConfigManager'
|
||||||
import { KParams } from './comb/KParams'
|
import { KParams } from './comb/KParams'
|
||||||
import { HashMap } from '@kit.ArkTS'
|
|
||||||
|
|
||||||
export type OnParamsChangeListener = () => void
|
export type OnParamsChangeListener = () => void
|
||||||
|
|
||||||
|
@ -28,13 +27,19 @@ export class KOnlineParamsManager {
|
||||||
this.combConfigManager = combConfigManager
|
this.combConfigManager = combConfigManager
|
||||||
}
|
}
|
||||||
|
|
||||||
getProjectConfig(): KParams.ProjectParams {
|
private getProjectConfig(): KParams.ProjectParams {
|
||||||
if (!this.combConfigManager) {
|
if (!this.combConfigManager) {
|
||||||
throw new Error('KOnlineParamsManager not initialized')
|
throw new Error('KOnlineParamsManager not initialized')
|
||||||
}
|
}
|
||||||
return this.combConfigManager.getProjectConfig()
|
return this.combConfigManager.getProjectConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async getParams(groupId: string) {
|
||||||
|
return await KOnlineParamsManager.getInstance()
|
||||||
|
.getProjectConfig()
|
||||||
|
.getMaxPriorityModuleFromMG(groupId)
|
||||||
|
}
|
||||||
|
|
||||||
// 强制拉取
|
// 强制拉取
|
||||||
async requestForce(isDiff: boolean = false) {
|
async requestForce(isDiff: boolean = false) {
|
||||||
await this.combConfigManager?.requestUpdateAsync(isDiff)
|
await this.combConfigManager?.requestUpdateAsync(isDiff)
|
||||||
|
@ -50,15 +55,15 @@ export class KOnlineParamsManager {
|
||||||
this.combConfigManager?.stop()
|
this.combConfigManager?.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册comb更新监听器
|
* 注册comb更新监听器
|
||||||
*/
|
*/
|
||||||
registerOnParamsChangeListener(onParamsChangeListener: OnParamsChangeListener): string {
|
static registerOnParamsChangeListener(onParamsChangeListener: OnParamsChangeListener): string {
|
||||||
return this.combConfigManager?.registerOnDataChangeListener(onParamsChangeListener) ?? ''
|
return KOnlineParamsManager.getInstance()
|
||||||
|
.combConfigManager?.registerOnDataChangeListener(onParamsChangeListener) ?? ''
|
||||||
}
|
}
|
||||||
|
|
||||||
unregisterOnParamsChangeListener(id: string) {
|
static unregisterOnParamsChangeListener(id: string) {
|
||||||
this.combConfigManager?.unregisterOnDataChangeListener(id)
|
KOnlineParamsManager.getInstance().combConfigManager?.unregisterOnDataChangeListener(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { CombDataUpdater } from '../comb_base/CombDataUpdater'
|
||||||
import { CombDataStore } from '../comb_store/CombDataStore'
|
import { CombDataStore } from '../comb_store/CombDataStore'
|
||||||
import { PreferencesStoreCore } from '../comb_store/core/PreferencesStoreCore'
|
import { PreferencesStoreCore } from '../comb_store/core/PreferencesStoreCore'
|
||||||
import { CombConfigManager } from './CombConfigManager'
|
import { CombConfigManager } from './CombConfigManager'
|
||||||
|
import { HashMap } from '@kit.ArkTS'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 多个蜂巢工程管理类
|
* 多个蜂巢工程管理类
|
||||||
|
@ -12,30 +13,36 @@ import { CombConfigManager } from './CombConfigManager'
|
||||||
*/
|
*/
|
||||||
export class CombManager {
|
export class CombManager {
|
||||||
private context: Context
|
private context: Context
|
||||||
|
private combMap: HashMap<number, CombConfigManager>
|
||||||
|
|
||||||
constructor(ctx: Context) {
|
constructor(ctx: Context) {
|
||||||
this.context = ctx
|
this.context = ctx
|
||||||
|
this.combMap = new HashMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
getCombConfigManager(projectID: number = 0) {
|
getCombConfigManager(projectID: number = -1) {
|
||||||
const storeCore = new PreferencesStoreCore(this.context)
|
let combConfigManager = this.combMap.get(projectID)
|
||||||
const combStore = new CombDataStore(this.context, storeCore)
|
if (combConfigManager) return combConfigManager
|
||||||
const combParser = new CombDataParser()
|
|
||||||
const combChecker = new CombDataChecker()
|
const storeCore = new PreferencesStoreCore(this.context) // 存储引擎
|
||||||
const combObserver = new CombDataObserver()
|
const combStore = new CombDataStore({ core: storeCore }) // 本地缓存仓库
|
||||||
|
const combParser = new CombDataParser() // 数据解析器
|
||||||
|
const combChecker = new CombDataChecker() // 数据校验器
|
||||||
|
const combObserver = new CombDataObserver() // 发布订阅器
|
||||||
const combUpdater = new CombDataUpdater({
|
const combUpdater = new CombDataUpdater({
|
||||||
store: combStore,
|
store: combStore,
|
||||||
parser: combParser,
|
parser: combParser,
|
||||||
checker: combChecker,
|
checker: combChecker,
|
||||||
observer: combObserver,
|
observer: combObserver,
|
||||||
})
|
}) // 数据更新器
|
||||||
|
|
||||||
const combConfigManager = new CombConfigManager({
|
combConfigManager = new CombConfigManager({
|
||||||
store: combStore,
|
store: combStore,
|
||||||
updater: combUpdater,
|
updater: combUpdater,
|
||||||
observer: combObserver,
|
observer: combObserver,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.combMap.set(projectID, combConfigManager)
|
||||||
return combConfigManager
|
return combConfigManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,10 @@ export class CombDataUpdater implements ICombUpdater {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getVer() {
|
async getVer() {
|
||||||
const verData = await CombNetTools.getVer()
|
const localVerion = await this.dataStore.getVersion()
|
||||||
|
const verData = await CombNetTools.getVer() // 传递版本号
|
||||||
this.verData = verData
|
this.verData = verData
|
||||||
return verData
|
return verData
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(isDiff: boolean = false) {
|
async update(isDiff: boolean = false) {
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
export namespace CombConfigManager {
|
||||||
|
}
|
|
@ -1,18 +1,22 @@
|
||||||
import { IConfigFileRes, IVerData } from '../comb_type/CombTypes'
|
import { IConfigFileRes, IVerData } from '../comb_type/CombTypes'
|
||||||
import { android_comb_diff_cofig, android_comb_full_config } from '../data/androd_comb_config'
|
|
||||||
import { CombNetUtil } from '../comb_utils/CombNetUtil'
|
import { CombNetUtil } from '../comb_utils/CombNetUtil'
|
||||||
import { CipherUtil } from '../comb_utils/CipherUtil'
|
import { CipherUtil } from '../comb_utils/CipherUtil'
|
||||||
import { CompressUtil } from '../comb_utils/CompressUtil'
|
import { CompressUtil } from '../comb_utils/CompressUtil'
|
||||||
|
|
||||||
export namespace CombNetTools {
|
export namespace CombNetTools {
|
||||||
|
const projectId = 1
|
||||||
|
|
||||||
|
const BASE_URL = `honeycomb.wps.cn/api/v4/project/${projectId}`
|
||||||
|
const VER_URL = BASE_URL + '/ver'
|
||||||
|
const IDS_URL = BASE_URL + '/ids'
|
||||||
|
|
||||||
const projectid = 1
|
|
||||||
const ver = 2700
|
const ver = 2700
|
||||||
const skv = 1665471000
|
const skv = 1665471000
|
||||||
|
|
||||||
const iv = 'aacbcb1b3299ff61'
|
const iv = 'aacbcb1b3299ff61'
|
||||||
const key = '44d81af4045343d3'
|
const key = '44d81af4045343d3'
|
||||||
|
|
||||||
|
|
||||||
async function deData(data: Uint8Array) {
|
async function deData(data: Uint8Array) {
|
||||||
const key_ = await CipherUtil.generateKey(128, key)
|
const key_ = await CipherUtil.generateKey(128, key)
|
||||||
const data_decrypted = await CipherUtil.decrypt(data, key_, 128)
|
const data_decrypted = await CipherUtil.decrypt(data, key_, 128)
|
||||||
|
@ -29,7 +33,7 @@ export namespace CombNetTools {
|
||||||
// headers: {Client-Type: wps-android; Client-Ver: 1; Client-Chann: 1;}
|
// headers: {Client-Type: wps-android; Client-Ver: 1; Client-Chann: 1;}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await CombNetUtil.getVer(projectid, ver, skv)
|
const res = await CombNetUtil.getVer(projectId, ver, skv)
|
||||||
return res
|
return res
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return
|
return
|
||||||
|
|
|
@ -16,17 +16,19 @@ import { HashMap } from '@kit.ArkTS'
|
||||||
import { IDiffConfigFile, IFullConfigFile } from '../comb_type/CombTypes'
|
import { IDiffConfigFile, IFullConfigFile } from '../comb_type/CombTypes'
|
||||||
import { KLog } from '../comb_utils/KLog'
|
import { KLog } from '../comb_utils/KLog'
|
||||||
|
|
||||||
|
interface ICombDataProps {
|
||||||
|
core: ICombStoreCore
|
||||||
|
}
|
||||||
|
|
||||||
export class CombDataStore {
|
export class CombDataStore {
|
||||||
private TAG: string = 'CombDataStore'
|
private TAG: string = 'CombDataStore'
|
||||||
public storeCore: ICombStoreCore
|
public storeCore: ICombStoreCore
|
||||||
private ctx: Context
|
|
||||||
private moduleMap: HashMap<string, KModule>
|
private moduleMap: HashMap<string, KModule>
|
||||||
private static LATEST_REQUEST_TIME_STAMP: string = 'latest_request_time_stamp'
|
private static LATEST_REQUEST_TIME_STAMP: string = 'latest_request_time_stamp'
|
||||||
private static DELAY_UPDATE_TIME: string = 'delay_update_time'
|
private static DELAY_UPDATE_TIME: string = 'delay_update_time'
|
||||||
|
|
||||||
constructor(ctx: Context, storeCore: ICombStoreCore) {
|
constructor(props: ICombDataProps) {
|
||||||
this.ctx = ctx
|
this.storeCore = props.core
|
||||||
this.storeCore = storeCore
|
|
||||||
this.moduleMap = new HashMap()
|
this.moduleMap = new HashMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,12 @@ export interface IDiffModules {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface IVerResponse {
|
||||||
|
code?: number
|
||||||
|
msg?: string
|
||||||
|
data?: IVerData
|
||||||
|
}
|
||||||
|
|
||||||
export interface IVerData {
|
export interface IVerData {
|
||||||
ver: number
|
ver: number
|
||||||
full_url: string
|
full_url: string
|
||||||
|
|
Loading…
Reference in New Issue
Block a user