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 /http_server.go | |
| 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].
Diffstat (limited to 'http_server.go')
| -rw-r--r-- | http_server.go | 10 |
1 files changed, 10 insertions, 0 deletions
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 |
