Oauth. Car Backups.

This commit is contained in:
2026-02-04 17:01:54 -06:00
parent 486c07f2d4
commit 4ed5d821da
14 changed files with 524 additions and 62 deletions

View File

@@ -25,6 +25,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"os"
"slices"
"time"
@@ -104,6 +105,32 @@ func NewPdsFromDid(id string) (*Pds, error) {
return ret, ret.unpack()
}
func (p *Pds) Backup() (string, int64, error) {
carPath := helpers.Path(viper.GetString("data"), p.Did.String()+".car")
srcStat, err := os.Stat(carPath)
if err != nil {
return "", 0, fmt.Errorf("car file not found: %w", err)
}
if !srcStat.Mode().IsRegular() {
return "", 0, fmt.Errorf("%s is not a regular file", carPath)
}
source, err := os.Open(carPath)
if err != nil {
return "", 0, fmt.Errorf("error opening car file: %w", err)
}
defer source.Close()
bkupName := fmt.Sprintf("%s%s.car", p.Did.String(), time.Now().Format("20060102150405"))
bkupPath := helpers.Path(viper.GetString("backup"), bkupName)
dest, err := os.Create(bkupPath)
if err != nil {
return "", 0, fmt.Errorf("error creating backup file: %w", err)
}
defer dest.Close()
bt, err := io.Copy(dest, source)
return bkupName, bt, err
}
func (p *Pds) unpack() error {
ctx := context.Background()
fi, err := os.Open(p.localPath)