openlark-docs 0.19.0

飞书开放平台云文档服务模块 - 文档、表格、知识库API (202 APIs, 100% 覆盖,不含旧版本)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
//! Drive、Explorer 与 Permission API 端点目录。

use super::CatalogEndpoint;
use openlark_core::api::{ApiRequest, HttpMethod};

/// CCM Drive Explorer API Old V2 端点枚举
/// 对应 meta.project = ccm_drive_explorer, meta.version = old
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(test, derive(strum_macros::EnumIter))]
pub enum CcmDriveExplorerApiOld {
    /// 获取我的空间(根文件夹)元数据
    RootFolderMeta,
    /// 获取文件夹元数据
    FolderMeta(String), // folder_token
    /// 新建文件
    File(String), // folder_token
    /// 删除Sheet
    FileSpreadsheets(String), // spreadsheet_token
    /// 复制文档
    FileCopy(String), // file_token
    /// 删除Doc
    FileDocs(String), // doc_token
    /// 获取文件夹下的文档清单
    FolderChildren(String), // folder_token
    /// 新建文件夹
    Folder(String), // folder_token
}

impl CcmDriveExplorerApiOld {
    /// 生成对应的 URL
    pub fn to_url(&self) -> String {
        match self {
            CcmDriveExplorerApiOld::RootFolderMeta => {
                "/open-apis/drive/explorer/v2/root_folder/meta".to_string()
            }
            CcmDriveExplorerApiOld::FolderMeta(folder_token) => {
                format!("/open-apis/drive/explorer/v2/folder/{folder_token}/meta")
            }
            CcmDriveExplorerApiOld::File(folder_token) => {
                format!("/open-apis/drive/explorer/v2/file/{folder_token}")
            }
            CcmDriveExplorerApiOld::FileSpreadsheets(spreadsheet_token) => {
                format!("/open-apis/drive/explorer/v2/file/spreadsheets/{spreadsheet_token}")
            }
            CcmDriveExplorerApiOld::FileCopy(file_token) => {
                format!("/open-apis/drive/explorer/v2/file/copy/files/{file_token}")
            }
            CcmDriveExplorerApiOld::FileDocs(doc_token) => {
                format!("/open-apis/drive/explorer/v2/file/docs/{doc_token}")
            }
            CcmDriveExplorerApiOld::FolderChildren(folder_token) => {
                format!("/open-apis/drive/explorer/v2/folder/{folder_token}/children")
            }
            CcmDriveExplorerApiOld::Folder(folder_token) => {
                format!("/open-apis/drive/explorer/v2/folder/{folder_token}")
            }
        }
    }

    /// 返回配置了稳定请求语义的请求。
    pub fn to_request<R>(&self) -> ApiRequest<R> {
        <Self as CatalogEndpoint>::to_request(self)
    }
}

impl CatalogEndpoint for CcmDriveExplorerApiOld {
    fn to_url(&self) -> String {
        CcmDriveExplorerApiOld::to_url(self)
    }

    fn method(&self) -> HttpMethod {
        match self {
            Self::RootFolderMeta | Self::FolderMeta(_) | Self::FolderChildren(_) => HttpMethod::Get,
            Self::File(_) | Self::FileCopy(_) | Self::Folder(_) => HttpMethod::Post,
            Self::FileSpreadsheets(_) | Self::FileDocs(_) => HttpMethod::Delete,
        }
    }

    // supported_access_token_types 使用 trait 默认实现(User + Tenant)
}

/// CCM Drive Explorer API V1 端点枚举
/// 对应 meta.project = ccm_drive_explorer, meta.version = v1
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(test, derive(strum_macros::EnumIter))]
pub enum CcmDriveExplorerApi {
    /// 获取根目录元数据
    RootFolderMeta,
    /// 获取文件夹元数据
    FolderMeta(String), // folder_token
    /// 获取文件元数据
    File(String), // file_token
    /// 复制文件
    FileCopy(String), // file_token
    /// 获取文档文件信息
    FileDocs(String), // file_token
    /// 获取表格文件信息
    FileSpreadsheets(String), // file_token
    /// 获取文件夹子内容
    FolderChildren(String), // folder_token
    /// 创建文件夹
    Folder,
}

