diff options
| author | Shulhan <ms@kilabit.info> | 2023-12-09 03:07:15 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-12-09 22:58:18 +0700 |
| commit | 6ce48247a2110492bb46470e9e10fd049d26e1fb (patch) | |
| tree | 486e4b14a445aa8c3fc5e59e988833fba55b3240 | |
| parent | 740a0139c1c8468f66cc5bc0fe27d9b68294d59d (diff) | |
| download | awwan-6ce48247a2110492bb46470e9e10fd049d26e1fb.tar.xz | |
all: reduce the response on HTTP endpoint on GET fs
Previously, the HTTP endpoint for "GET /awwan/api/fs" return the content
of files when the requested node is a directory.
This is cause unnecessary load because when requesting directory we
only need list of file names not the content.
This changes reduce the response by returning only list of node child
without its content, which require update on share module on [Node.JSON].
| -rw-r--r-- | go.mod | 2 | ||||
| -rw-r--r-- | go.sum | 4 | ||||
| -rw-r--r-- | http_server.go | 10 |
3 files changed, 13 insertions, 3 deletions
@@ -8,7 +8,7 @@ go 1.20 require ( git.sr.ht/~shulhan/ciigo v0.10.1 github.com/evanw/esbuild v0.19.8 - github.com/shuLhan/share v0.51.0 + github.com/shuLhan/share v0.51.1-0.20231208192030-ed9a59261448 ) require ( @@ -4,8 +4,8 @@ git.sr.ht/~shulhan/ciigo v0.10.1 h1:J/lZ9Xqretky2fgC0g8Z5HATNqEWWDFkSKUBLyFm83g= git.sr.ht/~shulhan/ciigo v0.10.1/go.mod h1:q6VQ+us4sErIfB0jk4F+VsSBLYK/k9T41X2loC9CBLw= github.com/evanw/esbuild v0.19.8 h1:IJ1CRsv3i4dkjPLo6NEGTMI0DDba7jOlPc6JFzIxtl4= github.com/evanw/esbuild v0.19.8/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48= -github.com/shuLhan/share v0.51.0 h1:WPKRNNWnZPaVTi/o6nUdkAePek2Lbjz5baoq8MU1U+I= -github.com/shuLhan/share v0.51.0/go.mod h1:Zn0zwUdSuu7L2BKaYkVOXwbwxd5Kn6Y2bhohD9Tf0Sc= +github.com/shuLhan/share v0.51.1-0.20231208192030-ed9a59261448 h1:NYa3OAbJ5R0ZIMhHOfbln+DPyAwPBKFwWZwPA8IDhTg= +github.com/shuLhan/share v0.51.1-0.20231208192030-ed9a59261448/go.mod h1:Zn0zwUdSuu7L2BKaYkVOXwbwxd5Kn6Y2bhohD9Tf0Sc= github.com/yuin/goldmark v1.6.0 h1:boZcn2GTjpsynOsC0iJHnBWa4Bi0qzfJjthwauItG68= github.com/yuin/goldmark v1.6.0/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc= diff --git a/http_server.go b/http_server.go index 30fe53a..e83cb2f 100644 --- a/http_server.go +++ b/http_server.go @@ -4,6 +4,7 @@ package awwan import ( + "bytes" "encoding/json" "errors" "fmt" @@ -408,6 +409,15 @@ func (httpd *httpServer) FSGet(epr *libhttp.EndpointRequest) (resb []byte, err e } return nil, err } + if node.IsDir() { + var buf bytes.Buffer + fmt.Fprint(&buf, `{"code":200,"data":`) + resb, _ = node.JSON(0, false, false) + buf.Write(resb) + buf.WriteByte('}') + resb = buf.Bytes() + return resb, nil + } res.Code = http.StatusOK res.Data = node |
