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 FROM ubuntu:latest
RUN apt-get update RUN apt-get update && apt-get -y install libsqlite3-0 libsqlite3-dev
RUN apt-get -y install libsqlite3-0 libsqlite3-dev
# Copy the previously built executable into the scratch layer # Copy the previously built executable into the scratch layer
COPY --from=compile /runtime/ ~/server/ RUN mkdir /lchatserver
COPY --from=compile /lchatserver/bin/tcp_server ~/server/lchatserver/bin/ COPY --from=compile /runtime/ /lchatserver/
COPY --from=compile /lchatserver/bin/tcp_server /lchatserver/bin/
# Start server. # Start server.
EXPOSE 20706 EXPOSE 20706
CMD ["~/server/lchatserver/bin/tcp_server"] WORKDIR /lchatserver/bin
CMD ["/lchatserver/bin/tcp_server"]

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

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

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-20 17:33:52 * @LastEditTime : 2022-10-20 20:20:00
* @Description : * @Description :
*/ */
@ -133,7 +133,7 @@ class TCPController {
//Create a future that listens to the status of the payload transmission //Create a future that listens to the status of the payload transmission
() { () {
var payloadPullStream = _payloadPullStreamController.stream; 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 += 1;
_fileCounter %= 1000; _fileCounter %= 1000;
Future(() async { Future(() async {