impl CcmDriveExplorerApi {
    /// 生成对应的 URL
    pub fn to_url(&self) -> String {
        match self {
            CcmDriveExplorerApi::RootFolderMeta => {
                "/open-apis/drive/v1/explorer/root_folder/meta".to_string()
            }
            CcmDriveExplorerApi::FolderMeta(folder_token) => {
                format!("/open-apis/drive/v1/explorer/folder/{folder_token}/meta")
            }
            CcmDriveExplorerApi::File(file_token) => {
                format!("/open-apis/drive/v1/explorer/file/{file_token}")
            }
            CcmDriveExplorerApi::FileCopy(file_token) => {
                format!("/open-apis/drive/v1/explorer/file/copy/files/{file_token}")
            }
            CcmDriveExplorerApi::FileDocs(file_token) => {
                format!("/open-apis/drive/v1/explorer/file/docs/{file_token}")
            }
            CcmDriveExplorerApi::FileSpreadsheets(file_token) => {
                format!("/open-apis/drive/v1/explorer/file/spreadsheets/{file_token}")
            }
            CcmDriveExplorerApi::FolderChildren(folder_token) => {
                format!("/open-apis/drive/v1/explorer/folder/{folder_token}/children")
            }
            CcmDriveExplorerApi::Folder => "/open-apis/drive/v1/explorer/folder".to_string(),
        }
    }

    /// 生成带参数的 URL
    pub fn to_url_with_params(&self, params: &[(&str, String)]) -> String {
        let base_url = self.to_url();
        if params.is_empty() {
            return base_url;
        }

        let query_string = params
            .iter()
            .map(|(key, value)| format!("{}={}", key, simple_url_encode(value)))
            .collect::<Vec<_>>()
            .join("&");

        format!("{base_url}?{query_string}")
    }

    /// 返回配置了稳定请求语义的请求。
    pub fn to_request<R>(&self) -> ApiRequest<R> {
        <Self as CatalogEndpoint>::to_request(self)
    }
}

impl CatalogEndpoint for CcmDriveExplorerApi {
    fn to_url(&self) -> String {
        CcmDriveExplorerApi::to_url(self)
    }

    fn method(&self) -> HttpMethod {
        match self {
            Self::RootFolderMeta
            | Self::FolderMeta(_)
            | Self::File(_)
            | Self::FileDocs(_)
            | Self::FileSpreadsheets(_)
            | Self::FolderChildren(_) => HttpMethod::Get,
            Self::FileCopy(_) | Self::Folder => HttpMethod::Post,
        }
    }

    // supported_access_token_types 使用 trait 默认实现(User + Tenant)
}

/// 简单的URL编码函数,用于查询参数编码
fn simple_url_encode(input: &str) -> String {
    input
        .chars()
        .map(|c| match c {
            'A'..='Z' | 'a'..='z' | '0'..='9' | '-' | '_' | '.' | '~' => c.to_string(),
            _ => format!("%{:02X}", c as u8),
        })
        .collect()
}

/// CCM Drive Permission API V1 端点枚举
/// 对应 meta.project = permission, meta.version = v1
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(test, derive(strum_macros::EnumIter))]
pub enum PermissionApi {
    /// 判断协作者是否有某权限
    MemberPermitted,
    /// 转移拥有者
    MemberTransfer,
    /// 获取云文档权限设置V2
    Public,
}

impl PermissionApi {
    /// 生成对应的 URL
    pub fn to_url(&self) -> String {
        match self {
            PermissionApi::MemberPermitted => {
                "/open-apis/drive/v1/permission/member/permitted".to_string()
            }
            PermissionApi::MemberTransfer => {
                "/open-apis/drive/v1/permission/member/transfer".to_string()
            }
            PermissionApi::Public => "/open-apis/drive/v1/permission/v2/public/".to_string(),
        }
    }

    /// 返回配置了稳定请求语义的请求。
    pub fn to_request<R>(&self) -> ApiRequest<R> {
        <Self as CatalogEndpoint>::to_request(self)
    }
}

