wisski-cloud-distillery/internal/wisski/ingredient/php/extras/pathbuilder.go
Tom a9572e6613 phpx/server: improve wire format
This commit updates the wire format of the phpx server. Instead of being
string-based, messages sent back and forth between go and php are now
base64-encoded DEFLATEd strings. This makes them a lot smaller and
faster to send.
2023-05-01 15:50:21 +02:00

61 lines
1.8 KiB
Go

package extras
import (
"context"
_ "embed"
"github.com/FAU-CDI/wisski-distillery/internal/phpx"
"github.com/FAU-CDI/wisski-distillery/internal/status"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/php"
"golang.org/x/exp/slices"
)
type Pathbuilder struct {
ingredient.Base
Dependencies struct {
PHP *php.PHP
}
}
var (
_ ingredient.WissKIFetcher = (*Pathbuilder)(nil)
)
//go:embed pathbuilder.php
var pathbuilderPHP string
// All returns the ids of all pathbuilders in consistent order.
//
// server is the server to fetch the pathbuilders from, any may be nil.
func (pathbuilder *Pathbuilder) All(ctx context.Context, server *phpx.Server) (ids []string, err error) {
err = pathbuilder.Dependencies.PHP.ExecScript(ctx, server, &ids, pathbuilderPHP, "all_list")
slices.Sort(ids)
return
}
// Get returns a single pathbuilder as xml.
// If it does not exist, it returns the empty string and nil error.
//
// server is the server to fetch the pathbuilders from, any may be nil.
func (pathbuilder *Pathbuilder) Get(ctx context.Context, server *phpx.Server, id string) (xml string, err error) {
err = pathbuilder.Dependencies.PHP.ExecScript(ctx, server, &xml, pathbuilderPHP, "one_xml", id)
return
}
// GetAll returns all pathbuilders serialized as xml
//
// server is the server to fetch the pathbuilders from, any may be nil.
func (pathbuilder *Pathbuilder) GetAll(ctx context.Context, server *phpx.Server) (pathbuilders map[string]string, err error) {
err = pathbuilder.Dependencies.PHP.ExecScript(ctx, server, &pathbuilders, pathbuilderPHP, "all_xml")
return
}
func (pathbuilder *Pathbuilder) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
if flags.Quick {
return
}
info.Pathbuilders, err = pathbuilder.GetAll(flags.Context, flags.Server)
return
}