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

Function qlEnvsSearch

zsfc/zsfc.treasure.js:396–431  ·  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

394 * @returns {Promise<object|Array|boolean>} 返回一个请求体对象或列表或布尔值的 Promise。
395 */
396async function qlEnvsSearch(envsName, envsValue, envsRemarks) {
397 let requestPayload; // 代表请求体的变量名更具体
398 const options = {
399 url: `${$.qlUrl}/open/envs?searchValue=${envsName}`,
400 headers: { "Authorization": `Bearer ${$.qlToken}` }
401 };
402 return new Promise(resolve => {
403 $.get(options, (err, resp, data) => {
404 if (data) {
405 const responseBody = $.toObj(data).data;
406 if (responseBody.length === 1) {
407 // 找到匹配的环境变量,生成单个请求体对象
408 const matchingEnv = responseBody[0];
409 if (matchingEnv.value === envsValue) {
410 requestPayload = false;
411 } else {
412 requestPayload = {
413 'id': matchingEnv.id,
414 'name': envsName,
415 'value': envsValue,
416 'remarks': envsRemarks
417 };
418 }
419 } else {
420 // 未找到匹配的环境变量,生成包含一个对象的数组
421 requestPayload = [{
422 'name': envsName,
423 'value': envsValue,
424 'remarks': envsRemarks
425 }];
426 }
427 }
428 resolve(requestPayload);
429 });
430 });
431}
432
433/**
434 * @description 编辑青龙面板的环境变量

Callers 1

zsfc.treasure.jsFile · 0.70

Calls 2

getMethod · 0.45
toObjMethod · 0.45

Tested by

no test coverage detected