impl CatalogEndpoint for PermissionApi {
    fn to_url(&self) -> String {
        PermissionApi::to_url(self)
    }

    fn method(&self) -> HttpMethod {
        HttpMethod::Post
    }

    // supported_access_token_types 使用 trait 默认实现(User + Tenant)
}

/// CCM Drive Permission API Old V2 端点枚举
/// 对应 meta.project = permission, meta.version = old
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(test, derive(strum_macros::EnumIter))]
pub enum PermissionApiOld {
    /// 判断协作者是否有某权限
    MemberPermitted,
    /// 转移拥有者
    MemberTransfer,
    /// 获取云文档权限设置V2
    Public,
}

impl PermissionApiOld {
    /// 生成对应的 URL
    pub fn to_url(&self) -> String {
        match self {
            PermissionApiOld::MemberPermitted => {
                "/open-apis/drive/v1/permission/member/permitted".to_string()
            }
            PermissionApiOld::MemberTransfer => {
                "/open-apis/drive/v1/permission/member/transfer".to_string()
            }
            PermissionApiOld::Public => "/open-apis/drive/v1/permission/v2/public/".to_string(),
        }
    }

    /// 返回配置了稳定请求语义的请求。
    pub fn to_request<R>(&self) -> ApiRequest<R> {
        <Self as CatalogEndpoint>::to_request(self)
    }
}

impl CatalogEndpoint for PermissionApiOld {
    fn to_url(&self) -> String {
        PermissionApiOld::to_url(self)
    }

    fn method(&self) -> HttpMethod {
        HttpMethod::Post
    }

    // supported_access_token_types 使用 trait 默认实现(User + Tenant)
}

/// Drive API 端点枚举
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(test, derive(strum_macros::EnumIter))]
pub enum DriveApi {
    // V1 APIs - 文件操作
    /// 获取文件夹中的文件清单
    ListFiles,
    /// 新建文件夹
    CreateFolder,
    /// 查询异步任务状态
    TaskCheck,
    /// 获取文件元数据(批量查询)
    BatchQueryMetas,
    /// 获取文件统计信息
    GetFileStatistics(String), // file_token
    /// 获取文件访问记录
    ListFileViewRecords(String), // file_token
    /// 复制文件
    CopyFile(String), // file_token
    /// 移动文件或文件夹
    MoveFile(String), // file_token
    /// 删除文件或文件夹
    DeleteFile(String), // file_token
    /// 创建文件快捷方式
    CreateShortcut,
    /// 上传文件
    UploadFile,
    /// 分片上传文件-预上传
    UploadPrepare,
    /// 分片上传文件-上传分片
    UploadPart,
    /// 分片上传文件-完成上传
    UploadFinish,
    /// 下载文件
    DownloadFile(String), // file_token
    /// 创建导入任务
    CreateImportTask,
    /// 查询导入任务结果
    GetImportTask(String), // ticket
    /// 创建导出任务
    CreateExportTask,
    /// 查询导出任务结果
    GetExportTask(String), // ticket
    /// 下载导出文件
    DownloadExportFile(String), // file_token
    /// 上传素材
    UploadMedia,
    /// 分片上传素材-预上传
    UploadMediaPrepare,
    /// 分片上传素材-上传分片
    UploadMediaPart,
    /// 分片上传素材-完成上传
    UploadMediaFinish,
    /// 下载素材
    DownloadMedia(String), // file_token
    /// 获取素材临时下载链接
    GetMediaTempDownloadUrls,
    /// 创建文档版本
    CreateFileVersion(String), // file_token
    /// 获取文档版本列表
    ListFileVersions(String), // file_token
    /// 获取文档版本信息
    GetFileVersion(String, String), // file_token, version_id
    /// 删除文档版本
    DeleteFileVersion(String, String), // file_token, version_id
    /// 订阅云文档事件
    SubscribeFile(String), // file_token
    /// 查询云文档事件订阅状态
    GetFileSubscribe(String), // file_token
    /// 取消云文档事件订阅
    DeleteFileSubscribe(String), // file_token
    /// 增加协作者权限
    CreatePermissionMember(String), // token
    /// 批量增加协作者权限
    BatchCreatePermissionMember(String), // token
    /// 更新协作者权限
    UpdatePermissionMember(String, String), // token, member_id
    /// 获取云文档协作者
    ListPermissionMembers(String), // token
    /// 移除云文档协作者权限
    DeletePermissionMember(String, String), // token, member_id
    /// 转移云文档所有者
    TransferOwner(String), // token
    /// 判断用户云文档权限
    AuthPermissionMember(String), // token
    /// 更新云文档权限设置
    UpdatePublicPermission(String), // token
    /// 获取云文档权限设置
    GetPublicPermission(String), // token
    /// 启用云文档密码
    CreatePublicPassword(String), // token
    /// 刷新云文档密码
    UpdatePublicPassword(String), // token
    /// 停用云文档密码
    DeletePublicPassword(String), // token
    /// 获取云文档所有评论
    ListFileComments(String), // file_token
    /// 批量获取评论
    BatchQueryComments(String), // file_token
    /// 解决/恢复评论
    PatchComment(String, String), // file_token, comment_id
    /// 添加全文评论
    CreateComment(String), // file_token
    /// 获取全文评论
    GetComment(String, String), // file_token, comment_id
    /// 获取回复信息
    ListCommentReplies(String, String), // file_token, comment_id
    /// 添加回复
    CreateCommentReply(String, String), // file_token, comment_id
    /// 更新回复的内容
    UpdateCommentReply(String, String, String), // file_token, comment_id, reply_id
    /// 删除回复
    DeleteCommentReply(String, String, String), // file_token, comment_id, reply_id
    /// 订阅用户云文档事件
    UserSubscription,
    /// 取消用户云文档事件订阅
    UserRemoveSubscription,
    /// 查询用户云文档事件订阅状态
    UserSubscriptionStatus,
    /// 获取订阅状态
    GetFileSubscription(String, String), // file_token, subscription_id
    /// 创建订阅
    CreateFileSubscription(String), // file_token
    /// 更新订阅状态
    UpdateFileSubscription(String, String), // file_token, subscription_id

