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

Function fetchPocketBase

internal/plugins/communityscripts/scripts.go:272–306  ·  view source on GitHub ↗
(url string, target any)

Source from the content-addressed store, hash-verified

270}
271
272func fetchPocketBase(url string, target any) error {
273 url, err := validateMetadataURL(url)
274 if err != nil {
275 return err
276 }
277
278 req, err := http.NewRequest(http.MethodGet, url, nil)
279 if err != nil {
280 return fmt.Errorf("failed to create request: %w", err)
281 }
282
283 req.Header.Add("User-Agent", "pvetui")
284
285 client := &http.Client{}
286 resp, err := client.Do(req)
287 if err != nil {
288 return fmt.Errorf("failed to fetch metadata: %w", err)
289 }
290
291 defer func() {
292 _ = resp.Body.Close()
293 }()
294
295 if resp.StatusCode != http.StatusOK {
296 body, _ := io.ReadAll(resp.Body)
297
298 return fmt.Errorf("metadata API error: %s - %s", resp.Status, string(body))
299 }
300
301 if err := json.NewDecoder(resp.Body).Decode(target); err != nil {
302 return fmt.Errorf("failed to parse metadata response: %w", err)
303 }
304
305 return nil
306}
307
308// GetScriptCategories returns the available script categories.
309func GetScriptCategories() []ScriptCategory {

Callers 3

GetScriptMetadataFilesFunction · 0.85
GetScriptMetadataFunction · 0.85
FetchScriptsFunction · 0.85

Calls 2

validateMetadataURLFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected