diff --git a/lib/state_model.dart b/lib/state_model.dart index a65e1ed..bfc28fc 100644 --- a/lib/state_model.dart +++ b/lib/state_model.dart @@ -159,6 +159,7 @@ class AssetModel extends ChangeNotifier { localHasMore = true; localAssets = []; notifyListeners(); + stateModel.setNotSyncedPhotos([]); await getLocalPhotos(); } @@ -170,6 +171,7 @@ class AssetModel extends ChangeNotifier { remoteAssets = []; notifyListeners(); remoteGetting = null; + stateModel.setNotSyncedPhotos([]); await getRemotePhotos(); } diff --git a/lib/storage/storage.dart b/lib/storage/storage.dart index 466067e..e05cdd1 100644 --- a/lib/storage/storage.dart +++ b/lib/storage/storage.dart @@ -107,6 +107,20 @@ class RemoteStorage { final thumbLen = thumbnailData!.length; final totalLen = imgLen + thumbLen; stateModel.updateUploadProgress(asset.id, uploaded, totalLen); + + final thumbRsp = await http.post( + Uri.parse("$httpBaseUrl/thumbnail/$name"), + body: thumbnailData, + headers: { + 'Image-Date': dateStr, + }, + ); + stateModel.updateUploadProgress(asset.id, uploaded + thumbLen, totalLen); + if (thumbRsp.statusCode != 200) { + stateModel.finishUpload(asset.id, false); + throw Exception("upload thumbnail failed: ${thumbRsp.statusCode}"); + } + var req = http.StreamedRequest("POST", Uri.parse("$httpBaseUrl/$name")); req.headers['Image-Date'] = dateStr; req.contentLength = await file.length(); @@ -123,19 +137,6 @@ class RemoteStorage { final body = await response.stream.bytesToString(); throw Exception("upload failed: [${response.statusCode}] $body"); } - - final thumbRsp = await http.post( - Uri.parse("$httpBaseUrl/thumbnail/$name"), - body: thumbnailData, - headers: { - 'Image-Date': dateStr, - }, - ); - stateModel.updateUploadProgress(asset.id, uploaded + thumbLen, totalLen); - if (thumbRsp.statusCode != 200) { - stateModel.finishUpload(asset.id, false); - throw Exception("upload thumbnail failed: ${thumbRsp.statusCode}"); - } stateModel.finishUpload(asset.id, true); } diff --git a/pubspec.yaml b/pubspec.yaml index 7a0ed3d..36723f7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.3.3+17 +version: 1.3.4+18 environment: sdk: '>=2.19.1 <3.0.0' diff --git a/server/drive/baidu/baidu.go b/server/drive/baidu/baidu.go index 8f9f62c..159db2f 100644 --- a/server/drive/baidu/baidu.go +++ b/server/drive/baidu/baidu.go @@ -437,7 +437,7 @@ func (d *BaiduNetdisk) Range(dir string, deal func(fs.FileInfo) bool) error { } fullpath := filepath.ToSlash(filepath.Join(d.rootPath, dir)) if fullpath == d.rootPath { - d.cacheDir() + d.cacheDir(true) } err := d.rangeFullDir(fullpath, deal) return err diff --git a/server/drive/baidu/fs.go b/server/drive/baidu/fs.go index 374f492..2d65585 100644 --- a/server/drive/baidu/fs.go +++ b/server/drive/baidu/fs.go @@ -119,14 +119,12 @@ type fsNode struct { UpdateTime time.Time } -func (d *BaiduNetdisk) cacheDir() error { - ok := d.cacheRLock.TryLock() - if !ok { - d.cacheRLock.RLock() - d.cacheRLock.RUnlock() +func (d *BaiduNetdisk) cacheDir(force bool) error { + d.cacheRLock.Lock() + defer d.cacheRLock.Unlock() + if !force && d.fsCache != nil && time.Since(d.fsCache.UpdateTime) < 10*time.Minute { return nil } - defer d.cacheRLock.Unlock() d.fsCache = &fsNode{ name: "", isDir: true, @@ -215,7 +213,7 @@ func (d *BaiduNetdisk) cacheDir() error { func (d *BaiduNetdisk) getFsID(fullPath string) (uint64, error) { if d.getRootFsNode() == nil { - err := d.cacheDir() + err := d.cacheDir(false) if err != nil { return 0, fmt.Errorf("cache dir error: %v", err) } @@ -231,7 +229,7 @@ RETRY: v, ok := currentDir.children[name] if !ok { if !retried { - err := d.cacheDir() + err := d.cacheDir(true) if err != nil { return 0, fmt.Errorf("cache dir error: %v", err) } @@ -258,7 +256,7 @@ func (d *BaiduNetdisk) rangeFullDir(fullDir string, deal func(fs.FileInfo) bool) eles := strings.Split(fullDir, "/") currentDir := d.getRootFsNode() if currentDir == nil || time.Since(currentDir.UpdateTime) > 10*time.Minute { - err := d.cacheDir() + err := d.cacheDir(true) if err != nil { log.Printf("cache dir error: %v", err) goto NOCACHE