    // V2 APIs
    /// 获取云文档的点赞者列表
    ListFileLikes(String), // file_token
    /// 获取云文档权限设置(v2)
    GetPublicPermissionV2(String), // token
    /// 更新云文档权限设置(v2)
    UpdatePublicPermissionV2(String), // token
    /// 添加或取消评论表情回应
    UpdateCommentReaction(String), // file_token

    // Media Upload Task APIs
    /// 创建媒体上传任务
    MediaUploadTasks,
    /// 获取媒体上传任务
    MediaUploadTask(String), // task_id
    /// 创建媒体分享链接
    CreateMediaShareLink(String), // file_token
    /// 获取公开密码
    GetPublicPassword(String), // file_token
}

impl DriveApi {
    /// 生成对应的 URL
    pub fn to_url(&self) -> String {
        match self {
            // V1 File APIs
            DriveApi::ListFiles => "/open-apis/drive/v1/files".to_string(),
            DriveApi::CreateFolder => "/open-apis/drive/v1/files/create_folder".to_string(),
            DriveApi::TaskCheck => "/open-apis/drive/v1/files/task_check".to_string(),
            DriveApi::BatchQueryMetas => "/open-apis/drive/v1/metas/batch_query".to_string(),
            DriveApi::GetFileStatistics(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}/statistics")
            }
            DriveApi::ListFileViewRecords(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}/view_records")
            }
            DriveApi::CopyFile(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}/copy")
            }
            DriveApi::MoveFile(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}/move")
            }
            DriveApi::DeleteFile(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}")
            }
            DriveApi::CreateShortcut => "/open-apis/drive/v1/files/create_shortcut".to_string(),
            DriveApi::UploadFile => "/open-apis/drive/v1/files/upload_all".to_string(),
            DriveApi::UploadPrepare => "/open-apis/drive/v1/files/upload_prepare".to_string(),
            DriveApi::UploadPart => "/open-apis/drive/v1/files/upload_part".to_string(),
            DriveApi::UploadFinish => "/open-apis/drive/v1/files/upload_finish".to_string(),
            DriveApi::DownloadFile(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}/download")
            }

            // Import/Export Task APIs
            DriveApi::CreateImportTask => "/open-apis/drive/v1/import_tasks".to_string(),
            DriveApi::GetImportTask(ticket) => {
                format!("/open-apis/drive/v1/import_tasks/{ticket}")
            }
            DriveApi::CreateExportTask => "/open-apis/drive/v1/export_tasks".to_string(),
            DriveApi::GetExportTask(ticket) => {
                format!("/open-apis/drive/v1/export_tasks/{ticket}")
            }
            DriveApi::DownloadExportFile(file_token) => {
                format!("/open-apis/drive/v1/export_tasks/file/{file_token}/download")
            }

            // Media APIs
            DriveApi::UploadMedia => "/open-apis/drive/v1/medias/upload_all".to_string(),
            DriveApi::UploadMediaPrepare => "/open-apis/drive/v1/medias/upload_prepare".to_string(),
            DriveApi::UploadMediaPart => "/open-apis/drive/v1/medias/upload_part".to_string(),
            DriveApi::UploadMediaFinish => "/open-apis/drive/v1/medias/upload_finish".to_string(),
            DriveApi::DownloadMedia(file_token) => {
                format!("/open-apis/drive/v1/medias/{file_token}/download")
            }
            DriveApi::GetMediaTempDownloadUrls => {
                "/open-apis/drive/v1/medias/batch_get_tmp_download_url".to_string()
            }

            // File Version APIs
            DriveApi::CreateFileVersion(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}/versions")
            }
            DriveApi::ListFileVersions(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}/versions")
            }
            DriveApi::GetFileVersion(file_token, version_id) => {
                format!("/open-apis/drive/v1/files/{file_token}/versions/{version_id}")
            }
            DriveApi::DeleteFileVersion(file_token, version_id) => {
                format!("/open-apis/drive/v1/files/{file_token}/versions/{version_id}")
            }

            // Subscription APIs
            DriveApi::SubscribeFile(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}/subscribe")
            }
            DriveApi::GetFileSubscribe(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}/get_subscribe")
            }
            DriveApi::DeleteFileSubscribe(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}/delete_subscribe")
            }

            // Permission Member APIs
            DriveApi::CreatePermissionMember(token) => {
                format!("/open-apis/drive/v1/permissions/{token}/members")
            }
            DriveApi::BatchCreatePermissionMember(token) => {
                format!("/open-apis/drive/v1/permissions/{token}/members/batch_create")
            }
            DriveApi::UpdatePermissionMember(token, member_id) => {
                format!("/open-apis/drive/v1/permissions/{token}/members/{member_id}")
            }
            DriveApi::ListPermissionMembers(token) => {
                format!("/open-apis/drive/v1/permissions/{token}/members")
            }
            DriveApi::DeletePermissionMember(token, member_id) => {
                format!("/open-apis/drive/v1/permissions/{token}/members/{member_id}")
            }
            DriveApi::TransferOwner(token) => {
                format!("/open-apis/drive/v1/permissions/{token}/members/transfer_owner")
            }
            DriveApi::AuthPermissionMember(token) => {
                format!("/open-apis/drive/v1/permissions/{token}/members/auth")
            }

            // Permission Public APIs
            DriveApi::UpdatePublicPermission(token) => {
                format!("/open-apis/drive/v1/permissions/{token}/public")
            }
            DriveApi::GetPublicPermission(token) => {
                format!("/open-apis/drive/v1/permissions/{token}/public")
            }
            DriveApi::CreatePublicPassword(token) => {
                format!("/open-apis/drive/v1/permissions/{token}/public/password")
            }
            DriveApi::UpdatePublicPassword(token) => {
                format!("/open-apis/drive/v1/permissions/{token}/public/password")
            }
            DriveApi::DeletePublicPassword(token) => {
                format!("/open-apis/drive/v1/permissions/{token}/public/password")
            }

            // Comment APIs
            DriveApi::ListFileComments(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}/comments")
            }
            DriveApi::BatchQueryComments(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}/comments/batch_query")
            }
            DriveApi::PatchComment(file_token, comment_id) => {
                format!("/open-apis/drive/v1/files/{file_token}/comments/{comment_id}")
            }
            DriveApi::CreateComment(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}/comments")
            }
            DriveApi::GetComment(file_token, comment_id) => {
                format!("/open-apis/drive/v1/files/{file_token}/comments/{comment_id}")
            }
            DriveApi::ListCommentReplies(file_token, comment_id) => {
                format!("/open-apis/drive/v1/files/{file_token}/comments/{comment_id}/replies")
            }
            DriveApi::CreateCommentReply(file_token, comment_id) => {
                format!("/open-apis/drive/v1/files/{file_token}/comments/{comment_id}/replies")
            }
            DriveApi::UpdateCommentReply(file_token, comment_id, reply_id) => {
                format!(
                    "/open-apis/drive/v1/files/{file_token}/comments/{comment_id}/replies/{reply_id}"
                )
            }
            DriveApi::DeleteCommentReply(file_token, comment_id, reply_id) => {
                format!(
                    "/open-apis/drive/v1/files/{file_token}/comments/{comment_id}/replies/{reply_id}"
                )
            }
            DriveApi::UserSubscription => "/open-apis/drive/v1/user/subscription".to_string(),
            DriveApi::UserRemoveSubscription => {
                "/open-apis/drive/v1/user/remove_subscription".to_string()
            }
            DriveApi::UserSubscriptionStatus => {
                "/open-apis/drive/v1/user/subscription_status".to_string()
            }

            // File Subscription APIs
            DriveApi::GetFileSubscription(file_token, subscription_id) => {
                format!("/open-apis/drive/v1/files/{file_token}/subscriptions/{subscription_id}")
            }
            DriveApi::CreateFileSubscription(file_token) => {
                format!("/open-apis/drive/v1/files/{file_token}/subscriptions")
            }
            DriveApi::UpdateFileSubscription(file_token, subscription_id) => {
                format!("/open-apis/drive/v1/files/{file_token}/subscriptions/{subscription_id}")
            }

            // V2 APIs
            DriveApi::ListFileLikes(file_token) => {
                format!("/open-apis/drive/v2/files/{file_token}/likes")
            }
            DriveApi::GetPublicPermissionV2(token) => {
                format!("/open-apis/drive/v2/permissions/{token}/public")
            }
            DriveApi::UpdatePublicPermissionV2(token) => {
                format!("/open-apis/drive/v2/permissions/{token}/public")
            }
            DriveApi::UpdateCommentReaction(file_token) => {
                format!("/open-apis/drive/v2/files/{file_token}/comments/reaction")
            }

            // Media Upload Task APIs
            DriveApi::MediaUploadTasks => "/open-apis/drive/v1/medias/upload_tasks".to_string(),
            DriveApi::MediaUploadTask(task_id) => {
                format!("/open-apis/drive/v1/medias/upload_tasks/{task_id}")
            }
            DriveApi::CreateMediaShareLink(file_token) => {
                format!("/open-apis/drive/v1/medias/{file_token}/share_link")
            }
            DriveApi::GetPublicPassword(file_token) => {
                format!("/open-apis/drive/v1/publics/{file_token}/password")
            }
        }
    }

    /// 返回配置了稳定请求语义的请求。
    pub fn to_request<R>(&self) -> ApiRequest<R> {
        <Self as CatalogEndpoint>::to_request(self)
    }

    /// 使用补充了动态 query 的 URL 构建请求。
    pub fn to_request_with_url<R>(&self, url: impl Into<String>) -> ApiRequest<R> {
        <Self as CatalogEndpoint>::to_request_with_url(self, url)
    }
}

