Minor fix and update

- Add find file method
This commit is contained in:
Linloir 2022-10-12 18:24:21 +08:00
parent af41d6ba39
commit 887a7e13be
No known key found for this signature in database
GPG Key ID: 58EEB209A0F2C366
5 changed files with 35 additions and 7 deletions

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-10-06 15:44:16 * @Date : 2022-10-06 15:44:16
* @LastEditTime : 2022-10-09 22:57:10 * @LastEditTime : 2022-10-12 18:23:31
* @Description : * @Description :
*/ */
@ -46,6 +46,7 @@ void main(List<String> arguments) async {
); );
controller.outStream.add(tokenResponse); controller.outStream.add(tokenResponse);
} }
//TODO: check if token id is not in tokenid list
tokenMap[request.tokenID!] = tokenMap[request.tokenID!] ?? controller; tokenMap[request.tokenID!] = tokenMap[request.tokenID!] ?? controller;
switch(request.requestType) { switch(request.requestType) {
case RequestType.checkState: { case RequestType.checkState: {
@ -135,6 +136,11 @@ void main(List<String> arguments) async {
controller.outStream.add(response); controller.outStream.add(response);
break; break;
} }
case RequestType.findFile: {
var response = await onFindFile(request, socket);
controller.outStream.add(response);
break;
}
case RequestType.fetchFile: { case RequestType.fetchFile: {
var response = await onFetchFile(request, socket); var response = await onFetchFile(request, socket);
controller.outStream.add(response); controller.outStream.add(response);

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-10-06 16:15:01 * @Date : 2022-10-06 16:15:01
* @LastEditTime : 2022-10-09 20:31:23 * @LastEditTime : 2022-10-12 09:35:07
* @Description : * @Description :
*/ */
@ -497,6 +497,19 @@ class DataBaseHelper {
} }
} }
Future<bool> findFile({
required String fileMd5
}) async {
var targetFile = await _database.query(
'files',
where: 'filemd5 = ?',
whereArgs: [
fileMd5
]
);
return targetFile.isNotEmpty;
}
Future<String> fetchFilePath({ Future<String> fetchFilePath({
required String msgMd5 required String msgMd5
}) async { }) async {
@ -510,7 +523,7 @@ class DataBaseHelper {
if(queryResult.isEmpty) { if(queryResult.isEmpty) {
throw Exception('File not found'); throw Exception('File not found');
} }
return queryResult[0]['filedir'] as String; return queryResult[0]['dir'] as String;
} }
Future<UserInfo> fetchUserInfoViaToken({ Future<UserInfo> fetchUserInfoViaToken({

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-10-08 20:52:48 * @Date : 2022-10-08 20:52:48
* @LastEditTime : 2022-10-09 13:39:02 * @LastEditTime : 2022-10-12 09:09:16
* @Description : * @Description :
*/ */
@ -190,6 +190,15 @@ Future<TCPResponse> onFetchMessage(TCPRequest request, Socket socket) async {
} }
} }
Future<TCPResponse> onFindFile(TCPRequest request, Socket socket) async {
var hasFile = await DataBaseHelper().findFile(fileMd5: request.body['filemd5'] as String);
return TCPResponse(
type: ResponseType.fromRequestType(request.requestType),
status: hasFile ? ResponseStatus.ok : ResponseStatus.err,
errInfo: hasFile ? null : 'File not found'
);
}
Future<TCPResponse> onFetchFile(TCPRequest request, Socket socket) async { Future<TCPResponse> onFetchFile(TCPRequest request, Socket socket) async {
try { try {
var filePath = await DataBaseHelper().fetchFilePath(msgMd5: request.body['msgmd5'] as String); var filePath = await DataBaseHelper().fetchFilePath(msgMd5: request.body['msgmd5'] as String);

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-10-08 15:10:04 * @Date : 2022-10-08 15:10:04
* @LastEditTime : 2022-10-09 21:24:07 * @LastEditTime : 2022-10-12 13:45:01
* @Description : * @Description :
*/ */

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-10-08 22:40:47 * @Date : 2022-10-08 22:40:47
* @LastEditTime : 2022-10-09 16:39:02 * @LastEditTime : 2022-10-12 13:53:06
* @Description : * @Description :
*/ */
@ -72,7 +72,7 @@ class TCPResponse {
}), }),
payloadFile = payload; payloadFile = payload;
int get responseLength => responseJson.length; int get responseLength => responseJson.codeUnits.length;
int get payloadLength => payloadFile?.lengthSync() ?? 0; int get payloadLength => payloadFile?.lengthSync() ?? 0;
Stream<List<int>> get stream async* { Stream<List<int>> get stream async* {
yield Uint8List(4)..buffer.asInt32List()[0] = responseLength; yield Uint8List(4)..buffer.asInt32List()[0] = responseLength;