@hangox/mg-cli 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -278,9 +278,6 @@ function parseMgpLink(link) {
278
278
  }
279
279
  if (encodedPageId) {
280
280
  const pageId = decodeURIComponent(encodedPageId);
281
- if (!/^\d+:\d+$/.test(pageId)) {
282
- return null;
283
- }
284
281
  return {
285
282
  pageUrl,
286
283
  pageId
@@ -2754,7 +2751,7 @@ async function handleListExtensions(options) {
2754
2751
  // src/cli/commands/open-page.ts
2755
2752
  import { Command as Command10 } from "commander";
2756
2753
  function createOpenPageCommand() {
2757
- return new Command10("open_page").description("\u901A\u8FC7 Chrome \u6269\u5C55\u6253\u5F00\u6307\u5B9A\u7684\u9875\u9762").requiredOption("--url <url>", "\u8981\u6253\u5F00\u7684\u9875\u9762 URL\uFF08\u5B8C\u6574 HTTPS URL\uFF09").option("--ext <index>", "\u6269\u5C55\u5B9E\u4F8B\u5E8F\u53F7\uFF081, 2, 3...\uFF09\uFF0C\u9ED8\u8BA4\u81EA\u52A8\u9009\u62E9\u7B2C\u4E00\u4E2A\u53EF\u7528\u6269\u5C55").option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
2754
+ return new Command10("open_page").description("\u901A\u8FC7 Chrome \u6269\u5C55\u6253\u5F00\u6307\u5B9A\u7684\u9875\u9762").requiredOption("--link <link>", "\u9875\u9762\u94FE\u63A5\uFF08\u652F\u6301 https:// \u6216 mgp:// \u683C\u5F0F\uFF09").option("--ext <index>", "\u6269\u5C55\u5B9E\u4F8B\u5E8F\u53F7\uFF081, 2, 3...\uFF09\uFF0C\u9ED8\u8BA4\u81EA\u52A8\u9009\u62E9\u7B2C\u4E00\u4E2A\u53EF\u7528\u6269\u5C55").option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
2758
2755
  await handleOpenPage(options);
2759
2756
  });
2760
2757
  }
@@ -2764,9 +2761,24 @@ async function handleOpenPage(options) {
2764
2761
  noRetry: options.noRetry
2765
2762
  });
2766
2763
  try {
2767
- if (!options.url.startsWith("https://") && !options.url.startsWith("http://")) {
2768
- console.error("\u9519\u8BEF: URL \u5FC5\u987B\u4EE5 https:// \u6216 http:// \u5F00\u5934");
2769
- console.error(`\u63D0\u4F9B\u7684 URL: ${options.url}`);
2764
+ let targetUrl;
2765
+ if (options.link.startsWith("mgp://")) {
2766
+ const parsed = parseMgpLink(options.link);
2767
+ if (!parsed) {
2768
+ console.error(`\u9519\u8BEF [${"E010" /* INVALID_LINK */}]: \u65E0\u6548\u7684 mgp:// \u94FE\u63A5\u683C\u5F0F`);
2769
+ console.error(`\u63D0\u4F9B\u7684\u94FE\u63A5: ${options.link}`);
2770
+ console.error(`\u671F\u671B\u683C\u5F0F: mgp://[mastergo_page_url]?nodeId=[\u8282\u70B9ID] \u6216 mgp://[mastergo_page_url]?pageId=[\u9875\u9762ID]`);
2771
+ process.exit(1);
2772
+ }
2773
+ targetUrl = `https://${parsed.pageUrl}`;
2774
+ } else if (options.link.startsWith("https://") || options.link.startsWith("http://")) {
2775
+ targetUrl = options.link;
2776
+ } else {
2777
+ console.error("\u9519\u8BEF: \u94FE\u63A5\u683C\u5F0F\u65E0\u6548");
2778
+ console.error(`\u63D0\u4F9B\u7684\u94FE\u63A5: ${options.link}`);
2779
+ console.error("\u652F\u6301\u7684\u683C\u5F0F:");
2780
+ console.error(" \u2022 https://mastergo.netease.com/file/xxx");
2781
+ console.error(" \u2022 mgp://mastergo.netease.com/file/xxx?nodeId=123%3A456");
2770
2782
  process.exit(1);
2771
2783
  }
2772
2784
  await client.connect();
@@ -2798,9 +2810,9 @@ async function handleOpenPage(options) {
2798
2810
  process.exit(1);
2799
2811
  }
2800
2812
  console.log(`\u6B63\u5728\u901A\u8FC7\u6269\u5C55 #${extensionIndex} \u6253\u5F00\u9875\u9762...`);
2801
- console.log(`URL: ${options.url}`);
2813
+ console.log(`URL: ${targetUrl}`);
2802
2814
  const params = {
2803
- url: options.url,
2815
+ url: targetUrl,
2804
2816
  extensionIndex
2805
2817
  };
2806
2818
  const data = await client.requestWithRetry(