Skip to content

Commit

Permalink
加解密同步优化
Browse files Browse the repository at this point in the history
  • Loading branch information
lyming99 committed Apr 29, 2024
1 parent bdd651f commit bd87453
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class AppController extends MvcController {
void onInitState(fluent.BuildContext context) {
super.onInitState(context);
try {
FlutterDisplayMode.setHighRefreshRate();
if(Platform.isAndroid) {
FlutterDisplayMode.setHighRefreshRate();
}
} catch (e) {
print(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class MobileSyncPasswordSettingsController extends ServiceManagerController {
}

Future<bool> changePwd(String pwd) async{
return serviceManager.cryptService.changeServerPassword(pwd);
var ret = serviceManager.cryptService.changeServerPassword(pwd);
await serviceManager.recordSyncService.reUploadDbData();
return ret;
}
}
2 changes: 1 addition & 1 deletion lib/service/api/delta_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class DbUploadVO<T> {
Map<String, dynamic> toJson() {
return {
'clientId': clientId,
'items': items?.map((e) => e.toMap()),
'items': items?.map((e) => e.toMap()).toList(),
'securityVersion': securityVersion,
};
}
Expand Down
6 changes: 3 additions & 3 deletions lib/service/api/doc_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class DocApi {
var docState = data["data"];
return LockResult()
..dataId = docId
..docState = docState['docState']
..securityVersion = docState['securityVersion']
..updateTime = docState['updateTime'];
..docState = docState?['docState']
..securityVersion = docState?['securityVersion']
..updateTime = docState?['updateTime'];
}
return null;
}
Expand Down
18 changes: 18 additions & 0 deletions lib/service/crypt/crypt_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ class CryptService {
passwordMap.keys.reduce((value, element) => max(value, element))];
}

bool hasPwd(int version) {
if (version == -1 && passwordMap.isNotEmpty) {
version =
passwordMap.keys.reduce((value, element) => max(value, element));
}
var pwd = passwordMap[version]?.password;
if (pwd == null) {
return false;
}
return true;
}

Uint8List encode(Uint8List data, [int version = -1]) {
if (version == -1 && passwordMap.isNotEmpty) {
version =
Expand Down Expand Up @@ -182,6 +194,9 @@ class CryptService {
if (input == null || input.isEmpty) {
return input;
}
if (!hasPwd(version)) {
return input;
}
var bytes = utf8.encode(input);
var ret = encode(bytes);
return base64Encode(ret);
Expand All @@ -191,6 +206,9 @@ class CryptService {
if (input == null || input.isEmpty) {
return input;
}
if (!hasPwd(version)) {
return input;
}
var bytes = base64Decode(input);
var ret = decode(bytes, version);
return utf8.decode(ret);
Expand Down
2 changes: 2 additions & 0 deletions lib/service/sync/impl/record_sync_service_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ class RecordSyncServiceImpl extends RecordSyncService {
updateTime: e.updateTime,
deleted: e.deleted,
hasUpload: e.hasUpload,
securityVersion:
serviceManager.cryptService.getCurrentPassword()?.version,
))
.toList();
}
Expand Down
4 changes: 4 additions & 0 deletions lib/service/user/user_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/get_utils/get_utils.dart';
import 'package:octo_image/octo_image.dart';
Expand Down Expand Up @@ -52,6 +53,9 @@ class UserService with ChangeNotifier {
if (noteServer == null) {
return null;
}
if(kDebugMode){
return "http://127.0.0.1:9898";
}
return "http://${noteServer.host}:${noteServer.port}";
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ packages:
ydart:
dependency: "direct main"
description:
path: "D:/GitHub/ydart"
path: "/Users/liyuanming/Documents/GitHub/ydart"
relative: false
source: path
version: "1.0.0+1"
Expand Down

0 comments on commit bd87453

Please sign in to comment.