Behavior Adjustment:

- Change path to ${current}/.data/
This commit is contained in:
Linloir 2022-10-20 22:22:41 +08:00
parent 8627538d31
commit 125b7ba135
No known key found for this signature in database
GPG Key ID: 58EEB209A0F2C366
4 changed files with 39 additions and 23 deletions

View File

@ -14,13 +14,14 @@ RUN dart compile exe bin/tcp_server.dart -o bin/tcp_server
FROM ubuntu:latest
RUN apt-get update
RUN apt-get -y install libsqlite3-0 libsqlite3-dev
RUN apt-get update && apt-get -y install libsqlite3-0 libsqlite3-dev
# Copy the previously built executable into the scratch layer
COPY --from=compile /runtime/ ~/server/
COPY --from=compile /lchatserver/bin/tcp_server ~/server/lchatserver/bin/
RUN mkdir /lchatserver
COPY --from=compile /runtime/ /lchatserver/
COPY --from=compile /lchatserver/bin/tcp_server /lchatserver/bin/
# Start server.
EXPOSE 20706
CMD ["~/server/lchatserver/bin/tcp_server"]
WORKDIR /lchatserver/bin
CMD ["/lchatserver/bin/tcp_server"]

View File

@ -1,7 +1,7 @@
/*
* @Author : Linloir
* @Date : 2022-10-06 15:44:16
* @LastEditTime : 2022-10-20 16:34:10
* @LastEditTime : 2022-10-20 20:25:43
* @Description :
*/
@ -17,10 +17,13 @@ import 'package:tcp_server/tcpcontroller/response.dart';
void main(List<String> arguments) async {
//Set address
var port = arguments.isEmpty ? 20706 : int.tryParse(arguments[1]) ?? 20706;
print('[L] [STARTUP ]-----------------------');
print('[L] Running at directory ${Directory.current.path}');
//Create nessesary working directories
await Directory('${Directory.current.path}/.tmp').create();
await Directory('${Directory.current.path}/.data').create();
await Directory('${Directory.current.path}/.data/.tmp').create();
await Directory('${Directory.current.path}/.data/files').create();
await DataBaseHelper().initialize();

View File

@ -1,7 +1,7 @@
/*
* @Author : Linloir
* @Date : 2022-10-06 16:15:01
* @LastEditTime : 2022-10-20 13:14:40
* @LastEditTime : 2022-10-20 20:58:57
* @Description :
*/
@ -25,7 +25,7 @@ class DataBaseHelper {
Future<void> initialize() async {
_database = await databaseFactoryFfi.openDatabase(
'${Directory.current.path}/.tmp/database.db',
'${Directory.current.path}/.data/.tmp/database.db',
options: OpenDatabaseOptions(
version: 1,
onCreate: (db, version) async {
@ -34,7 +34,7 @@ class DataBaseHelper {
'''
CREATE TABLE users (
userid integer primary key autoincrement,
username text not null,
username text unique not null,
passwd text not null,
avatar text
);
@ -241,17 +241,29 @@ class DataBaseHelper {
//Insert into users
try {
await _database.insert(
'users',
{
'username': identity.userName,
'passwd': identity.userPasswd,
'avatar': null
},
conflictAlgorithm: ConflictAlgorithm.rollback
);
} catch (conflict) {
throw Exception(['Database failure', conflict.toString()]);
await _database.transaction((txn) async {
var result = await txn.query(
'users',
where: 'username = ?',
whereArgs: [
identity.userName
]
);
if(result.isNotEmpty) {
throw Exception('Username already exists');
}
await txn.insert(
'users',
{
'username': identity.userName,
'passwd': identity.userPasswd,
'avatar': null
},
conflictAlgorithm: ConflictAlgorithm.rollback
);
});
} catch (e) {
rethrow;
}
//Get new userid

View File

@ -1,7 +1,7 @@
/*
* @Author : Linloir
* @Date : 2022-10-08 15:10:04
* @LastEditTime : 2022-10-20 17:33:52
* @LastEditTime : 2022-10-20 20:20:00
* @Description :
*/
@ -133,7 +133,7 @@ class TCPController {
//Create a future that listens to the status of the payload transmission
() {
var payloadPullStream = _payloadPullStreamController.stream;
var tempFile = File('${Directory.current.path}/.tmp/${DateTime.now().microsecondsSinceEpoch}$_fileCounter')..createSync();
var tempFile = File('${Directory.current.path}/.data/.tmp/${DateTime.now().microsecondsSinceEpoch}$_fileCounter')..createSync();
_fileCounter += 1;
_fileCounter %= 1000;
Future(() async {