MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / GetScriptMetadata

Function GetScriptMetadata

internal/plugins/communityscripts/scripts.go:396–431  ·  view source on GitHub ↗

GetScriptMetadata fetches and parses the metadata for a specific script.

(metadataURL string)

Source from the content-addressed store, hash-verified

394
395// GetScriptMetadata fetches and parses the metadata for a specific script.
396func 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.
434func FetchScripts() ([]Script, error) {

Callers

nothing calls this directly

Calls 7

getPluginCacheFunction · 0.85
fetchPocketBaseFunction · 0.85
getScriptsLoggerFunction · 0.70
mapPocketBaseRecordFunction · 0.70
GetMethod · 0.65
DebugMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected