aboutsummaryrefslogtreecommitdiff
path: root/cmd/xesite/internalapi.go
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2024-02-18 13:34:51 -0500
committerXe Iaso <me@xeiaso.net>2024-02-18 13:34:51 -0500
commit8d63fd1b351cf9ffd99555b21017cc503dd1d0fe (patch)
treee642b17c4a445006dc0e92025725ebf430f932b0 /cmd/xesite/internalapi.go
parent5a4d6d92e9d3c1483104f2adcc9085b64bd1871f (diff)
downloadxesite-8d63fd1b351cf9ffd99555b21017cc503dd1d0fe.tar.xz
xesite-8d63fd1b351cf9ffd99555b21017cc503dd1d0fe.zip
add an external API
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd/xesite/internalapi.go')
-rw-r--r--cmd/xesite/internalapi.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/cmd/xesite/internalapi.go b/cmd/xesite/internalapi.go
index 7d1ebcb..99516fc 100644
--- a/cmd/xesite/internalapi.go
+++ b/cmd/xesite/internalapi.go
@@ -6,9 +6,17 @@ import (
"log"
"net"
"net/http"
+ "os"
+ "os/exec"
"path/filepath"
+ "runtime"
+ "github.com/twitchtv/twirp"
+ "google.golang.org/protobuf/types/known/emptypb"
+ "google.golang.org/protobuf/types/known/timestamppb"
+ "xeiaso.net/v4/internal/adminpb"
"xeiaso.net/v4/internal/lume"
+ "xeiaso.net/v4/pb"
)
func internalAPI(fs *lume.FS) {
@@ -26,6 +34,8 @@ func internalAPI(fs *lume.FS) {
http.ServeFile(w, r, filepath.Join(*dataDir, "site.zip"))
})
+ mux.Handle(adminpb.AdminPathPrefix, adminpb.NewAdminServer(&AdminAPI{fs: fs}))
+
ln, err := net.Listen("tcp", ":80")
if err != nil {
log.Fatal(err)
@@ -33,3 +43,28 @@ func internalAPI(fs *lume.FS) {
http.Serve(ln, mux)
}
+
+type AdminAPI struct {
+ fs *lume.FS
+}
+
+func (aa *AdminAPI) Rebuild(ctx context.Context, _ *emptypb.Empty) (*pb.BuildInfo, error) {
+ deno, err := exec.LookPath("deno")
+ if err != nil {
+ return nil, twirp.InternalErrorf("can't find deno in $PATH: %w", err)
+ }
+
+ result := &pb.BuildInfo{
+ GoVersion: runtime.Version(),
+ DenoVersion: deno,
+ XesiteVersion: os.Args[0],
+ }
+
+ if err := aa.fs.Update(ctx); err != nil {
+ return nil, twirp.InternalErrorWith(err)
+ }
+
+ result.BuildTime = timestamppb.Now()
+
+ return result, nil
+}