Skip to content

Commit

Permalink
update to 1.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
fregie committed Aug 7, 2023
1 parent 6aa3626 commit fc9daa5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
2 changes: 2 additions & 0 deletions lib/state_model.dart
Expand Up @@ -159,6 +159,7 @@ class AssetModel extends ChangeNotifier {
localHasMore = true;
localAssets = [];
notifyListeners();
stateModel.setNotSyncedPhotos([]);
await getLocalPhotos();
}

Expand All @@ -170,6 +171,7 @@ class AssetModel extends ChangeNotifier {
remoteAssets = [];
notifyListeners();
remoteGetting = null;
stateModel.setNotSyncedPhotos([]);
await getRemotePhotos();
}

Expand Down
27 changes: 14 additions & 13 deletions lib/storage/storage.dart
Expand Up @@ -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();
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion server/drive/baidu/baidu.go
Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions server/drive/baidu/fs.go
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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
Expand Down

0 comments on commit fc9daa5

Please sign in to comment.