updateMetadata 更新元数据(内部使用)
(path string)
| 162 | |
| 163 | // updateMetadata 更新元数据(内部使用) |
| 164 | func (m *PlanFileManager) updateMetadata(path string) error { |
| 165 | // 保存简单的元数据索引 |
| 166 | metadataPath := filepath.Join(m.basePath, ".metadata.json") |
| 167 | |
| 168 | var metadata map[string]PlanFileMetadata |
| 169 | if data, err := os.ReadFile(metadataPath); err == nil { |
| 170 | _ = json.Unmarshal(data, &metadata) |
| 171 | } |
| 172 | if metadata == nil { |
| 173 | metadata = make(map[string]PlanFileMetadata) |
| 174 | } |
| 175 | |
| 176 | name := strings.TrimSuffix(filepath.Base(path), ".md") |
| 177 | now := time.Now() |
| 178 | |
| 179 | if existing, ok := metadata[name]; ok { |
| 180 | existing.UpdatedAt = now |
| 181 | metadata[name] = existing |
| 182 | } else { |
| 183 | metadata[name] = PlanFileMetadata{ |
| 184 | ID: name, |
| 185 | Name: name, |
| 186 | Path: path, |
| 187 | CreatedAt: now, |
| 188 | UpdatedAt: now, |
| 189 | Status: "active", |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | data, err := json.MarshalIndent(metadata, "", " ") |
| 194 | if err != nil { |
| 195 | return err |
| 196 | } |
| 197 | |
| 198 | return os.WriteFile(metadataPath, data, 0644) |
| 199 | } |
| 200 | |
| 201 | // generatePlanName 生成随机的计划名称 |
| 202 | // 格式: adjective-adjective-noun |