diff --git a/shortcuts/common/resource_url.go b/shortcuts/common/resource_url.go index 69345ea9..29ec31c1 100644 --- a/shortcuts/common/resource_url.go +++ b/shortcuts/common/resource_url.go @@ -73,6 +73,9 @@ var urlPathToType = []struct { Type string }{ {"/drive/folder/", "folder"}, + {"/drive/file/", "file"}, + {"/drive/shr/", "folder"}, + {"/chat/drive/", "folder"}, {"/docx/", "docx"}, {"/doc/", "doc"}, {"/sheets/", "sheet"}, diff --git a/shortcuts/common/resource_url_test.go b/shortcuts/common/resource_url_test.go index baa1165f..c0109fe9 100644 --- a/shortcuts/common/resource_url_test.go +++ b/shortcuts/common/resource_url_test.go @@ -28,6 +28,9 @@ func TestParseResourceURL(t *testing.T) { {"wiki", "https://xxx.feishu.cn/wiki/wikcnABC", "wiki", "wikcnABC", true}, {"file", "https://xxx.feishu.cn/file/boxcnABC", "file", "boxcnABC", true}, {"folder", "https://xxx.feishu.cn/drive/folder/fldcnABC", "folder", "fldcnABC", true}, + {"file via /drive/file/", "https://feishu.doubao.com/drive/file/boxcnABC", "file", "boxcnABC", true}, + {"folder via /chat/drive/", "https://feishu.doubao.com/chat/drive/fldcnABC", "folder", "fldcnABC", true}, + {"folder via /drive/shr/", "https://feishu.doubao.com/drive/shr/fldcnABC", "folder", "fldcnABC", true}, {"mindnote", "https://xxx.feishu.cn/mindnote/mncnABC", "mindnote", "mncnABC", true}, {"slides", "https://xxx.feishu.cn/slides/slkcnABC", "slides", "slkcnABC", true}, diff --git a/shortcuts/drive/drive_inspect_test.go b/shortcuts/drive/drive_inspect_test.go index a40cc399..19da7ecb 100644 --- a/shortcuts/drive/drive_inspect_test.go +++ b/shortcuts/drive/drive_inspect_test.go @@ -109,6 +109,45 @@ func TestDriveInspectValidate_ValidWikiURL(t *testing.T) { } } +func TestDriveInspectValidate_ValidDoubaoDriveFileURL(t *testing.T) { + cmd := &cobra.Command{Use: "drive +inspect"} + cmd.Flags().String("url", "", "") + cmd.Flags().String("type", "", "") + _ = cmd.Flags().Set("url", "https://feishu.doubao.com/drive/file/boxcnABC") + + runtime := common.TestNewRuntimeContext(cmd, &core.CliConfig{}) + err := DriveInspect.Validate(context.Background(), runtime) + if err != nil { + t.Fatalf("expected no error, got %v", err) + } +} + +func TestDriveInspectValidate_ValidDoubaoChatDriveFolderURL(t *testing.T) { + cmd := &cobra.Command{Use: "drive +inspect"} + cmd.Flags().String("url", "", "") + cmd.Flags().String("type", "", "") + _ = cmd.Flags().Set("url", "https://feishu.doubao.com/chat/drive/fldcnABC") + + runtime := common.TestNewRuntimeContext(cmd, &core.CliConfig{}) + err := DriveInspect.Validate(context.Background(), runtime) + if err != nil { + t.Fatalf("expected no error, got %v", err) + } +} + +func TestDriveInspectValidate_ValidDoubaoDriveShareFolderURL(t *testing.T) { + cmd := &cobra.Command{Use: "drive +inspect"} + cmd.Flags().String("url", "", "") + cmd.Flags().String("type", "", "") + _ = cmd.Flags().Set("url", "https://feishu.doubao.com/drive/shr/fldcnABC") + + runtime := common.TestNewRuntimeContext(cmd, &core.CliConfig{}) + err := DriveInspect.Validate(context.Background(), runtime) + if err != nil { + t.Fatalf("expected no error, got %v", err) + } +} + // --- DryRun tests --- func TestDriveInspectDryRun_DocxURL(t *testing.T) { @@ -235,6 +274,82 @@ func TestDriveInspectDryRun_BareTokenWithType(t *testing.T) { } } +func TestDriveInspectDryRun_DoubaoDriveFileURL(t *testing.T) { + cmd := &cobra.Command{Use: "drive +inspect"} + cmd.Flags().String("url", "", "") + cmd.Flags().String("type", "", "") + _ = cmd.Flags().Set("url", "https://feishu.doubao.com/drive/file/boxcnABC") + + runtime := common.TestNewRuntimeContext(cmd, &core.CliConfig{}) + dry := DriveInspect.DryRun(context.Background(), runtime) + if dry == nil { + t.Fatal("DryRun returned nil") + } + + data, err := json.Marshal(dry) + if err != nil { + t.Fatalf("marshal dry run: %v", err) + } + + var got struct { + API []struct { + Body map[string]interface{} `json:"body"` + } `json:"api"` + } + if err := json.Unmarshal(data, &got); err != nil { + t.Fatalf("unmarshal dry run: %v", err) + } + reqDocs, ok := got.API[0].Body["request_docs"].([]interface{}) + if !ok || len(reqDocs) != 1 { + t.Fatalf("expected request_docs with 1 entry, got %v", got.API[0].Body["request_docs"]) + } + doc, _ := reqDocs[0].(map[string]interface{}) + if doc["doc_token"] != "boxcnABC" { + t.Errorf("doc_token = %v, want boxcnABC", doc["doc_token"]) + } + if doc["doc_type"] != "file" { + t.Errorf("doc_type = %v, want file", doc["doc_type"]) + } +} + +func TestDriveInspectDryRun_DoubaoDriveShareFolderURL(t *testing.T) { + cmd := &cobra.Command{Use: "drive +inspect"} + cmd.Flags().String("url", "", "") + cmd.Flags().String("type", "", "") + _ = cmd.Flags().Set("url", "https://feishu.doubao.com/drive/shr/fldcnABC") + + runtime := common.TestNewRuntimeContext(cmd, &core.CliConfig{}) + dry := DriveInspect.DryRun(context.Background(), runtime) + if dry == nil { + t.Fatal("DryRun returned nil") + } + + data, err := json.Marshal(dry) + if err != nil { + t.Fatalf("marshal dry run: %v", err) + } + + var got struct { + API []struct { + Body map[string]interface{} `json:"body"` + } `json:"api"` + } + if err := json.Unmarshal(data, &got); err != nil { + t.Fatalf("unmarshal dry run: %v", err) + } + reqDocs, ok := got.API[0].Body["request_docs"].([]interface{}) + if !ok || len(reqDocs) != 1 { + t.Fatalf("expected request_docs with 1 entry, got %v", got.API[0].Body["request_docs"]) + } + doc, _ := reqDocs[0].(map[string]interface{}) + if doc["doc_token"] != "fldcnABC" { + t.Errorf("doc_token = %v, want fldcnABC", doc["doc_token"]) + } + if doc["doc_type"] != "folder" { + t.Errorf("doc_type = %v, want folder", doc["doc_type"]) + } +} + // --- Execute tests --- func TestDriveInspectExecute_DocxURL(t *testing.T) { diff --git a/tests/cli_e2e/drive/drive_inspect_dryrun_test.go b/tests/cli_e2e/drive/drive_inspect_dryrun_test.go index 286d6b54..8d375ad3 100644 --- a/tests/cli_e2e/drive/drive_inspect_dryrun_test.go +++ b/tests/cli_e2e/drive/drive_inspect_dryrun_test.go @@ -45,12 +45,30 @@ func TestDriveInspectDryRun_FileURL(t *testing.T) { assertOneStepBatchQuery(t, result) } +func TestDriveInspectDryRun_DoubaoDriveFileURL(t *testing.T) { + setDriveInspectE2EEnv(t) + result := runInspectDryRun(t, "https://feishu.doubao.com/drive/file/boxcnDryRunE2E") + assertOneStepBatchQuery(t, result) +} + func TestDriveInspectDryRun_FolderURL(t *testing.T) { setDriveInspectE2EEnv(t) result := runInspectDryRun(t, "https://xxx.feishu.cn/drive/folder/fldcnDryRunE2E") assertOneStepBatchQuery(t, result) } +func TestDriveInspectDryRun_DoubaoChatDriveFolderURL(t *testing.T) { + setDriveInspectE2EEnv(t) + result := runInspectDryRun(t, "https://feishu.doubao.com/chat/drive/fldcnDryRunE2E") + assertOneStepBatchQuery(t, result) +} + +func TestDriveInspectDryRun_DoubaoDriveShareFolderURL(t *testing.T) { + setDriveInspectE2EEnv(t) + result := runInspectDryRun(t, "https://feishu.doubao.com/drive/shr/fldcnDryRunE2E") + assertOneStepBatchQuery(t, result) +} + func TestDriveInspectDryRun_MindnoteURL(t *testing.T) { setDriveInspectE2EEnv(t) result := runInspectDryRun(t, "https://xxx.feishu.cn/mindnote/mncnDryRunE2E")