From 0a444c79c14d8e03e6c7d4e15bf523d6b6861852 Mon Sep 17 00:00:00 2001 From: "Alexander Ilyenko (WX1330152)" Date: Thu, 14 Aug 2025 12:47:35 +0300 Subject: [PATCH 1/3] Add: "tools/storage/openlab/cli.mjs": add "search-asset-paths-by-name", "download-asset-by-name" commands --- tools/storage/openlab/cli.mjs | 26 ++++++++++++++++++++++++++ tools/storage/openlab/openlab.mjs | 30 +++++++++++++++++++++++++++++- tools/utils/http.mjs | 1 - 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/tools/storage/openlab/cli.mjs b/tools/storage/openlab/cli.mjs index b8ca38d43..7464f16c6 100644 --- a/tools/storage/openlab/cli.mjs +++ b/tools/storage/openlab/cli.mjs @@ -41,6 +41,32 @@ command.command("download") await download(options) }) +command.command("search-asset-paths-by-name") + .description("List assets from openlab by name filter") + .option("--repository ", "Repository name", "koala-raw") + .option("--name ", "path-like filter", "/ohos-sdk/6.*.zip") + .action(async (options) => { + var searchResul = await openlab.searchAssets({ + "repository": options.repository, + "name": options.name + }) + searchResul.items.forEach(assetInfo => { + console.log(assetInfo.path) + }) + }) + +command.command("download-asset-by-name") + .description("Downloads package from openlab") + .option("--repository ", "Repository name", "koala-raw") + .option("--name ", "path-like name") + .option("-d --destination ", "path to the folder to download") + .action(async (options) => { + await openlab.downloadRawArchiveFromUrl( + `${openlab.webRepositoryBaseUrl()}/${options.repository}${options.name}`, + options.destination, + ) + }) + command.command("chmod") .description("Sets mod bits") .requiredOption("-p --path ", "path to the file or folder") diff --git a/tools/storage/openlab/openlab.mjs b/tools/storage/openlab/openlab.mjs index 2502f1c5f..eaabe86ec 100644 --- a/tools/storage/openlab/openlab.mjs +++ b/tools/storage/openlab/openlab.mjs @@ -15,9 +15,12 @@ import path from "path" import process from "process" +import querystring from "querystring" import { Http } from "../../utils/http.mjs" +import { Message } from "../../utils/log/message.mjs"; const KOALA_REPO = process.env.KOALA_REPO +const DEFAUL_KOALA_REPO_NAME = "koala-raw" // Set NEXUS_NPM_PASS or both OPENLAB_USERNAME/OPENLAB_PASSWORD in your ENV to use Openlab storage const NEXUS_NPM_PASS = process.env.NEXUS_NPM_PASS @@ -55,7 +58,23 @@ export class Openlab { if (KOALA_REPO) { return KOALA_REPO } - return 'https://nexus.cn.bz-openlab.ru:10443/repository/koala-raw/' + return `${this.webRepositoryBaseUrl()}/${DEFAUL_KOALA_REPO_NAME}/` + } + + restBaseUrl() { + return `${this.rootUrl()}/service/rest/v1` + } + + webRepositoryBaseUrl() { + return `${this.rootUrl()}/repository` + } + + rootUrl() { + var rootUrl = 'https://nexus.cn.bz-openlab.ru:10443' + if (KOALA_REPO) { + Message.warning("Ignore(unsupported currently) env.var. KOALA_REPO(${KOALA_REPO}). Using '${rootUrl}'...") + } + return rootUrl } rawPackageUrl(name, version, file) { @@ -63,6 +82,15 @@ export class Openlab { return host + name + '/' + version + '/' + file } + // https://help.sonatype.com/en/assets-api.html + async searchAssets(params) { + var resultJsonString = await Http.httpGet( + `${this.restBaseUrl()}/search/assets?${querystring.stringify(params)}`, + this.getHeaders() + ) + return JSON.parse(resultJsonString) + } + async downloadRawFile(packageName, packageVersion, fileName, outDir, outFile) { await Http.downloadFile( this.rawPackageUrl(packageName, packageVersion, fileName), diff --git a/tools/utils/http.mjs b/tools/utils/http.mjs index fb9e98078..f3301eb1b 100644 --- a/tools/utils/http.mjs +++ b/tools/utils/http.mjs @@ -49,7 +49,6 @@ export class Http { reject(new Error(`Error: ${error.message}`)) }); - request.write(); request.end(); }) } -- Gitee From 2388b0ac033676603de2b93c9ddc4f9d8f79eec9 Mon Sep 17 00:00:00 2001 From: "Alexander Ilyenko (WX1330152)" Date: Thu, 14 Aug 2025 15:57:40 +0300 Subject: [PATCH 2/3] Fix: typo in KOALA_REPO logging (quotas) --- tools/storage/openlab/openlab.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/storage/openlab/openlab.mjs b/tools/storage/openlab/openlab.mjs index eaabe86ec..741c1927b 100644 --- a/tools/storage/openlab/openlab.mjs +++ b/tools/storage/openlab/openlab.mjs @@ -72,7 +72,7 @@ export class Openlab { rootUrl() { var rootUrl = 'https://nexus.cn.bz-openlab.ru:10443' if (KOALA_REPO) { - Message.warning("Ignore(unsupported currently) env.var. KOALA_REPO(${KOALA_REPO}). Using '${rootUrl}'...") + Message.warning(`Ignore(unsupported currently) env.var. KOALA_REPO('${KOALA_REPO}'). Using '${rootUrl}'...`) } return rootUrl } -- Gitee From 46a8df070a5d806280bf3e46da5eb92440c5678f Mon Sep 17 00:00:00 2001 From: "Alexander Ilyenko (WX1330152)" Date: Thu, 14 Aug 2025 16:21:03 +0300 Subject: [PATCH 3/3] CR: CI: "var"=>"const" --- tools/storage/openlab/cli.mjs | 2 +- tools/storage/openlab/openlab.mjs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/storage/openlab/cli.mjs b/tools/storage/openlab/cli.mjs index 7464f16c6..940718709 100644 --- a/tools/storage/openlab/cli.mjs +++ b/tools/storage/openlab/cli.mjs @@ -46,7 +46,7 @@ command.command("search-asset-paths-by-name") .option("--repository ", "Repository name", "koala-raw") .option("--name ", "path-like filter", "/ohos-sdk/6.*.zip") .action(async (options) => { - var searchResul = await openlab.searchAssets({ + const searchResul = await openlab.searchAssets({ "repository": options.repository, "name": options.name }) diff --git a/tools/storage/openlab/openlab.mjs b/tools/storage/openlab/openlab.mjs index 741c1927b..beefe35d5 100644 --- a/tools/storage/openlab/openlab.mjs +++ b/tools/storage/openlab/openlab.mjs @@ -70,7 +70,7 @@ export class Openlab { } rootUrl() { - var rootUrl = 'https://nexus.cn.bz-openlab.ru:10443' + const rootUrl = 'https://nexus.cn.bz-openlab.ru:10443' if (KOALA_REPO) { Message.warning(`Ignore(unsupported currently) env.var. KOALA_REPO('${KOALA_REPO}'). Using '${rootUrl}'...`) } @@ -84,7 +84,7 @@ export class Openlab { // https://help.sonatype.com/en/assets-api.html async searchAssets(params) { - var resultJsonString = await Http.httpGet( + const resultJsonString = await Http.httpGet( `${this.restBaseUrl()}/search/assets?${querystring.stringify(params)}`, this.getHeaders() ) -- Gitee