forked from riba2534/feishu-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_wiki_node.go
More file actions
78 lines (64 loc) · 2.09 KB
/
delete_wiki_node.go
File metadata and controls
78 lines (64 loc) · 2.09 KB
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
package cmd
import (
"fmt"
"github.com/riba2534/feishu-cli/internal/client"
"github.com/riba2534/feishu-cli/internal/config"
"github.com/spf13/cobra"
)
var deleteWikiNodeCmd = &cobra.Command{
Use: "delete <node_token>",
Short: "删除知识库节点",
Long: `删除知识库节点(将节点对应的文档移至回收站)。
参数:
node_token 节点 Token(必填)
警告:
删除操作会将文档移至回收站,请谨慎操作!
注意:
- 此命令通过 Drive API 删除节点对应的文档
- 删除操作可能是异步的,会返回任务 ID
示例:
# 删除节点
feishu-cli wiki delete wikcnXXXXXX`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := config.Validate(); err != nil {
return err
}
nodeToken, err := extractWikiToken(args[0])
if err != nil {
return err
}
force, _ := cmd.Flags().GetBool("force")
// 先获取节点信息以获取 obj_token 和 obj_type
node, err := client.GetWikiNode(nodeToken, resolveOptionalUserToken(cmd))
if err != nil {
return fmt.Errorf("获取节点信息失败: %w", err)
}
// 危险操作确认
if !force {
if !confirmAction(fmt.Sprintf("确定要删除知识库节点 \"%s\" (%s) 吗?此操作会将文档移至回收站", node.Title, nodeToken)) {
fmt.Println("操作已取消")
return nil
}
}
// 通过 Drive API 删除对应的文档
taskID, err := client.DeleteFile(node.ObjToken, node.ObjType)
if err != nil {
return err
}
fmt.Printf("知识库节点删除操作已提交!\n")
fmt.Printf(" 节点 Token: %s\n", nodeToken)
fmt.Printf(" 文档 Token: %s\n", node.ObjToken)
fmt.Printf(" 文档类型: %s\n", node.ObjType)
fmt.Printf(" 标题: %s\n", node.Title)
if taskID != "" {
fmt.Printf(" 任务 ID: %s\n", taskID)
}
return nil
},
}
func init() {
wikiCmd.AddCommand(deleteWikiNodeCmd)
deleteWikiNodeCmd.Flags().BoolP("force", "f", false, "跳过确认直接删除")
deleteWikiNodeCmd.Flags().String("user-access-token", "", "User Access Token(可选,用于访问个人知识库)")
}