From aefd00d89446b354e004b91a8678544d9389e1ec Mon Sep 17 00:00:00 2001 From: Kelly Peilin Chan Date: Sun, 16 Feb 2025 18:05:24 +0800 Subject: [PATCH] feat: support custom --apiEndpoint --- readme.md | 1 + src/feishu-doc-export/FeiShuConsts.cs | 2 +- src/feishu-doc-export/GlobalConfig.cs | 8 +++++++- src/feishu-doc-export/HttpApi/FeiShuHttpApiCaller.cs | 4 ++-- src/feishu-doc-export/HttpApi/IFeiShuHttpApi.cs | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 2de8bf4..378bb80 100644 --- a/readme.md +++ b/readme.md @@ -87,6 +87,7 @@ --type 知识库(wiki)或个人空间云文档(cloudDoc)(可选值:cloudDoc、wiki,为空则默认为wiki). --saveType 文档导出的文件类型(可选值:docx、md、pdf,为空或其他非可选值则默认为docx). --folderToken 当type为个人空间云文档时,该项必填. + --apiEndpoint 可以指定 API 的路径,如https://open.larksuite.com ,以支持Lark 环境 ``` - win环境 diff --git a/src/feishu-doc-export/FeiShuConsts.cs b/src/feishu-doc-export/FeiShuConsts.cs index 462daf7..a1075ba 100644 --- a/src/feishu-doc-export/FeiShuConsts.cs +++ b/src/feishu-doc-export/FeiShuConsts.cs @@ -11,6 +11,6 @@ public static class FeiShuConsts /// /// 飞书开发接口地址 /// - public const string OpenApiEndPoint = "https://open.feishu.cn"; + public const string DefaultOpenApiEndPoint = "https://open.feishu.cn"; } } diff --git a/src/feishu-doc-export/GlobalConfig.cs b/src/feishu-doc-export/GlobalConfig.cs index d2dd0ef..648cb25 100644 --- a/src/feishu-doc-export/GlobalConfig.cs +++ b/src/feishu-doc-export/GlobalConfig.cs @@ -13,6 +13,8 @@ public static class GlobalConfig public static string ExportPath { get; set; } + public static string ApiEndpoint { get; set; } + public static string WikiSpaceId { get; set; } public static string CloudDocFolder { get; set; } @@ -60,7 +62,7 @@ private static void InitAsposeLicense() { License license = new License(); // 加载本地密钥 - license.SetLicense("C:\\Users\\User\\Desktop\\Aspose.lic"); + license.SetLicense("/private/tmp/License.lic"); } /// @@ -78,6 +80,10 @@ public static void Init(string[] args) WikiSpaceId = GetCommandLineArg(args, "--spaceId=", true); DocSaveType = GetCommandLineArg(args, "--saveType=", true); ExportPath = GetCommandLineArg(args, "--exportPath="); + ApiEndpoint = GetCommandLineArg(args, "--apiEndpoint="); + if (string.IsNullOrWhiteSpace(ExportPath)) { + ApiEndpoint = FeiShuConsts.DefaultOpenApiEndPoint; + } Quit = args.Contains("--quit"); } else diff --git a/src/feishu-doc-export/HttpApi/FeiShuHttpApiCaller.cs b/src/feishu-doc-export/HttpApi/FeiShuHttpApiCaller.cs index d394420..48253b4 100644 --- a/src/feishu-doc-export/HttpApi/FeiShuHttpApiCaller.cs +++ b/src/feishu-doc-export/HttpApi/FeiShuHttpApiCaller.cs @@ -130,7 +130,7 @@ public FeiShuHttpApiCaller(IFeiShuHttpApi feiShuHttpApi) public async Task> GetWikiNodeList(string spaceId, string pageToken = null, string parentNodeToken = null) { - StringBuilder urlBuilder = new StringBuilder($"{FeiShuConsts.OpenApiEndPoint}/open-apis/wiki/v2/spaces/{spaceId}/nodes?page_size=50");// page_size=50 + StringBuilder urlBuilder = new StringBuilder($"{FeiShuConsts.DefaultOpenApiEndPoint}/open-apis/wiki/v2/spaces/{spaceId}/nodes?page_size=50");// page_size=50 if (!string.IsNullOrWhiteSpace(pageToken)) { urlBuilder.Append($"&page_token={pageToken}"); @@ -383,7 +383,7 @@ public async Task GetFolderMeta(string folderToken) public async Task> GetCloudDocList(string folderToken = null, string pageToken = null) { - StringBuilder urlBuilder = new StringBuilder($"{FeiShuConsts.OpenApiEndPoint}/open-apis/drive/v1/files?folder_token={folderToken}&page_size=50");// page_size=50 + StringBuilder urlBuilder = new StringBuilder($"{FeiShuConsts.DefaultOpenApiEndPoint}/open-apis/drive/v1/files?folder_token={folderToken}&page_size=50");// page_size=50 if (!string.IsNullOrWhiteSpace(pageToken)) { urlBuilder.Append($"&page_token={pageToken}"); diff --git a/src/feishu-doc-export/HttpApi/IFeiShuHttpApi.cs b/src/feishu-doc-export/HttpApi/IFeiShuHttpApi.cs index cfa9529..fdfa09f 100644 --- a/src/feishu-doc-export/HttpApi/IFeiShuHttpApi.cs +++ b/src/feishu-doc-export/HttpApi/IFeiShuHttpApi.cs @@ -10,7 +10,7 @@ namespace feishu_doc_export.HttpApi { - [HttpHost(FeiShuConsts.OpenApiEndPoint)] + [HttpHost(FeiShuConsts.DefaultOpenApiEndPoint)] public interface IFeiShuHttpApi : IHttpApi { ///