change to /wave/file, update blockid to zoneid

This commit is contained in:
sawka 2024-06-03 13:22:44 -07:00
parent 8f04e0163a
commit f148d7fcf2
2 changed files with 16 additions and 16 deletions

View File

@ -114,19 +114,19 @@ const TerminalView = ({ blockId }: { blockId: string }) => {
if (!termRef.current) {
return;
}
// load data from blockfile
// load data from filestore
const startTs = Date.now();
let loadedBytes = 0;
const localTerm = termRef.current; // avoids devmode double effect running issue (terminal gets created twice)
const usp = new URLSearchParams();
usp.set("blockid", blockId);
usp.set("zoneid", blockId);
usp.set("name", "main");
fetch("/wave/blockfile?" + usp.toString())
fetch("/wave/file?" + usp.toString())
.then((resp) => {
if (resp.ok) {
return resp.arrayBuffer();
}
console.log("error loading blockfile", resp.status, resp.statusText);
console.log("error loading file", resp.status, resp.statusText);
})
.then((data: ArrayBuffer) => {
const uint8View = new Uint8Array(data);
@ -139,7 +139,7 @@ const TerminalView = ({ blockId }: { blockId: string }) => {
});
initialLoadRef.current.loaded = true;
initialLoadRef.current.heldData = [];
console.log(`terminal loaded blockfile ${loadedBytes} bytes, ${Date.now() - startTs}ms`);
console.log(`terminal loaded file ${loadedBytes} bytes, ${Date.now() - startTs}ms`);
});
}, [termRef.current]);

22
main.go
View File

@ -72,7 +72,7 @@ func createWindow(windowData *wstore.Window, app *application.App) {
Backdrop: application.MacBackdropTranslucent,
TitleBar: application.MacTitleBarHiddenInset,
},
BackgroundColour: application.NewRGB(0, 0, 0),
BackgroundColour: application.NewRGBA(0, 0, 0, 255),
URL: "/public/index.html?windowid=" + windowData.OID + "&clientid=" + client.OID,
X: windowData.Pos.X,
Y: windowData.Pos.Y,
@ -102,11 +102,11 @@ type waveAssetHandler struct {
AssetHandler http.Handler
}
func serveBlockFile(w http.ResponseWriter, r *http.Request) {
blockId := r.URL.Query().Get("blockid")
func serveWaveFile(w http.ResponseWriter, r *http.Request) {
zoneId := r.URL.Query().Get("zoneid")
name := r.URL.Query().Get("name")
if _, err := uuid.Parse(blockId); err != nil {
http.Error(w, fmt.Sprintf("invalid blockid: %v", err), http.StatusBadRequest)
if _, err := uuid.Parse(zoneId); err != nil {
http.Error(w, fmt.Sprintf("invalid zoneid: %v", err), http.StatusBadRequest)
return
}
if name == "" {
@ -114,7 +114,7 @@ func serveBlockFile(w http.ResponseWriter, r *http.Request) {
return
}
file, err := filestore.WFS.Stat(r.Context(), blockId, name)
file, err := filestore.WFS.Stat(r.Context(), zoneId, name)
if err == fs.ErrNotExist {
http.NotFound(w, r)
return
@ -129,16 +129,16 @@ func serveBlockFile(w http.ResponseWriter, r *http.Request) {
}
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Length", fmt.Sprintf("%d", file.Size))
w.Header().Set("X-BlockFileInfo", base64.StdEncoding.EncodeToString(jsonFileBArr))
w.Header().Set("X-ZoneFileInfo", base64.StdEncoding.EncodeToString(jsonFileBArr))
w.Header().Set("Last-Modified", time.UnixMilli(file.ModTs).UTC().Format(http.TimeFormat))
for offset := file.DataStartIdx(); offset < file.Size; offset += filestore.DefaultPartDataSize {
_, data, err := filestore.WFS.ReadAt(r.Context(), blockId, name, offset, filestore.DefaultPartDataSize)
_, data, err := filestore.WFS.ReadAt(r.Context(), zoneId, name, offset, filestore.DefaultPartDataSize)
if err != nil {
if offset == 0 {
http.Error(w, fmt.Sprintf("error reading file: %v", err), http.StatusInternalServerError)
} else {
// nothing to do, the headers have already been sent
log.Printf("error reading file %s/%s @ %d: %v\n", blockId, name, offset, err)
log.Printf("error reading file %s/%s @ %d: %v\n", zoneId, name, offset, err)
}
return
}
@ -154,8 +154,8 @@ func serveWaveUrls(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, fileName)
return
}
if r.URL.Path == "/wave/blockfile" {
serveBlockFile(w, r)
if r.URL.Path == "/wave/file" {
serveWaveFile(w, r)
return
}
http.NotFound(w, r)