-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from xhnbzdl/cloud-doc
支持个人空间云文档导出
- Loading branch information
Showing
9 changed files
with
551 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using feishu_doc_export.Dtos; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace feishu_doc_export | ||
{ | ||
public static class CloudDocPathGenerator | ||
{ | ||
/// <summary> | ||
/// 文档token和路径的映射 | ||
/// </summary> | ||
private static Dictionary<string, string> documentPaths; | ||
|
||
public static void GenerateDocumentPaths(List<CloudDocDto> documents, string rootFolderPath) | ||
{ | ||
documentPaths = new Dictionary<string, string>(); | ||
|
||
foreach (var document in documents) | ||
{ | ||
if (!documentPaths.ContainsKey(document.Token)) | ||
{ | ||
GenerateDocumentPath(document, rootFolderPath, documents); | ||
} | ||
} | ||
|
||
} | ||
|
||
private static void GenerateDocumentPath(CloudDocDto document, string parentFolderPath, List<CloudDocDto> documents) | ||
{ | ||
// 替换文件名中的非法字符 | ||
string name = Regex.Replace(document.Name, @"[\\/:\*\?""<>\|]", "-"); | ||
string documentFolderPath = Path.Combine(parentFolderPath, name); | ||
|
||
documentPaths[document.Token] = documentFolderPath; | ||
|
||
foreach (var childDocument in GetChildDocuments(document, documents)) | ||
{ | ||
GenerateDocumentPath(childDocument, documentFolderPath, documents); | ||
} | ||
} | ||
|
||
private static IEnumerable<CloudDocDto> GetChildDocuments(CloudDocDto document, List<CloudDocDto> documents) | ||
{ | ||
return documents.Where(d => d.ParentToken == document.Token); | ||
} | ||
|
||
/// <summary> | ||
/// 获取文档的存储路径 | ||
/// </summary> | ||
/// <param name="objToken"></param> | ||
/// <returns></returns> | ||
public static string GetDocumentPath(string objToken) | ||
{ | ||
documentPaths.TryGetValue(objToken, out string path); | ||
return path; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
|
||
namespace feishu_doc_export.Dtos | ||
{ | ||
/// <summary> | ||
/// 个人空间云文档 | ||
/// </summary> | ||
public class CloudDocDto | ||
{ | ||
[JsonPropertyName("created_time")] | ||
public string CreatedTime { get; set; } | ||
|
||
[JsonPropertyName("modified_time")] | ||
public string ModifiedTime { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
[JsonPropertyName("owner_id")] | ||
public string OwnerId { get; set; } | ||
|
||
[JsonPropertyName("parent_token")] | ||
public string ParentToken { get; set; } | ||
|
||
public string Token { get; set; } | ||
|
||
public string Type { get; set; } | ||
|
||
public string Url { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace feishu_doc_export.Dtos | ||
{ | ||
/// <summary> | ||
/// 个人空间云文档文件夹信息 | ||
/// </summary> | ||
public class CloudDocFolderMeta | ||
{ | ||
public string Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public string Token { get; set; } | ||
|
||
public string CreateUid { get; set; } | ||
|
||
public string EditUid { get; set; } | ||
|
||
public string ParentId { get; set; } | ||
|
||
public string OwnUid { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.