use super::CatalogEndpoint;
use openlark_core::api::{ApiRequest, HttpMethod};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(test, derive(strum_macros::EnumIter))]
pub enum CcmDriveExplorerApiOld {
RootFolderMeta,
FolderMeta(String), File(String), FileSpreadsheets(String), FileCopy(String), FileDocs(String), FolderChildren(String), Folder(String), }
impl CcmDriveExplorerApiOld {
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,
}
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(test, derive(strum_macros::EnumIter))]
pub enum CcmDriveExplorerApi {
RootFolderMeta,
FolderMeta(String), File(String), FileCopy(String), FileDocs(String), FileSpreadsheets(String), FolderChildren(String), Folder,
}
impl CcmDriveExplorerApi {
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(),
}
}
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,
}
}
}
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()
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(test, derive(strum_macros::EnumIter))]
pub enum PermissionApi {
MemberPermitted,
MemberTransfer,
Public,
}
impl PermissionApi {
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
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(test, derive(strum_macros::EnumIter))]
pub enum PermissionApiOld {
MemberPermitted,
MemberTransfer,
Public,
}
impl PermissionApiOld {
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
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(test, derive(strum_macros::EnumIter))]
pub enum DriveApi {
ListFiles,
CreateFolder,
TaskCheck,
BatchQueryMetas,
GetFileStatistics(String), ListFileViewRecords(String), CopyFile(String), MoveFile(String), DeleteFile(String), CreateShortcut,
UploadFile,
UploadPrepare,
UploadPart,
UploadFinish,
DownloadFile(String), CreateImportTask,
GetImportTask(String), CreateExportTask,
GetExportTask(String), DownloadExportFile(String), UploadMedia,
UploadMediaPrepare,
UploadMediaPart,
UploadMediaFinish,
DownloadMedia(String), GetMediaTempDownloadUrls,
CreateFileVersion(String), ListFileVersions(String), GetFileVersion(String, String), DeleteFileVersion(String, String), SubscribeFile(String), GetFileSubscribe(String), DeleteFileSubscribe(String), CreatePermissionMember(String), BatchCreatePermissionMember(String), UpdatePermissionMember(String, String), ListPermissionMembers(String), DeletePermissionMember(String, String), TransferOwner(String), AuthPermissionMember(String), UpdatePublicPermission(String), GetPublicPermission(String), CreatePublicPassword(String), UpdatePublicPassword(String), DeletePublicPassword(String), ListFileComments(String), BatchQueryComments(String), PatchComment(String, String), CreateComment(String), GetComment(String, String), ListCommentReplies(String, String), CreateCommentReply(String, String), UpdateCommentReply(String, String, String), DeleteCommentReply(String, String, String), UserSubscription,
UserRemoveSubscription,
UserSubscriptionStatus,
GetFileSubscription(String, String), CreateFileSubscription(String), UpdateFileSubscription(String, String),
ListFileLikes(String), GetPublicPermissionV2(String), UpdatePublicPermissionV2(String), UpdateCommentReaction(String),
MediaUploadTasks,
MediaUploadTask(String), CreateMediaShareLink(String), GetPublicPassword(String), }
impl DriveApi {
pub fn to_url(&self) -> String {
match self {
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")
}
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")
}
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()
}
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}")
}
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")
}
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")
}
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")
}
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()
}
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}")
}
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")
}
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)
}
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,
}
}
}
#[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>()
);
}
}