MCPcopy
hub / github.com/geekjourneyx/md2wechat-skill / CreateDraftFromFile

Method CreateDraftFromFile

internal/draft/service.go:80–116  ·  view source on GitHub ↗

CreateDraftFromFile 从 JSON 文件创建草稿

(jsonFile string)

Source from the content-addressed store, hash-verified

78
79// CreateDraftFromFile 从 JSON 文件创建草稿
80func (s *Service) CreateDraftFromFile(jsonFile string) (*DraftResult, error) {
81 s.log.Info("creating draft from file", zap.String("file", jsonFile))
82
83 // 读取 JSON 文件
84 data, err := os.ReadFile(jsonFile)
85 if err != nil {
86 return nil, fmt.Errorf("read file: %w", err)
87 }
88
89 // 解析请求
90 var req DraftRequest
91 if err := json.Unmarshal(data, &req); err != nil {
92 return nil, fmt.Errorf("parse json: %w", err)
93 }
94
95 // 验证
96 if len(req.Articles) == 0 {
97 return nil, fmt.Errorf("no articles in request")
98 }
99
100 // 转换为 SDK 格式
101 articles, err := buildSDKArticles(req.Articles)
102 if err != nil {
103 return nil, err
104 }
105
106 // 调用微信 API
107 result, err := s.ws.CreateDraft(articles)
108 if err != nil {
109 return nil, err
110 }
111
112 return &DraftResult{
113 MediaID: result.MediaID,
114 DraftURL: result.DraftURL,
115 }, nil
116}
117
118// CreateDraft 创建草稿
119func (s *Service) CreateDraft(articles []Article) (*DraftResult, error) {

Callers 2

main.goFile · 0.80

Calls 3

buildSDKArticlesFunction · 0.85
CreateDraftMethod · 0.65
StringMethod · 0.45

Tested by 1