MCPcopy Create free account
hub / github.com/chavyleung/scripts / qlEnvsSearch

Function qlEnvsSearch

zsfc/zsfc.js:828–869  ·  view source on GitHub ↗

* @description 搜索环境变量并生成新的请求体部分参数 * @param {string} envsName - 新环境变量的名称 * @param {string} envsValue - 新环境变量的具体值 * @param {string} envsRemarks - 新环境变量的备注名 * @returns {Promise } 返回一个请求体对象或列表或布尔值的 Promise。

(envsName, envsValue, envsRemarks)

Source from the content-addressed store, hash-verified

826 * @returns {Promise<object|Array|boolean>} 返回一个请求体对象或列表或布尔值的 Promise。
827 */
828async function qlEnvsSearch(envsName, envsValue, envsRemarks) {
829 // 初始化请求体的变量名
830 let requestPayload;
831
832 // 构建请求体
833 const options = {
834 url: `${$.qlUrl}/open/envs?searchValue=${envsName}`,
835 headers: { "Authorization": `Bearer ${$.qlToken}` }
836 };
837
838 // 返回一个 Promise 对象,用于异步操作
839 return new Promise(resolve => {
840 // 发送 GET 请求,搜索指定变量
841 $.get(options, (err, resp, data) => {
842 if (data) {
843 const responseBody = $.toObj(data).data;
844 if (responseBody.length === 1) {
845 // 找到匹配的环境变量,生成单个请求体对象
846 const matchingEnv = responseBody[0];
847 if (matchingEnv.value === envsValue) {
848 requestPayload = false;
849 } else {
850 requestPayload = {
851 'id': matchingEnv.id,
852 'name': envsName,
853 'value': envsValue,
854 'remarks': envsRemarks
855 };
856 }
857 } else {
858 // 未找到匹配的环境变量,生成包含一个对象的数组
859 requestPayload = [{
860 'name': envsName,
861 'value': envsValue,
862 'remarks': envsRemarks
863 }];
864 }
865 }
866 resolve(requestPayload);
867 });
868 });
869}
870
871/**
872 * @description 编辑青龙面板的环境变量

Callers 1

zsfc.jsFile · 0.70

Calls 2

getMethod · 0.45
toObjMethod · 0.45

Tested by

no test coverage detected