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

Function GetScriptMetadataFiles

internal/plugins/communityscripts/scripts.go:340–393  ·  view source on GitHub ↗

GetScriptMetadataFiles fetches the list of script metadata JSON files from the repository.

()

Source from the content-addressed store, hash-verified

338
339// GetScriptMetadataFiles fetches the list of script metadata JSON files from the repository.
340func GetScriptMetadataFiles() ([]GitHubContent, error) {
341 // Check cache first
342 c := getPluginCache()
343
344 var cachedFiles []GitHubContent
345
346 found, err := c.Get(ScriptMetadataListCacheKey, &cachedFiles)
347 if err != nil {
348 getScriptsLogger().Debug("Cache error for script list: %v", err)
349 } else if found && len(cachedFiles) > 0 {
350 getScriptsLogger().Debug("Using cached script list (%d items)", len(cachedFiles))
351
352 return cachedFiles, nil
353 }
354
355 const perPage = 200
356 page := 1
357 records := []GitHubContent{}
358
359 for {
360 endpoint := fmt.Sprintf("%s/script_scripts/records?perPage=%d&page=%d&sort=slug", MetadataPocketBaseAPI, perPage, page)
361
362 var response pocketBaseResponse
363 if err := fetchPocketBase(endpoint, &response); err != nil {
364 return nil, fmt.Errorf("failed to fetch script metadata list: %w", err)
365 }
366
367 for _, item := range response.Items {
368 records = append(records, GitHubContent{
369 Name: item.Slug,
370 Path: "script_scripts/" + item.ID,
371 Type: "record",
372 DownloadURL: MetadataPocketBaseAPI + "/script_scripts/records/" + item.ID + "?expand=type",
373 })
374 }
375
376 if page >= response.TotalPages || len(response.Items) == 0 {
377 break
378 }
379
380 page++
381 }
382
383 // Cache the results
384 if len(records) > 0 {
385 if err := c.Set(ScriptMetadataListCacheKey, records, ScriptListTTL); err != nil {
386 getScriptsLogger().Debug("Failed to cache script list: %v", err)
387 } else {
388 getScriptsLogger().Debug("Cached script list with %d items", len(records))
389 }
390 }
391
392 return records, nil
393}
394
395// GetScriptMetadata fetches and parses the metadata for a specific script.
396func GetScriptMetadata(metadataURL string) (*Script, error) {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected