mirror of
https://github.com/Linloir/Simple-TCP-Server.git
synced 2025-12-16 23:48:11 +08:00
Minor fix and update
- Add find file method
This commit is contained in:
parent
af41d6ba39
commit
887a7e13be
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-06 15:44:16
|
||||
* @LastEditTime : 2022-10-09 22:57:10
|
||||
* @LastEditTime : 2022-10-12 18:23:31
|
||||
* @Description :
|
||||
*/
|
||||
|
||||
@ -46,6 +46,7 @@ void main(List<String> arguments) async {
|
||||
);
|
||||
controller.outStream.add(tokenResponse);
|
||||
}
|
||||
//TODO: check if token id is not in tokenid list
|
||||
tokenMap[request.tokenID!] = tokenMap[request.tokenID!] ?? controller;
|
||||
switch(request.requestType) {
|
||||
case RequestType.checkState: {
|
||||
@ -135,6 +136,11 @@ void main(List<String> arguments) async {
|
||||
controller.outStream.add(response);
|
||||
break;
|
||||
}
|
||||
case RequestType.findFile: {
|
||||
var response = await onFindFile(request, socket);
|
||||
controller.outStream.add(response);
|
||||
break;
|
||||
}
|
||||
case RequestType.fetchFile: {
|
||||
var response = await onFetchFile(request, socket);
|
||||
controller.outStream.add(response);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-06 16:15:01
|
||||
* @LastEditTime : 2022-10-09 20:31:23
|
||||
* @LastEditTime : 2022-10-12 09:35:07
|
||||
* @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({
|
||||
required String msgMd5
|
||||
}) async {
|
||||
@ -510,7 +523,7 @@ class DataBaseHelper {
|
||||
if(queryResult.isEmpty) {
|
||||
throw Exception('File not found');
|
||||
}
|
||||
return queryResult[0]['filedir'] as String;
|
||||
return queryResult[0]['dir'] as String;
|
||||
}
|
||||
|
||||
Future<UserInfo> fetchUserInfoViaToken({
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-08 20:52:48
|
||||
* @LastEditTime : 2022-10-09 13:39:02
|
||||
* @LastEditTime : 2022-10-12 09:09:16
|
||||
* @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 {
|
||||
try {
|
||||
var filePath = await DataBaseHelper().fetchFilePath(msgMd5: request.body['msgmd5'] as String);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-08 15:10:04
|
||||
* @LastEditTime : 2022-10-09 21:24:07
|
||||
* @LastEditTime : 2022-10-12 13:45:01
|
||||
* @Description :
|
||||
*/
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-08 22:40:47
|
||||
* @LastEditTime : 2022-10-09 16:39:02
|
||||
* @LastEditTime : 2022-10-12 13:53:06
|
||||
* @Description :
|
||||
*/
|
||||
|
||||
@ -72,7 +72,7 @@ class TCPResponse {
|
||||
}),
|
||||
payloadFile = payload;
|
||||
|
||||
int get responseLength => responseJson.length;
|
||||
int get responseLength => responseJson.codeUnits.length;
|
||||
int get payloadLength => payloadFile?.lengthSync() ?? 0;
|
||||
Stream<List<int>> get stream async* {
|
||||
yield Uint8List(4)..buffer.asInt32List()[0] = responseLength;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user