feat: support flutter web

This commit is contained in:
levi authored and monkeyWie committed 2022-10-27 13:58:43 +08:00
1 parent c4a30dc4c2
commit 4d4d3b446a
39 files changed
+450 -299

No files matched your search

+7 -7
View File
@@ -2,12 +2,12 @@ package download
import (
"errors"
"github.com/monkeyWie/gopeed-core/internal/controller"
"github.com/monkeyWie/gopeed-core/internal/fetcher"
"github.com/monkeyWie/gopeed-core/internal/protocol/bt"
"github.com/monkeyWie/gopeed-core/internal/protocol/http"
"github.com/monkeyWie/gopeed-core/pkg/base"
"github.com/monkeyWie/gopeed-core/pkg/util"
"github.com/monkeyWie/gopeed/internal/controller"
"github.com/monkeyWie/gopeed/internal/fetcher"
"github.com/monkeyWie/gopeed/internal/protocol/bt"
"github.com/monkeyWie/gopeed/internal/protocol/http"
"github.com/monkeyWie/gopeed/pkg/base"
"github.com/monkeyWie/gopeed/pkg/util"
"strings"
"sync"
"sync/atomic"
@@ -380,7 +380,7 @@ func (d *Downloader) GetTasks() []*Task {
return d.tasks
}
func (d *Downloader) GetConfig(v any) error {
func (d *Downloader) GetConfig(v any) (bool, error) {
return d.storage.Get(bucketConfig, "config", v)
}
+2 -2
View File
@@ -1,8 +1,8 @@
package download
import (
"github.com/monkeyWie/gopeed-core/internal/test"
"github.com/monkeyWie/gopeed-core/pkg/base"
"github.com/monkeyWie/gopeed/internal/test"
"github.com/monkeyWie/gopeed/pkg/base"
"reflect"
"sync"
"testing"
+16 -7
View File
@@ -11,7 +11,7 @@ import (
type Storage interface {
Setup(buckets []string) error
Put(bucket string, key string, v any) error
Get(bucket string, key string, v any) error
Get(bucket string, key string, v any) (bool, error)
List(bucket string, v any) error
Pop(bucket string, key string, v any) error
Delete(bucket string, key string) error
@@ -67,9 +67,12 @@ func (n *MemStorage) Put(bucket string, key string, v any) error {
return nil
}
func (n *MemStorage) Get(bucket string, key string, v any) error {
changeValue(v, memData[bucket][key])
return nil
func (n *MemStorage) Get(bucket string, key string, v any) (bool, error) {
if dv, ok := memData[bucket][key]; ok {
changeValue(v, dv)
return true, nil
}
return false, nil
}
func (n *MemStorage) List(bucket string, v any) error {
@@ -147,7 +150,7 @@ func (b *BoltStorage) Put(bucket string, key string, v any) error {
})
}
func (b *BoltStorage) Get(bucket string, key string, v any) error {
func (b *BoltStorage) Get(bucket string, key string, v any) (bool, error) {
var data []byte
err := b.db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(bucket))
@@ -155,9 +158,15 @@ func (b *BoltStorage) Get(bucket string, key string, v any) error {
return nil
})
if err != nil {
return err
return false, err
}
return json.Unmarshal(data, v)
if data == nil {
return false, nil
}
if err := json.Unmarshal(data, v); err != nil {
return false, err
}
return true, nil
}
func (b *BoltStorage) List(bucket string, v any) error {
+3 -3
View File
@@ -2,9 +2,9 @@ package download
import (
gonanoid "github.com/matoous/go-nanoid/v2"
"github.com/monkeyWie/gopeed-core/internal/fetcher"
"github.com/monkeyWie/gopeed-core/pkg/base"
"github.com/monkeyWie/gopeed-core/pkg/util"
"github.com/monkeyWie/gopeed/internal/fetcher"
"github.com/monkeyWie/gopeed/pkg/base"
"github.com/monkeyWie/gopeed/pkg/util"
"sync"
"time"
)