Borg/cmd/pwa.go
google-labs-jules[bot] efee04bfdb feat: Add PWA download and serve commands
This commit introduces two new commands: `pwa` and `serve`.

The `pwa` command downloads a Progressive Web Application (PWA) from a given URL. It discovers the PWA's manifest, downloads the assets referenced in the manifest (start URL and icons), and packages them into a single `.tar` file.

The `serve` command takes a `.tar` file created by the `pwa` command and serves its contents using a standard Go HTTP file server. It unpacks the tarball into an in-memory filesystem, making it a self-contained and efficient way to host the downloaded PWA.
2025-10-31 20:32:46 +00:00

50 lines
1.2 KiB
Go

package cmd
import (
"fmt"
"os"
"borg-data-collector/pkg/pwa"
"github.com/spf13/cobra"
)
// pwaCmd represents the pwa command
var pwaCmd = &cobra.Command{
Use: "pwa [url]",
Short: "Download a PWA from a URL",
Long: `Downloads a Progressive Web Application (PWA) from a given URL by finding its manifest.`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
pwaURL := args[0]
outputFile, _ := cmd.Flags().GetString("output")
fmt.Println("Finding PWA manifest...")
manifestURL, err := pwa.FindManifestURL(pwaURL)
if err != nil {
fmt.Printf("Error finding manifest: %v\n", err)
return
}
fmt.Printf("Found manifest: %s\n", manifestURL)
fmt.Println("Downloading and packaging PWA...")
pwaData, err := pwa.DownloadAndPackagePWA(pwaURL, manifestURL)
if err != nil {
fmt.Printf("Error downloading and packaging PWA: %v\n", err)
return
}
err = os.WriteFile(outputFile, pwaData, 0644)
if err != nil {
fmt.Printf("Error writing PWA to file: %v\n", err)
return
}
fmt.Printf("PWA saved to %s\n", outputFile)
},
}
func init() {
rootCmd.AddCommand(pwaCmd)
pwaCmd.PersistentFlags().String("output", "pwa.tar", "Output file for the PWA tarball")
}