UNPKG

kitten-cloud-function

Version:

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

69 lines (68 loc) 2.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KittenCloudPrivateVariableGroup = void 0; const other_1 = require("../../../utils/other"); const kitten_cloud_send_message_type_1 = require("../../network/kitten-cloud-send-message-type"); const kitten_cloud_private_variable_1 = require("../kitten-cloud-private-variable"); const kitten_cloud_variable_group_1 = require("./kitten-cloud-variable-group"); /** * 私有云变量组。 */ class KittenCloudPrivateVariableGroup extends kitten_cloud_variable_group_1.KittenCloudVariableGroup { constructor(connection) { super(connection, { cacheTime: 100, uploadIntervalTime: 1500 }); this.dataTypeName = "私有云变量"; this.dataUpdateSendMessageType = kitten_cloud_send_message_type_1.KittenCloudSendMessageType.UPDATE_PRIVATE_VARIABLE; this.getRankingListArray = []; } sendGetRankingList(variable, message) { this.getRankingListArray.push(variable); this.connection.send(kitten_cloud_send_message_type_1.KittenCloudSendMessageType.GET_PRIVATE_VARIABLE_RANKING_LIST, message); } handleReceiveRankingList(data) { const first = this.getRankingListArray.shift(); if (first == other_1.None) { throw new Error("没有请求排行榜,却收到了排行榜响应"); } first.handleReceiveRankingList(data); } createData(cvid, name, value) { return new kitten_cloud_private_variable_1.KittenCloudPrivateVariable(this.connection, this, cvid, name, value); } handleCloudUpdate(__cloudMessage) { var _a; try { const firstUploadCount = this.uploadCount.shift(); if (firstUploadCount == other_1.None) { throw new Error("不存在上传数据"); } for (let i = 0; i < this.dataArray.length; i++) { for (;;) { const count = firstUploadCount[i]; if (count == other_1.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)}`); } } exports.KittenCloudPrivateVariableGroup = KittenCloudPrivateVariableGroup;