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

22
main.go
View File

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