impl CatalogEndpoint for DriveApi {
    fn to_url(&self) -> String {
        DriveApi::to_url(self)
    }

    fn method(&self) -> HttpMethod {
        match self {
            Self::ListFiles
            | Self::TaskCheck
            | Self::GetFileStatistics(_)
            | Self::ListFileViewRecords(_)
            | Self::GetImportTask(_)
            | Self::GetExportTask(_)
            | Self::DownloadFile(_)
            | Self::DownloadExportFile(_)
            | Self::DownloadMedia(_)
            | Self::GetMediaTempDownloadUrls
            | Self::ListFileVersions(_)
            | Self::GetFileVersion(_, _)
            | Self::GetFileSubscribe(_)
            | Self::ListPermissionMembers(_)
            | Self::AuthPermissionMember(_)
            | Self::GetPublicPermission(_)
            | Self::ListFileComments(_)
            | Self::GetComment(_, _)
            | Self::ListCommentReplies(_, _)
            | Self::GetFileSubscription(_, _)
            | Self::ListFileLikes(_)
            | Self::GetPublicPermissionV2(_)
            | Self::MediaUploadTask(_)
            | Self::GetPublicPassword(_) => HttpMethod::Get,
            Self::UserSubscriptionStatus => HttpMethod::Get,
            Self::CreateFolder
            | Self::CopyFile(_)
            | Self::MoveFile(_)
            | Self::CreateShortcut
            | Self::UploadFile
            | Self::UploadPrepare
            | Self::UploadPart
            | Self::UploadFinish
            | Self::CreateImportTask
            | Self::CreateExportTask
            | Self::UploadMedia
            | Self::UploadMediaPrepare
            | Self::UploadMediaPart
            | Self::UploadMediaFinish
            | Self::CreateFileVersion(_)
            | Self::SubscribeFile(_)
            | Self::CreatePermissionMember(_)
            | Self::BatchCreatePermissionMember(_)
            | Self::TransferOwner(_)
            | Self::CreatePublicPassword(_)
            | Self::CreateComment(_)
            | Self::CreateCommentReply(_, _)
            | Self::UserSubscription
            | Self::UpdateCommentReaction(_)
            | Self::CreateFileSubscription(_)
            | Self::MediaUploadTasks
            | Self::CreateMediaShareLink(_)
            | Self::BatchQueryMetas
            | Self::BatchQueryComments(_) => HttpMethod::Post,
            Self::UpdatePermissionMember(_, _)
            | Self::UpdatePublicPassword(_)
            | Self::UpdateCommentReply(_, _, _) => HttpMethod::Put,
            Self::UpdatePublicPermission(_)
            | Self::PatchComment(_, _)
            | Self::UpdateFileSubscription(_, _)
            | Self::UpdatePublicPermissionV2(_) => HttpMethod::Patch,
            Self::DeleteFile(_)
            | Self::DeleteFileVersion(_, _)
            | Self::DeleteFileSubscribe(_)
            | Self::DeletePermissionMember(_, _)
            | Self::DeletePublicPassword(_)
            | Self::DeleteCommentReply(_, _, _) => HttpMethod::Delete,
            Self::UserRemoveSubscription => HttpMethod::Delete,
        }
    }

    // supported_access_token_types 使用 trait 默认实现(User + Tenant)
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::common::api_endpoints::test_support::catalog_semantics_snapshot;

    #[test]
    fn drive_catalog_semantics_snapshots() {
        insta::assert_snapshot!(
            "ccm_drive_explorer_old_catalog_semantics",
            catalog_semantics_snapshot::<CcmDriveExplorerApiOld>()
        );
        insta::assert_snapshot!(
            "ccm_drive_explorer_catalog_semantics",
            catalog_semantics_snapshot::<CcmDriveExplorerApi>()
        );
        insta::assert_snapshot!(
            "permission_catalog_semantics",
            catalog_semantics_snapshot::<PermissionApi>()
        );
        insta::assert_snapshot!(
            "permission_old_catalog_semantics",
            catalog_semantics_snapshot::<PermissionApiOld>()
        );
        insta::assert_snapshot!(
            "drive_catalog_semantics",
            catalog_semantics_snapshot::<DriveApi>()
        );
    }
}