GetScriptMetadata fetches and parses the metadata for a specific script.
(metadataURL string)
| 394 | |
| 395 | // GetScriptMetadata fetches and parses the metadata for a specific script. |
| 396 | func GetScriptMetadata(metadataURL string) (*Script, error) { |
| 397 | // Generate a cache key based on the URL |
| 398 | cacheKey := ScriptCacheKeyPrefix + strings.ReplaceAll(metadataURL, "/", "_") |
| 399 | |
| 400 | // Check cache first |
| 401 | c := getPluginCache() |
| 402 | |
| 403 | var cachedScript Script |
| 404 | |
| 405 | found, err := c.Get(cacheKey, &cachedScript) |
| 406 | if err != nil { |
| 407 | getScriptsLogger().Debug("Cache error for script %s: %v", metadataURL, err) |
| 408 | } else if found && cachedScript.Name != "" { |
| 409 | getScriptsLogger().Debug("Using cached script metadata for %s", cachedScript.Name) |
| 410 | |
| 411 | return &cachedScript, nil |
| 412 | } |
| 413 | |
| 414 | var record pocketBaseScriptRecord |
| 415 | if err := fetchPocketBase(metadataURL, &record); err != nil { |
| 416 | return nil, fmt.Errorf("failed to fetch script metadata: %w", err) |
| 417 | } |
| 418 | |
| 419 | script := mapPocketBaseRecord(record) |
| 420 | |
| 421 | // Cache the script metadata |
| 422 | if script.Name != "" && script.ScriptPath != "" { |
| 423 | if err := c.Set(cacheKey, script, ScriptMetadataTTL); err != nil { |
| 424 | getScriptsLogger().Debug("Failed to cache script metadata for %s: %v", script.Name, err) |
| 425 | } else { |
| 426 | getScriptsLogger().Debug("Cached script metadata for %s", script.Name) |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | return &script, nil |
| 431 | } |
| 432 | |
| 433 | // FetchScripts fetches all available scripts from the repository. |
| 434 | func FetchScripts() ([]Script, error) { |
nothing calls this directly
no test coverage detected