UNPKG

kitten-cloud-function

Version:

用于编程猫源码云功能(云变量、云列表等)的客户端工具

65 lines (64 loc) 2.54 kB
import { None } from "../../../utils/other"; import { KittenCloudSendMessageType } from "../../network/kitten-cloud-send-message-type"; import { KittenCloudPrivateVariable } from "../kitten-cloud-private-variable"; import { KittenCloudVariableGroup } from "./kitten-cloud-variable-group"; /** * 私有云变量组。 */ export class KittenCloudPrivateVariableGroup extends KittenCloudVariableGroup { constructor(connection) { super(connection, { cacheTime: 100, uploadIntervalTime: 1500 }); this.dataTypeName = "私有云变量"; this.dataUpdateSendMessageType = KittenCloudSendMessageType.UPDATE_PRIVATE_VARIABLE; this.getRankingListArray = []; } sendGetRankingList(variable, message) { this.getRankingListArray.push(variable); this.connection.send(KittenCloudSendMessageType.GET_PRIVATE_VARIABLE_RANKING_LIST, message); } handleReceiveRankingList(data) { const first = this.getRankingListArray.shift(); if (first == None) { throw new Error("没有请求排行榜,却收到了排行榜响应"); } first.handleReceiveRankingList(data); } createData(cvid, name, value) { return new KittenCloudPrivateVariable(this.connection, this, cvid, name, value); } handleCloudUpdate(__cloudMessage) { var _a; try { const firstUploadCount = this.uploadCount.shift(); if (firstUploadCount == None) { throw new Error("不存在上传数据"); } for (let i = 0; i < this.dataArray.length; i++) { for (;;) { const count = firstUploadCount[i]; if (count == None || count <= 0) { break; } (_a = this.dataArray[i]) === null || _a === void 0 ? void 0 : _a.updateManager.handleUploadingSuccess(); firstUploadCount[i] = count - 1; } } } catch (error) { this.handleCloudUpdateError(); } } toUploadMessage(message) { if (!(typeof message == "object" && message != null && "code" in message && "msg" in message)) { throw new Error(`无法识别更新数据格式:${message}`); } if (message.code == 1 && message.msg == "ok") { return {}; } throw new Error(`私有云变量更新失败:${JSON.stringify(message)}`); } }