generated from dellevin/template
添加点击 最近添加
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import '../models/data_models.dart';
|
||||
|
||||
/// 数据库帮助类 - 管理数据库的创建和版本控制
|
||||
@@ -341,11 +341,11 @@ class DatabaseHelper {
|
||||
'updated_at': row['updated_at']?.toString() ?? now,
|
||||
});
|
||||
} catch (e) {
|
||||
// 忽略迁移失败的记录
|
||||
debugPrint('[DB] 迁移笔记记录失败: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// 升级books表到V3
|
||||
Future<void> _upgradeBooksTableV3(Database db) async {
|
||||
// 备份旧数据
|
||||
@@ -393,7 +393,7 @@ class DatabaseHelper {
|
||||
'is_deleted': 0,
|
||||
});
|
||||
} catch (e) {
|
||||
// 忽略迁移失败的记录
|
||||
debugPrint('[DB] 迁移书籍记录失败: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -448,7 +448,7 @@ class DatabaseHelper {
|
||||
'is_deleted': row['is_deleted'] ?? 0,
|
||||
});
|
||||
} catch (e) {
|
||||
// 忽略迁移失败的记录
|
||||
debugPrint('[DB] 迁移影视记录失败: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,8 +361,9 @@ class ServerDataService {
|
||||
final size = exists ? await file.length() : 0;
|
||||
debugPrint('[Sync] 图片: $relPath (存在=$exists 大小=$size)');
|
||||
if (exists) {
|
||||
request.files.add(await http.MultipartFile(
|
||||
'images', file.readAsBytes().asStream(), size,
|
||||
final bytes = await file.readAsBytes();
|
||||
request.files.add(http.MultipartFile.fromBytes(
|
||||
'images', bytes,
|
||||
filename: relPath,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
@@ -312,18 +311,22 @@ class ServerSyncService {
|
||||
final deviceId = _prefs.deviceId;
|
||||
final appDir = (await getApplicationDocumentsDirectory()).path;
|
||||
|
||||
// 上传数据库
|
||||
// 上传数据库(先关闭连接再读取,避免文件被占用)
|
||||
await DatabaseHelper.instance.close();
|
||||
final dbPath = await DatabaseHelper.instance.databasePath;
|
||||
final request = http.MultipartRequest('POST', Uri.parse('$url/api/sync/upload'));
|
||||
request.fields['code'] = code;
|
||||
request.fields['device_id'] = deviceId;
|
||||
if (dbPath != null && File(dbPath).existsSync()) {
|
||||
request.files.add(await http.MultipartFile(
|
||||
'database', File(dbPath).readAsBytes().asStream(), await File(dbPath).length(),
|
||||
final dbBytes = await File(dbPath).readAsBytes();
|
||||
request.files.add(http.MultipartFile.fromBytes(
|
||||
'database', dbBytes,
|
||||
filename: 'mooknote.db',
|
||||
));
|
||||
debugPrint('[Sync] 上传数据库: ${await File(dbPath).length()} bytes');
|
||||
debugPrint('[Sync] 上传数据库: ${dbBytes.length} bytes');
|
||||
}
|
||||
// 重新打开数据库
|
||||
await DatabaseHelper.instance.reopen();
|
||||
|
||||
// 收集并上传所有图片
|
||||
final imagePaths = _collectAllImageFiles(appDir);
|
||||
@@ -331,8 +334,9 @@ class ServerSyncService {
|
||||
for (final path in imagePaths) {
|
||||
final relPath = p.relative(path, from: appDir).replaceAll('\\', '/');
|
||||
if (await File(path).exists()) {
|
||||
request.files.add(await http.MultipartFile(
|
||||
'images', File(path).readAsBytes().asStream(), await File(path).length(),
|
||||
final bytes = await File(path).readAsBytes();
|
||||
request.files.add(http.MultipartFile.fromBytes(
|
||||
'images', bytes,
|
||||
filename: relPath,
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user