kitten-cloud-function
Version:
用于编程猫源码云功能(云变量、云列表等)的客户端工具
1,180 lines (1,164 loc) • 234 kB
JavaScript
/**
* @name 源码云功能
* @author SLIGHTNING
* @version 1.2.0
* @license AGPL-3.0
*/
/******/ (function() { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ 976:
/***/ (function(module, __unused_webpack___webpack_exports__, __webpack_require__) {
// NAMESPACE OBJECT: C:\Users\SLIGHTNING\OneDrive\代码\其他\编程猫\扩展\CoCo 自定义控件\源码云功能\src\wrapper\kitten-cloud-function-package.ts
var C_Users_SLIGHTNING_OneDrive_CoCo_src_wrapper_kitten_cloud_function_package_namespaceObject = {};
__webpack_require__.r(C_Users_SLIGHTNING_OneDrive_CoCo_src_wrapper_kitten_cloud_function_package_namespaceObject);
__webpack_require__.d(C_Users_SLIGHTNING_OneDrive_CoCo_src_wrapper_kitten_cloud_function_package_namespaceObject, {
CodemaoUser: function() { return CodemaoUser; },
CodemaoUserInfo: function() { return CodemaoUserInfo; },
CodemaoUserSex: function() { return CodemaoUserSex; },
CodemaoWork: function() { return CodemaoWork; },
CodemaoWorkEditor: function() { return CodemaoWorkEditor; },
CodemaoWorkInfo: function() { return CodemaoWorkInfo; },
KittenCloudData: function() { return KittenCloudData; },
KittenCloudDataGroup: function() { return KittenCloudDataGroup; },
KittenCloudDataType: function() { return KittenCloudDataType; },
KittenCloudDataUpdateSource: function() { return KittenCloudDataUpdateSource; },
KittenCloudFunction: function() { return KittenCloudFunction; },
KittenCloudFunctionConfigLayer: function() { return KittenCloudFunctionConfigLayer; },
KittenCloudList: function() { return KittenCloudList; },
KittenCloudListGroup: function() { return KittenCloudListGroup; },
KittenCloudOnlineUserNumber: function() { return KittenCloudOnlineUserNumber; },
KittenCloudPrivateVariable: function() { return KittenCloudPrivateVariable; },
KittenCloudPrivateVariableGroup: function() { return KittenCloudPrivateVariableGroup; },
KittenCloudPublicVariable: function() { return KittenCloudPublicVariable; },
KittenCloudPublicVariableGroup: function() { return KittenCloudPublicVariableGroup; },
KittenCloudVariable: function() { return KittenCloudVariable; },
KittenCloudVariableGroup: function() { return KittenCloudVariableGroup; },
Signal: function() { return Signal; },
SingleConfig: function() { return SingleConfig; },
__diff: function() { return __diff; },
getCalibratedTimestamp: function() { return getCalibratedTimestamp; },
getClientID: function() { return getClientID; },
getCurrentTime: function() { return getCurrentTime; },
getKittenNWorkPublicResource: function() { return getKittenNWorkPublicResource; },
getKittenWorkPublicResource: function() { return getKittenWorkPublicResource; },
getNemoWorkPublicResource: function() { return getNemoWorkPublicResource; },
getSignUUID: function() { return getSignUUID; },
getThisUserDetail: function() { return getThisUserDetail; },
getTimeDifference: function() { return getTimeDifference; },
getUserDetail: function() { return getUserDetail; },
getUserHonor: function() { return getUserHonor; },
getUserProfile: function() { return getUserProfile; },
getWorkDetail: function() { return getWorkDetail; },
getWorkInfo: function() { return getWorkInfo; },
setXCreationToolsDeviceAuth: function() { return setXCreationToolsDeviceAuth; }
});
;// C:\Users\SLIGHTNING\OneDrive\代码\其他\编程猫\扩展\CoCo 自定义控件\源码云功能\src\utils\other.ts
const None = null;
function equal(a, b) {
if (a === b) {
return true;
}
if (a && b && typeof a == "object" && typeof b == "object") {
if (a.constructor != b.constructor) {
return false;
}
if (Array.isArray(a)) {
if (a.length != b.length) {
return false;
}
for (let i = 0; i < a.length; i++) {
if (!equal(a[i], b[i])) {
return false;
}
}
return true;
}
let keys = Object.keys(a);
if (keys.length != Object.keys(b).length) {
return false;
}
for (const key of keys) {
if (!(key in b) || !equal(a[key], b[key])) {
return false;
}
}
return true;
}
return false;
}
function merge(target, source) {
for (const key in source) {
if (typeof source[key] == "object" && source[key] != None) {
if (!(key in target)) {
target[key] = {};
}
if (typeof target[key] == "object" && target[key] != None) {
merge(target[key], source[key]);
}
} else if (!(key in target)) {
target[key] = source[key];
}
}
return target;
}
function enumerable(value) {
return function (__target, __propertyKey, descriptor) {
descriptor.enumerable = value;
};
}
const NUMBER_CHAR = "0123456789",
LOWER_CASE_LETTER = "abcdefghijklmnopqrstuvwxyz",
UPPER_CASE_LETTER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
LETTER = LOWER_CASE_LETTER.concat(UPPER_CASE_LETTER);
function randomString(length = 32, charset = NUMBER_CHAR.concat(LETTER)) {
let result = "";
for (let i = 0; i < length; i++) {
result += charset[Math.floor(Math.random() * charset.length)];
}
return result;
}
;// C:\Users\SLIGHTNING\OneDrive\代码\其他\编程猫\扩展\CoCo 自定义控件\源码云功能\src\codemao\codemao-environment.ts
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
const isNode = typeof void 0 == "object";
const isBrowser = typeof window == "object";
const isCodemaoWindow = isBrowser && location.hostname.endsWith("codemao.cn");
const dirs = isNode ? Object(function webpackMissingModule() { var e = new Error("Cannot find module 'appdirsjs'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())({
appName: "SLIGHTNING/Codemao-Community"
}) : null;
async function getAuthorization() {
if (dirs == null) {
throw new Error("当前环境不支持该方法");
}
try {
return String(await (await Promise.resolve().then(function webpackMissingModule() { var e = new Error("Cannot find module 'fs'"); e.code = 'MODULE_NOT_FOUND'; throw e; })).promises.readFile((await Promise.resolve().then(function webpackMissingModule() { var e = new Error("Cannot find module 'path'"); e.code = 'MODULE_NOT_FOUND'; throw e; })).resolve(dirs.config, "authorization.txt")));
} catch (error) {
if (error instanceof Error && "code" in error && error.code == "ENOENT") {
return null;
} else {
throw error;
}
}
}
let codemaoIFrameElement = null;
let codemaoWindow = null;
function getCodemaoIFrameElement() {
return codemaoIFrameElement;
}
function getCodemaoWindow() {
if (codemaoWindow != null) {
return codemaoWindow;
}
return codemaoWindow = new Promise((resolve, reject) => {
function startListen(codemaoWindow) {
if (codemaoWindow == null) {
reject(new Error("编程猫环境服务连接失败:窗口为空"));
return;
}
function listener(event) {
const {
data
} = event;
if (data == null || typeof data != "object") {
return;
}
if (/^https?:\/\/coco\.codemao\.cn$/.test(event.origin) && data.type == "COCO_CODEMAO_ENVIRONMENT_SERVER_INIT") {
window.removeEventListener("message", listener);
resolve(codemaoWindow);
}
}
window.addEventListener("message", listener);
codemaoWindow.addEventListener("beforeunload", () => {
codemaoIFrameElement = null;
codemaoWindow = null;
reject(new Error("编程猫环境服务连接失败:窗口已被关闭"));
});
window.addEventListener("beforeunload", () => {
var _codemaoWindow;
(_codemaoWindow = codemaoWindow) === null || _codemaoWindow === void 0 || _codemaoWindow.close();
codemaoIFrameElement = null;
codemaoWindow = null;
});
}
if (location.protocol == "file:") {
codemaoIFrameElement = document.createElement("iframe");
codemaoIFrameElement.src = "https://coco.codemao.cn/editor/player/255051613?channel=h5";
codemaoIFrameElement.style.display = "none";
document.body.appendChild(codemaoIFrameElement);
startListen(codemaoIFrameElement.contentWindow);
} else {
const buttonElement = document.createElement("div");
buttonElement.innerText = "点击打开编程猫环境服务\n打开后请不要关闭编程猫环境服务页面";
buttonElement.style.width = "100%";
buttonElement.style.height = "100%";
buttonElement.style.fontSize = "2em";
buttonElement.style.position = "fixed";
buttonElement.style.left = "0px";
buttonElement.style.top = "0px";
buttonElement.style.right = "0px";
buttonElement.style.bottom = "0px";
buttonElement.style.backgroundColor = "white";
buttonElement.style.cursor = "pointer";
buttonElement.style.zIndex = "10000";
buttonElement.addEventListener("click", () => {
startListen(open("https://coco.codemao.cn/editor/player/255051613?channel=h5"));
buttonElement.remove();
});
document.body.appendChild(buttonElement);
}
});
}
const CoCoCodemaoEnvironmentServerAxiosIDSet = new Set();
async function CoCoCodemaoEnvironmentServerAxios(argument) {
let id;
do {
id = Math.floor(Math.random() * 90000000) + 10000000;
} while (CoCoCodemaoEnvironmentServerAxiosIDSet.has(id));
CoCoCodemaoEnvironmentServerAxiosIDSet.add(id);
return new Promise((resolve, reject) => {
function listener(event) {
const {
data
} = event;
if (data == null || typeof data != "object") {
return;
}
if (data.type == "CODEMAO_ENVIRONMENT_AXIOS_RESULT" && data.id == id) {
CoCoCodemaoEnvironmentServerAxiosIDSet.delete(id);
window.removeEventListener("message", listener);
if (data.success) {
resolve(data.response);
} else {
reject(data.error);
}
}
}
window.addEventListener("message", listener);
getCodemaoWindow().then(codemaoWindow => {
codemaoWindow.postMessage({
type: "CODEMAO_ENVIRONMENT_AXIOS",
id,
argument
}, "https://coco.codemao.cn");
}).catch(reject);
});
}
const CoCoCodemaoEnvironmentServerWebSocketIDSet = new Set();
class CoCoCodemaoEnvironmentServerWebSocket {
constructor(url) {
_defineProperty(this, "url", void 0);
_defineProperty(this, "id", void 0);
this.url = url;
do {
this.id = Math.floor(Math.random() * 90000000) + 10000000;
} while (CoCoCodemaoEnvironmentServerWebSocketIDSet.has(this.id));
CoCoCodemaoEnvironmentServerWebSocketIDSet.add(this.id);
const listener = event => {
const {
data
} = event;
if (data == null || typeof data != "object") {
return;
}
if (data.type == "CODEMAO_ENVIRONMENT_WEB_SOCKET_OPEN" && data.id == this.id) {
this.onopen(data.event);
}
if (data.type == "CODEMAO_ENVIRONMENT_WEB_SOCKET_MESSAGE" && data.id == this.id) {
this.onmessage(data.event);
}
if (data.type == "CODEMAO_ENVIRONMENT_WEB_SOCKET_CLOSE" && data.id == this.id) {
this.onclose(data.event);
CoCoCodemaoEnvironmentServerWebSocketIDSet.delete(this.id);
window.removeEventListener("message", listener);
}
if (data.type == "CODEMAO_ENVIRONMENT_WEB_SOCKET_ERROR" && data.id == this.id) {
var _data$error;
this.onerror((_data$error = data.error) !== null && _data$error !== void 0 ? _data$error : data.event);
}
};
window.addEventListener("message", listener);
getCodemaoWindow().then(codemaoWindow => {
codemaoWindow.postMessage({
type: "CODEMAO_ENVIRONMENT_WEB_SOCKET",
id: this.id,
url
}, "https://coco.codemao.cn");
}).catch(this.onerror);
}
send(data) {
getCodemaoWindow().then(codemaoWindow => {
codemaoWindow.postMessage({
type: "CODEMAO_ENVIRONMENT_WEB_SOCKET_SEND",
id: this.id,
data
}, "https://coco.codemao.cn");
}).catch(this.onerror);
}
close() {
getCodemaoWindow().then(codemaoWindow => {
codemaoWindow.postMessage({
type: "CODEMAO_ENVIRONMENT_WEB_SOCKET_CLOSE",
id: this.id
}, "https://coco.codemao.cn");
}).catch(this.onerror);
}
onopen(__event) {}
onmessage(__event) {}
onclose(__event) {}
onerror(__event) {}
}
const CodemaoLocalStorage = (() => {
if (isNode) {
return new class CodemaoLocalStorage {
constructor() {
_defineProperty(this, "filePath", void 0);
_defineProperty(this, "store", void 0);
this.filePath = Object(function webpackMissingModule() { var e = new Error("Cannot find module 'path'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(dirs.config, "local-storage.json");
try {
this.store = JSON.parse(String(Object(function webpackMissingModule() { var e = new Error("Cannot find module 'fs'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(this.filePath)));
} catch (error) {
if (error instanceof Error && "code" in error && error.code == "ENOENT") {
this.store = {};
} else {
throw error;
}
}
}
save() {
(async () => {
(await Promise.resolve().then(function webpackMissingModule() { var e = new Error("Cannot find module 'fs'"); e.code = 'MODULE_NOT_FOUND'; throw e; })).promises.writeFile(this.filePath, JSON.stringify(this.store));
})();
}
get length() {
return Object.keys(this.store).length;
}
clear() {
this.store = {};
this.save();
}
getItem(key) {
var _this$store$key;
return (_this$store$key = this.store[key]) !== null && _this$store$key !== void 0 ? _this$store$key : null;
}
key(index) {
var _Object$values$index;
return (_Object$values$index = Object.values(this.store)[index]) !== null && _Object$values$index !== void 0 ? _Object$values$index : null;
}
removeItem(key) {
delete this.store[key];
this.save();
}
setItem(key, value) {
this.store[key] = value;
this.save();
}
}();
} else if (isBrowser) {
return localStorage;
} else {
throw new Error("未知的运行平台");
}
})();
async function CodemaoAxios(argument) {
const axios = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 719, 23));
const axiosDefault = isNode || isCodemaoWindow ? axios.default : CoCoCodemaoEnvironmentServerAxios;
if (isNode && argument.withCredentials) {
const authorization = await getAuthorization();
if (authorization != null) {
var _argument$headers, _argument$headers2, _Cookie, _argument$headers2$_C;
(_argument$headers = argument.headers) !== null && _argument$headers !== void 0 ? _argument$headers : argument.headers = {};
(_argument$headers2$_C = (_argument$headers2 = argument.headers)[_Cookie = "Cookie"]) !== null && _argument$headers2$_C !== void 0 ? _argument$headers2$_C : _argument$headers2[_Cookie] = "";
argument.headers["Cookie"] += `Authorization=${authorization};`;
}
}
const response = await axiosDefault(argument);
let {
data
} = response;
if (data != null && typeof data == "object" && "status" in data && typeof data.status == "number" && "text" in data && typeof data.text == "string") {
data = JSON.parse(data.text);
}
if (data != null && typeof data == "object" && "code" in data && typeof data.code == "number" && "msg" in data && typeof data.msg == "string" && "data" in data) {
if (data.code != 200) {
throw new axios.AxiosError(data.msg, data.code.toString(), response.config, response.request, response);
}
return data.data;
}
return data;
}
async function CodemaoWebSocket(url) {
if (isNode) {
const WebSocket = (await Promise.resolve().then(function webpackMissingModule() { var e = new Error("Cannot find module 'websocket'"); e.code = 'MODULE_NOT_FOUND'; throw e; })).w3cwebsocket;
const authorization = await getAuthorization();
if (authorization == null) {
return new WebSocket(url);
} else {
return new WebSocket(url, undefined, undefined, {
Cookie: `Authorization=${authorization};`
});
}
} else if (isCodemaoWindow) {
return new WebSocket(url);
} else if (isBrowser) {
return new CoCoCodemaoEnvironmentServerWebSocket(url);
} else {
throw new Error("未知的运行平台");
}
}
;// C:\Users\SLIGHTNING\OneDrive\代码\其他\编程猫\扩展\CoCo 自定义控件\源码云功能\src\codemao\codemao-community-api.ts
/**
* https://api.codemao.cn/coconut/clouddb/currentTime
*/
async function getCurrentTime() {
return CodemaoAxios({
method: "GET",
url: "https://api.codemao.cn/coconut/clouddb/currentTime"
});
}
let timeDifference = null;
/**
* 获取本地时间与 {@link getCurrentTime} 的差异
*/
async function getTimeDifference() {
if (timeDifference == null) {
timeDifference = Math.round(Date.now() / 1000) - (await getCurrentTime());
}
return timeDifference;
}
/**
* 获取通过 {@link getTimeDifference} 校准过的时间戳
*/
async function getCalibratedTimestamp() {
return Math.round(Date.now() / 1000) - (await getTimeDifference());
}
function getSignUUID() {
var _CodemaoLocalStorage$;
let signUUID = (_CodemaoLocalStorage$ = CodemaoLocalStorage.getItem("sign_uuid")) !== null && _CodemaoLocalStorage$ !== void 0 ? _CodemaoLocalStorage$ : randomString(8, NUMBER_CHAR.concat(LOWER_CASE_LETTER));
CodemaoLocalStorage.setItem("sign_uuid", signUUID);
return signUUID;
}
function getClientID() {
return getSignUUID();
}
async function setXCreationToolsDeviceAuth(argument) {
var _argument$headers;
let timestamp = await getCalibratedTimestamp();
let clientID = getClientID();
(_argument$headers = argument.headers) !== null && _argument$headers !== void 0 ? _argument$headers : argument.headers = {};
argument.headers["X-Creation-Tools-Device-Auth"] = JSON.stringify({
sign: (await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 846, 23))).SHA256("pBlYqXbJDu" + timestamp + clientID).toString().toLocaleUpperCase(),
timestamp,
client_id: clientID
});
return argument;
}
/**
* https://api.codemao.cn/tiger/v3/web/accounts/profile
*
* @param authorization 用户凭证,留空则使用默认 Cookie
*
* @returns 用户信息
*/
async function getUserProfile(authorization) {
const headers = authorization == null ? {} : {
Cookie: `Authorization=${authorization}`
};
return CodemaoAxios({
method: "GET",
url: "https://api.codemao.cn/tiger/v3/web/accounts/profile",
withCredentials: true,
headers
});
}
/**
* https://api.codemao.cn/web/users/details
*
* 用户被封号时该 API 不可用。
*
* @param authorization 用户凭证,留空则使用默认 Cookie
*/
function getThisUserDetail(authorization) {
const headers = authorization == null ? {} : {
Cookie: `Authorization=${authorization}`
};
return CodemaoAxios({
method: "GET",
url: "https://api.codemao.cn/web/users/details",
withCredentials: true,
headers
});
}
/**
* https://api.codemao.cn/api/user/info/detail/${userID}
*/
async function getUserDetail(userID) {
return (await CodemaoAxios({
method: "GET",
url: `https://api.codemao.cn/api/user/info/detail/${userID}`,
withCredentials: true
})).userInfo;
}
/**
* https://api.codemao.cn/creation-tools/v1/user/center/honor?user_id=${userID}
*/
function getUserHonor(userID) {
return CodemaoAxios({
method: "GET",
url: `https://api.codemao.cn/creation-tools/v1/user/center/honor?user_id=${userID}`
});
}
/**
* https://api.codemao.cn/creation-tools/v1/works/${workID}
*/
function getWorkInfo(workID) {
return CodemaoAxios({
method: "GET",
url: `https://api.codemao.cn/creation-tools/v1/works/${workID}`
});
}
/**
* https://api.codemao.cn/api/work/info/${workID}
*/
async function getWorkDetail(workID) {
return (await CodemaoAxios({
method: "GET",
url: `https://api.codemao.cn/api/work/info/${workID}`
})).workDetail;
}
/**
* https://api.codemao.cn/creation-tools/v1/works/${workID}/source/public
*/
function getNemoWorkPublicResource(workID) {
return CodemaoAxios({
method: "GET",
url: `https://api.codemao.cn/creation-tools/v1/works/${workID}/source/public`
});
}
/**
* https://api-creation.codemao.cn/kitten/r2/work/player/load/${workID}
*/
function getKittenWorkPublicResource(workID) {
return CodemaoAxios({
method: "GET",
url: `https://api-creation.codemao.cn/kitten/r2/work/player/load/${workID}`
});
}
/**
* https://api-creation.codemao.cn/neko/community/player/published-work-detail/${workID}
*/
async function getKittenNWorkPublicResource(workID) {
return CodemaoAxios(await setXCreationToolsDeviceAuth({
method: "GET",
url: `https://api-creation.codemao.cn/neko/community/player/published-work-detail/${workID}`
}));
}
;// C:\Users\SLIGHTNING\OneDrive\代码\其他\编程猫\扩展\CoCo 自定义控件\源码云功能\node_modules\@ungap\promise-any\esm\index.js
var any = (Promise.any || function ($) {
return new Promise(function (D, E, A, L) {
A = [];
L = $.map(function ($, i) {
return Promise.resolve($).then(D, function (O) {
return ((A[i] = O), --L) || E({errors: A});
});
}).length;
});
}).bind(Promise);
/* harmony default export */ const C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index = (any);
;// C:\Users\SLIGHTNING\OneDrive\代码\其他\编程猫\扩展\CoCo 自定义控件\源码云功能\src\codemao\user\codemao-user-sex.ts
var _CodemaoUserSex;
function C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_sex_defineProperty(e, r, t) { return (r = C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_sex_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_sex_toPropertyKey(t) { var i = C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_sex_toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_sex_toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/** 用户性别。*/class CodemaoUserSex {
static from(argument) {
if (argument instanceof CodemaoUserSex) {
return argument;
}
return CodemaoUserSex.parse(argument);
}
static parse(type) {
if (typeof type == "number") {
type = type.toString();
}
type = type.toUpperCase();
if (!(type in sexMap)) {
throw new Error(`无法识别的用户性别:${type}`);
}
return sexMap[type];
}
/** 用户性别名称。*/
constructor(name) {
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_sex_defineProperty(this, "name", void 0);
/** 用户性别符号。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_sex_defineProperty(this, "symbol", void 0);
this.name = name;
this.symbol = Symbol(name);
}
toString() {
return this.name;
}
}
_CodemaoUserSex = CodemaoUserSex;
/** 男性。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_sex_defineProperty(CodemaoUserSex, "MALE", new _CodemaoUserSex("男"));
/** 女性。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_sex_defineProperty(CodemaoUserSex, "FEMALE", new _CodemaoUserSex("女"));
const sexMap = {
"1": CodemaoUserSex.MALE,
"MALE": CodemaoUserSex.MALE,
"0": CodemaoUserSex.FEMALE,
"FEMALE": CodemaoUserSex.FEMALE
};
;// C:\Users\SLIGHTNING\OneDrive\代码\其他\编程猫\扩展\CoCo 自定义控件\源码云功能\src\codemao\user\codemao-user-badge.ts
var _CodemaoUserBadge;
function C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(e, r, t) { return (r = C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_toPropertyKey(t) { var i = C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/** 编程猫用户创作者等级。*/class CodemaoUserBadge {
static from(value) {
if (value instanceof CodemaoUserBadge) {
return value;
}
return CodemaoUserBadge.parse(value);
}
static parse(value) {
if (!(value in badgeMap)) {
throw new Error(`无法识别的创作者勋章:${value}`);
}
return badgeMap[value];
}
constructor({
name,
shortName,
color,
description,
imageURL,
shortImageURL,
iconURL
}) {
/** 用户勋章名称。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(this, "name", void 0);
/** 用户勋章短名称。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(this, "shortName", void 0);
/** 用户勋章颜色。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(this, "color", void 0);
/** 用户勋章描述。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(this, "description", void 0);
/** 用户勋章图像链接。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(this, "imageURL", void 0);
/** 用户勋章短图像链接。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(this, "shortImageURL", void 0);
/** 用户勋章图标链接。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(this, "iconURL", void 0);
/** 用户勋章符号。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(this, "symbol", void 0);
this.name = name;
this.shortName = shortName !== null && shortName !== void 0 ? shortName : name;
this.color = color;
this.description = description;
this.imageURL = imageURL;
this.shortImageURL = shortImageURL;
this.iconURL = iconURL;
this.symbol = Symbol(description);
}
}
_CodemaoUserBadge = CodemaoUserBadge;
/** 准创作者。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(CodemaoUserBadge, "QUASI_CREATOR", new _CodemaoUserBadge({
name: "准创作者"
}));
/** 积木小白。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(CodemaoUserBadge, "BLOCK_BEGINNER", new _CodemaoUserBadge({
name: "积木小白",
shortName: "小白"
}));
/** ⭐ 潜力新星。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(CodemaoUserBadge, "PROMISING_NEW_STAR", new _CodemaoUserBadge({
name: "⭐ 潜力新星",
shortName: "⭐ 新星",
color: "#35699F",
description: "恭喜你在源码世界中崭露头角\n加油,未来可期",
imageURL: "https://cdn-community.codemao.cn/community_frontend/asset/badge1_6c95b.png",
shortImageURL: "https://cdn-community.codemao.cn/community_frontend/asset/badge1-lite_7b1a1.png",
iconURL: "https://cdn-community.codemao.cn/community_frontend/asset/step_1_a2963.png"
}));
/** 💎 进阶高手。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(CodemaoUserBadge, "ADVANCED_MASTER", new _CodemaoUserBadge({
name: "💎 进阶高手",
shortName: "💎 高手",
color: "#206ACB",
description: "领先源码世界90%的创作者\n拥有卓尔不凡的编程水平",
imageURL: "https://cdn-community.codemao.cn/community_frontend/asset/badge2_92044.png",
shortImageURL: "https://cdn-community.codemao.cn/community_frontend/asset/badge2-lite_ad3f7.png",
iconURL: "https://cdn-community.codemao.cn/community_frontend/asset/step_2_ef50a.png"
}));
/** 👑 编程大佬。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(CodemaoUserBadge, "PROGRAMMING_BIG_SHOT", new _CodemaoUserBadge({
name: "👑 编程大佬",
shortName: "👑 大佬",
color: "#DA6627",
description: "领先源码世界99%的创作者\n拥有出神入化的编程水平",
imageURL: "https://cdn-community.codemao.cn/community_frontend/asset/badge3_09b3a.png",
shortImageURL: "https://cdn-community.codemao.cn/community_frontend/asset/dalao_13224.gif",
iconURL: "https://cdn-community.codemao.cn/community_frontend/asset/step_3_11280.png"
}));
/** 👑 源码传说。*/
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_badge_defineProperty(CodemaoUserBadge, "CODE_LEGEND", new _CodemaoUserBadge({
name: "👑 源码传说",
shortName: "👑 传说",
color: "#9F3DCF",
description: "源码世界巅峰\n传说级别人物",
imageURL: "https://cdn-community.codemao.cn/community_frontend/asset/badge4_3d2da.png",
shortImageURL: "https://cdn-community.codemao.cn/community_frontend/asset/chuanshuo_8a57e.gif",
iconURL: "https://cdn-community.codemao.cn/community_frontend/asset/step_4_4a172.png"
}));
const badgeMap = {
0: CodemaoUserBadge.QUASI_CREATOR,
1: CodemaoUserBadge.BLOCK_BEGINNER,
2: CodemaoUserBadge.PROMISING_NEW_STAR,
3: CodemaoUserBadge.ADVANCED_MASTER,
4: CodemaoUserBadge.PROGRAMMING_BIG_SHOT,
5: CodemaoUserBadge.CODE_LEGEND
};
;// C:\Users\SLIGHTNING\OneDrive\代码\其他\编程猫\扩展\CoCo 自定义控件\源码云功能\src\codemao\user\codemao-user-info.ts
function C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(e, r, t) { return (r = C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_toPropertyKey(t) { var i = C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var __decorate = undefined && undefined.__decorate || function (decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
/**
* 编程猫用户信息类。
*
* - 用于获取编程猫用户信息。
* - 所有属性均为`Promise`对象,当属性获取失败时访问该属性的值会被拒绝。
*
* 提供的用户信息详见类属性。
*
* ### 具有以下特性:
* - 集成多个API接口,以确保在部分API接口信息获取失败时仍能提供尽可能完整的用户信息。
* - 内置懒加载和缓存机制,以减少不必要的请求。
*
* ### 集成API接口
*
* #### 已经集成的API接口
* - {@link getUserProfile}
* - {@link getThisUserDetail}
* - {@link getUserDetail}
* - {@link getUserHonor}
*
* #### 将来可能集成的API接口:
* - {@link searchUserByName}
*
* #### API优先级:
* {@link getUserProfile} > {@link getThisUserDetail} > {@link getUserDetail} > {@link getUserHonor}
*/
class CodemaoUserInfo {
get profile() {
return (async () => {
if (this.__profile == null) {
Object.defineProperty(this, "__profile", {
value: (async () => {
const profile = await getUserProfile(await this.authorization);
return {
id: profile.id,
nickname: profile.nickname,
avatarURL: profile.avatar_url,
description: profile.description,
grade: profile.grade,
birthday: new Date(profile.birthday * 1000)
};
})(),
enumerable: false,
configurable: true
});
this.setCache(await this.__profile);
}
return this.__profile;
})();
}
get thisDetail() {
return (async () => {
if (this.__thisDetail == null) {
Object.defineProperty(this, "__thisDetail", {
value: (async () => {
const userDetail = await getThisUserDetail(await this.authorization);
return {
id: parseInt(userDetail.id),
username: userDetail.username,
nickname: userDetail.nickname,
realname: userDetail.real_name,
avatarURL: userDetail.avatar_url,
description: userDetail.description,
email: userDetail.email,
badge: CodemaoUserBadge.parse(userDetail.author_level),
birthday: new Date(userDetail.birthday * 1000),
sex: CodemaoUserSex.from(userDetail.sex)
};
})(),
enumerable: false,
configurable: true
});
this.setCache(await this.__thisDetail);
}
return this.__thisDetail;
})();
}
get detail() {
return (async () => {
if (this.__detail == null) {
Object.defineProperty(this, "__detail", {
value: (async () => {
const userDetail = await getUserDetail(await this.id);
return {
id: userDetail.user.id,
nickname: userDetail.user.nickname,
avatarURL: userDetail.user.avatar,
description: userDetail.user.description,
doing: userDetail.user.doing,
sex: CodemaoUserSex.from(userDetail.user.sex),
viewTimes: userDetail.viewTimes,
praiseTimes: userDetail.praiseTimes,
forkTimes: userDetail.forkedTimes
};
})(),
enumerable: false,
configurable: true
});
this.setCache(await this.__detail);
}
return this.__detail;
})();
}
get honor() {
return (async () => {
if (this.__honor == null) {
Object.defineProperty(this, "__honor", {
value: (async () => {
const honor = await getUserHonor(await this.id);
return {
id: honor.user_id,
nickname: honor.nickname,
avatarURL: honor.avatar_url,
coverURL: honor.user_cover,
description: honor.user_description,
doing: honor.doing,
badge: CodemaoUserBadge.parse(honor.author_level),
viewTimes: honor.view_times,
praiseTimes: honor.liked_total,
collectTimes: honor.collect_times,
forkTimes: honor.re_created_total
};
})(),
enumerable: false,
configurable: true
});
this.setCache(await this.__honor);
}
return this.__honor;
})();
}
/**
* 身份信息。
*/
get authorization() {
if (this.__authorization == null) {
this.__authorization = Promise.reject(new Error("没有提供身份信息"));
}
return this.__authorization.catch(error => Promise.reject(["获取用户身份信息失败", error]));
}
/**
* 用户ID。
*/
get id() {
if (this.__id == null) {
this.__id = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户ID")), this.profile.catch(error0 => this.thisDetail.catch(error1 => Promise.reject([error0, error1]))).then(info => info.id)]).catch(({
errors
}) => Promise.reject(["获取用户ID失败", errors[0], ...errors[1]]));
}
return this.__id;
}
/**
* 用户名,用户名可以用于登录编程猫账号。如果用户没有设置用户名,则返回空字符串。
*/
get username() {
if (this.__username == null) {
this.__username = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户名")), this.thisDetail.then(info => info.username)]).catch(({
errors
}) => Promise.reject(["获取用户名失败", ...errors]));
}
return this.__username;
}
/**
* 用户昵称。
*/
get nickname() {
if (this.__nickname == null) {
this.__nickname = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户昵称")), this.profile.catch(error0 => this.thisDetail.catch(error1 => this.detail.catch(error2 => this.honor.catch(error3 => Promise.reject([error0, error1, error2, error3]))))).then(info => info.nickname)]).catch(({
errors
}) => Promise.reject(["获取用户昵称失败", errors[0], ...errors[1]]));
}
return this.__nickname;
}
/**
* 用户真实姓名。如果用户没有填写真实姓名,则返回空字符串。
*/
get realname() {
if (this.__realname == null) {
this.__realname = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户真实姓名")), this.thisDetail.then(info => info.realname)]).catch(({
errors
}) => Promise.reject(["获取用户真实姓名失败", ...errors]));
}
return this.__realname;
}
/**
* 用户头像地址。
*/
get avatarURL() {
if (this.__avatarURL == null) {
this.__avatarURL = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户头像地址")), this.profile.catch(error0 => this.thisDetail.catch(error1 => this.detail.catch(error2 => this.honor.catch(error3 => Promise.reject([error0, error1, error2, error3]))))).then(info => info.avatarURL)]).catch(({
errors
}) => Promise.reject(["获取用户头像地址失败", errors[0], ...errors[1]]));
}
return this.__avatarURL;
}
/**
* 用户背景图片地址。
*/
get coverURL() {
if (this.__coverURL == null) {
this.__coverURL = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户背景图片地址")), this.honor.then(info => info.coverURL)]).catch(({
errors
}) => Promise.reject(["获取用户背景图片地址失败", ...errors]));
}
return this.__coverURL;
}
/**
* 用户描述。
*/
get description() {
if (this.__description == null) {
this.__description = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户描述")), this.profile.catch(error0 => this.thisDetail.catch(error1 => this.detail.catch(error2 => this.honor.catch(error3 => Promise.reject([error0, error1, error2, error3]))))).then(info => info.description)]).catch(({
errors
}) => Promise.reject(["获取用户描述失败", errors[0], ...errors[1]]));
}
return this.__description;
}
/**
* 用户正在做什么。
*/
get doing() {
if (this.__doing == null) {
this.__doing = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户正在做什么")), this.detail.then(info => info.doing)]).catch(({
errors
}) => Promise.reject(["获取用户正在做什么失败", ...errors]));
}
return this.__doing;
}
/**
* 用户邮箱地址。
*/
get email() {
if (this.__email == null) {
this.__email = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户邮箱")), this.thisDetail.then(info => info.email)]).catch(({
errors
}) => Promise.reject(["获取用户邮箱失败", ...errors]));
}
return this.__email;
}
/**
* 用户创作者勋章。
*/
get badge() {
if (this.__badge == null) {
this.__badge = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户创作者勋章")), this.thisDetail.catch(error0 => this.honor.catch(error1 => Promise.reject([error0, error1]))).then(info => info.badge)]).catch(({
errors
}) => Promise.reject(["获取用户创作者勋章", errors[0], ...errors[1]]));
}
return this.__badge;
}
/**
* 用户等级。
*/
get grade() {
if (this.__grade == null) {
this.__grade = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户等级")), this.profile.then(info => info.grade)]).catch(({
errors
}) => Promise.reject(["获取用户等级失败", ...errors]));
}
return this.__grade;
}
/**
* 用户生日。
*/
get birthday() {
if (this.__birthday == null) {
this.__birthday = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户生日")), this.profile.catch(error0 => this.thisDetail.catch(error1 => Promise.reject([error0, error1]))).then(info => info.birthday)]).catch(({
errors
}) => Promise.reject(["获取用户生日失败", errors[0], ...errors[1]]));
}
return this.__birthday;
}
/**
* 用户性别。详见 {@link CodemaoUserSex}。
*/
get sex() {
if (this.__sex == null) {
this.__sex = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户性别")), this.thisDetail.catch(error0 => this.detail.catch(error1 => Promise.reject([error0, error1]))).then(info => info.sex)]).catch(({
errors
}) => Promise.reject(["获取用户性别失败", errors[0], ...errors[1]]));
}
return this.__sex;
}
/**
* 用户所有作品被浏览的次数总和。
*/
get viewTimes() {
if (this.__viewTimes == null) {
this.__viewTimes = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户被浏览次数")), this.detail.catch(error0 => this.honor.catch(error1 => Promise.reject([error0, error1]))).then(info => info.viewTimes)]).catch(({
errors
}) => Promise.reject(["获取用户被浏览次数失败", errors[0], ...errors[1]]));
}
return this.__viewTimes;
}
/**
* 用户所有作品被点赞的次数总和。
*/
get praiseTimes() {
if (this.__praiseTimes == null) {
this.__praiseTimes = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户被点赞次数")), this.detail.catch(error0 => this.honor.catch(error1 => Promise.reject([error0, error1]))).then(info => info.praiseTimes)]).catch(({
errors
}) => Promise.reject(["获取用户被点赞次数失败", errors[0], ...errors[1]]));
}
return this.__praiseTimes;
}
/**
* 用户所有作品被收藏的次数总和。
*/
get collectTimes() {
if (this.__collectTimes == null) {
this.__collectTimes = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户被收藏次数")), this.honor.then(info => info.collectTimes)]).catch(({
errors
}) => Promise.reject(["获取用户被收藏次数失败", ...errors]));
}
return this.__collectTimes;
}
/**
* 用户所有作品被再创作的次数总和。
*/
get forkTimes() {
if (this.__forkTimes == null) {
this.__forkTimes = C_Users_SLIGHTNING_OneDrive_CoCo_node_modules_ungap_promise_any_esm_index([Promise.reject(new Error("没有提供用户被再创作次数")), this.honor.catch(error0 => this.detail.catch(error1 => Promise.reject([error0, error1]))).then(info => info.forkTimes)]).catch(({
errors
}) => Promise.reject(["获取用户被再创作次数失败", errors[0], ...errors[1]]));
}
return this.__forkTimes;
}
/**
* @param info 已知的用户信息,如果什么信息都不提供,则表示表示当前登录的用户。
*/
constructor(info) {
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__profile", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__thisDetail", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__detail", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__honor", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__authorization", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__id", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__username", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__nickname", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__realname", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__avatarURL", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__coverURL", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__description", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__doing", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__email", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__badge", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__grade", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__birthday", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__sex", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__viewTimes", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__praiseTimes", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__collectTimes", void 0);
C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_info_defineProperty(this, "__forkTimes", void 0);
for (const key in this) {
if (key.startsWith("__") && this[key] == Node) {
Object.defineProperty(this, key, {
value: undefined,
enumerable: false,
configurable: true
});
}
}
if (Object.keys(info).length == 0) {
this.__authorization = Promise.resolve(null);
} else {
this.setCache(info);
}
}
setCache(info) {
for (let key in info) {
let value = info[key];
if (value != null) {
Object.defineProperty(this, `__${key}`, {
value: Promise.resolve(value),
enumerable: false,
configurable: true
});
}
}
}
}
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "authorization", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "id", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "username", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "nickname", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "realname", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "avatarURL", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "coverURL", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "description", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "doing", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "email", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "badge", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "grade", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "birthday", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "sex", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "viewTimes", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "praiseTimes", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "collectTimes", null);
__decorate([enumerable(true)], CodemaoUserInfo.prototype, "forkTimes", null);
;// C:\Users\SLIGHTNING\OneDrive\代码\其他\编程猫\扩展\CoCo 自定义控件\源码云功能\src\codemao\user\codemao-user.ts
function C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_defineProperty(e, r, t) { return (r = C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_toPropertyKey(t) { var i = C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function C_Users_SLIGHTNING_OneDrive_CoCo_src_codemao_user_codemao_user_toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/**
* 编程猫用户。
*/
class CodemaoUser {
/**
* 设置身份,仅在 Node 中可用。
*/
static async setAuthorization(authorization) {
const path = await Promise.resolve().then(function webpackMissingModule() { var e = new Error("Cannot find module 'path'"); e.code = 'MODULE_NOT_FOUND'; throw e; });
const {
mkdir,
writeFile
} = (await Promise.resolve().then(function webpackMissingModule() { var e = new Error("Cannot find module 'fs'"); e.code = 'MODULE_NOT_FOUND'; throw e; })).promises;
const appDirs = (await Promise.resolve().then(function webpackMissingModule() { var e = new Error("Cannot find module 'appdirsjs'"); e.code = 'MODULE_NOT_FOUND'; throw e; })).default;
const configPath = appDirs({
appName: "SLIGHTNING/Codemao-Community"
}).config;
await mkdir(configPath, {
recursive: true
});
await writeFile(path.resolve(configPath, "authorization.txt"), authorization);
}
/**
* 请求用户登录编程猫账号,仅在浏览器中可用。
*/
static asy