From 851f1975d651a776bfe341e48b2c118ba55c9f0d Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Tue, 30 Aug 2022 12:13:22 -0700 Subject: [PATCH] Add LoadResources() to API --- api/resources.go | 26 ++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 4 ++-- socket.go | 25 +++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 api/resources.go diff --git a/api/resources.go b/api/resources.go new file mode 100644 index 0000000..8690ddc --- /dev/null +++ b/api/resources.go @@ -0,0 +1,26 @@ +package api + +import ( + "context" + + "go.arsenm.dev/infinitime" +) + +// LoadResources loads resources onto the watch from the given +// file path to the resources zip +func (c *Client) LoadResources(ctx context.Context, path string) (<-chan infinitime.ResourceLoadProgress, error) { + progCh := make(chan infinitime.ResourceLoadProgress) + + err := c.client.Call( + ctx, + "FS", + "LoadResources", + path, + progCh, + ) + if err != nil { + return nil, err + } + + return progCh, nil +} diff --git a/go.mod b/go.mod index b99795e..d7eb013 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/mozillazg/go-pinyin v0.19.0 github.com/rs/zerolog v1.26.1 github.com/urfave/cli/v2 v2.3.0 - go.arsenm.dev/infinitime v0.0.0-20220819210252-d199fba93c2f + go.arsenm.dev/infinitime v0.0.0-20220829214316-3e9957d41961 go.arsenm.dev/lrpc v0.0.0-20220513001344-3bcc01fdb6a0 golang.org/x/text v0.3.7 modernc.org/sqlite v1.17.2 diff --git a/go.sum b/go.sum index 76bdf4a..98aeb44 100644 --- a/go.sum +++ b/go.sum @@ -396,8 +396,8 @@ github.com/yuin/goldmark v1.3.8/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1 github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.4 h1:zNWRjYUW32G9KirMXYHQHVNFkXvMI7LpgNW2AgYAoIs= github.com/yuin/goldmark v1.4.4/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg= -go.arsenm.dev/infinitime v0.0.0-20220819210252-d199fba93c2f h1:Np0ZNlgVC5D9NOilN14HJ1mSXM8vl2LYGfK0fZOYUbY= -go.arsenm.dev/infinitime v0.0.0-20220819210252-d199fba93c2f/go.mod h1:K3NJ6fyPv5qqHUedB3MccKOE0whJMJZ80l/yTzzTrgc= +go.arsenm.dev/infinitime v0.0.0-20220829214316-3e9957d41961 h1:UcggI2jru69nHLcj8uDRLhaeUecaokeTjUItvifX4jM= +go.arsenm.dev/infinitime v0.0.0-20220829214316-3e9957d41961/go.mod h1:K3NJ6fyPv5qqHUedB3MccKOE0whJMJZ80l/yTzzTrgc= go.arsenm.dev/lrpc v0.0.0-20220513001344-3bcc01fdb6a0 h1:1K96g1eww+77GeGchwMhd0NTrs7Mk/Hc3M3ItW5NbG4= go.arsenm.dev/lrpc v0.0.0-20220513001344-3bcc01fdb6a0/go.mod h1:goK9z735lfXmqlDxu9qN7FS8t0HJHN3PjyDtCToUY4w= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= diff --git a/socket.go b/socket.go index 5dba567..1e85aa6 100644 --- a/socket.go +++ b/socket.go @@ -424,6 +424,31 @@ func (fs *FS) Download(ctx *server.Context, paths [2]string) error { return nil } +func (fs *FS) LoadResources(ctx *server.Context, path string) error { + resFl, err := os.Open(path) + if err != nil { + return err + } + + progCh, err := infinitime.LoadResources(resFl, fs.fs) + if err != nil { + return err + } + + ch, err := ctx.MakeChannel() + if err != nil { + return err + } + + go func() { + for evt := range progCh { + ch <- evt + } + }() + + return nil +} + func (fs *FS) updateFS() { if fs.fs == nil || updateFS { // Get new FS