Add LoadResources() to API
This commit is contained in:
parent
e50c8430be
commit
ec6d216346
26
api/resources.go
Normal file
26
api/resources.go
Normal file
@ -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
|
||||
}
|
2
go.mod
2
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
|
||||
|
4
go.sum
4
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=
|
||||
|
25
socket.go
25
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
|
||||
|
Loading…
Reference in New Issue
Block a user