From 3fd545966dd97aba790bec2e3ed08f14aff6d59b Mon Sep 17 00:00:00 2001 From: Anas Fikhi Date: Wed, 29 Nov 2023 10:30:19 +0100 Subject: [PATCH] [ Edit ] applied changes from the server to match the new impl --- .../sub_commands/create_command.dart | 1 + .../commands/start_command/start_command.dart | 18 ++++++++++-------- lib/src/etc/extensions.dart | 2 ++ lib/src/etc/models/Localization_doc.dart | 8 ++++---- .../models/{partition.dart => operation.dart} | 8 ++++---- lib/src/etc/models/result_locale.dart | 8 ++++---- lib/src/etc/models/user_info.dart | 2 +- lib/src/etc/networking/client.dart | 6 +++--- lib/src/etc/utils.dart | 4 ++-- 9 files changed, 31 insertions(+), 26 deletions(-) rename lib/src/etc/models/{partition.dart => operation.dart} (73%) diff --git a/lib/src/commands/config_command/sub_commands/create_command.dart b/lib/src/commands/config_command/sub_commands/create_command.dart index d5db988..8cfac56 100644 --- a/lib/src/commands/config_command/sub_commands/create_command.dart +++ b/lib/src/commands/config_command/sub_commands/create_command.dart @@ -190,6 +190,7 @@ class ConfigCreateCommand extends Command { progress: creationProgress, update: 'Something went wrong while creating the ${configFileController.configFileName} file, please try again.', + stacktrace: stacktrace, ); try { diff --git a/lib/src/commands/start_command/start_command.dart b/lib/src/commands/start_command/start_command.dart index 86844ce..d40c290 100644 --- a/lib/src/commands/start_command/start_command.dart +++ b/lib/src/commands/start_command/start_command.dart @@ -81,6 +81,7 @@ class StartCommand extends Command { logger.customErr( progress: configFilesValidationProgress, update: 'Something went wrong while validating your config file.', + stacktrace: stacktrace, error: e, ); @@ -119,14 +120,14 @@ class StartCommand extends Command { logger ..info('\n') ..warn( - 'The ID of this operation is: ${jsonPartitionRes.partitionId}. in case of any issues, please contact us providing this ID so we can help.', + 'The ID of this operation is: ${jsonPartitionRes.operationId}. in case of any issues, please contact us providing this ID so we can help.', ); final result = await aIProcessResult( apiKey: apiKey, langs: asConfig.langs, languageLocalizationMaxDelay: asConfig.languageLocalizationMaxDelay, - partitionId: jsonPartitionRes.partitionId, + operationId: jsonPartitionRes.operationId, ); logger @@ -137,14 +138,14 @@ class StartCommand extends Command { final outputList = await NetClient.instance.retrieveJsonPartitionWithOutput( - outputPartitionId: result.outputPartitionId, + outputoperationId: result.outputoperationId, apiKey: apiKey, ); await _writeNewLocalizationFiles( outputList: outputList, outputDir: Directory(asConfig.outputDir), - partitionId: jsonPartitionRes.partitionId, + operationId: jsonPartitionRes.operationId, ); logger.success('All done!'); @@ -153,6 +154,7 @@ class StartCommand extends Command { } catch (e, stacktrace) { logger.customErr( error: e, + stacktrace: stacktrace, progress: savingSourceFileProgress, update: 'Something went wrong, try again!', ); @@ -197,7 +199,7 @@ class StartCommand extends Command { Future _writeNewLocalizationFiles({ required List outputList, required Directory outputDir, - required String partitionId, + required String operationId, }) async { for (var index = 0; index < outputList.length; index++) { final current = outputList[index]; @@ -224,7 +226,7 @@ class StartCommand extends Command { { 'message': 'Please, if you think that this is an unexpected bug in LangSync, contact us so we can help', - 'partitionId': partitionId, + 'operationId': operationId, 'processedResponse': current.jsonFormattedResponse, 'target_language': current.lang, 'success_file_name': '${current.lang}.json', @@ -265,7 +267,7 @@ class StartCommand extends Command { Future aIProcessResult({ required String apiKey, required Iterable langs, - required String partitionId, + required String operationId, required int? languageLocalizationMaxDelay, }) async { final completer = Completer(); @@ -273,7 +275,7 @@ class StartCommand extends Command { final processStream = NetClient.instance.startAIProcess( apiKey: apiKey, langs: langs, - operationId: partitionId, + operationId: operationId, languageLocalizationMaxDelay: languageLocalizationMaxDelay, ); diff --git a/lib/src/etc/extensions.dart b/lib/src/etc/extensions.dart index 9ccf8ef..264a8af 100644 --- a/lib/src/etc/extensions.dart +++ b/lib/src/etc/extensions.dart @@ -71,11 +71,13 @@ extension LoggerExt on Logger { required Progress progress, required String update, required Object error, + StackTrace? stacktrace, }) { info('\n'); if (utils.isDebugMode) { progress.fail(error.toString()); + if (stacktrace != null) info(stacktrace.toString()); } else { progress.fail(update); } diff --git a/lib/src/etc/models/Localization_doc.dart b/lib/src/etc/models/Localization_doc.dart index 76d8382..7c816ae 100644 --- a/lib/src/etc/models/Localization_doc.dart +++ b/lib/src/etc/models/Localization_doc.dart @@ -3,7 +3,7 @@ import 'package:equatable/equatable.dart'; class LocalizationDoc extends Equatable { const LocalizationDoc({ required this.createdAt, - required this.partitionId, + required this.operationId, required this.jsonPartsLength, this.outputLangs, }); @@ -11,7 +11,7 @@ class LocalizationDoc extends Equatable { factory LocalizationDoc.fromJson(Map json) { return LocalizationDoc( createdAt: DateTime.parse(json['createdAt'] as String), - partitionId: json['partitionId'] as String, + operationId: json['operationId'] as String, jsonPartsLength: json['jsonPartsLength'] is int ? json['jsonPartsLength'] as int : int.parse(json['jsonPartsLength'] as String), @@ -24,14 +24,14 @@ class LocalizationDoc extends Equatable { } final DateTime createdAt; - final String partitionId; + final String operationId; final int jsonPartsLength; final List? outputLangs; @override List get props => [ createdAt, - partitionId, + operationId, jsonPartsLength, outputLangs, ]; diff --git a/lib/src/etc/models/partition.dart b/lib/src/etc/models/operation.dart similarity index 73% rename from lib/src/etc/models/partition.dart rename to lib/src/etc/models/operation.dart index 7867709..44b7cad 100644 --- a/lib/src/etc/models/partition.dart +++ b/lib/src/etc/models/operation.dart @@ -2,20 +2,20 @@ import 'package:equatable/equatable.dart'; class PartitionResponse extends Equatable { - final String partitionId; + final String operationId; const PartitionResponse({ - required this.partitionId, + required this.operationId, }); factory PartitionResponse.fromJson(Map json) { return PartitionResponse( - partitionId: json['partitionId'] as String, + operationId: json['operationId'] as String, ); } @override List get props => [ - partitionId, + operationId, ]; } diff --git a/lib/src/etc/models/result_locale.dart b/lib/src/etc/models/result_locale.dart index 3753fce..09c058c 100644 --- a/lib/src/etc/models/result_locale.dart +++ b/lib/src/etc/models/result_locale.dart @@ -46,10 +46,10 @@ class LangSyncServerSSE extends Equatable { } class LangSyncServerResultSSE extends LangSyncServerSSE { - final String outputPartitionId; + final String outputoperationId; const LangSyncServerResultSSE({ - required this.outputPartitionId, + required this.outputoperationId, required super.message, required super.type, required super.statusCode, @@ -61,7 +61,7 @@ class LangSyncServerResultSSE extends LangSyncServerSSE { final decoded = jsonDecode(message) as Map; return LangSyncServerResultSSE( - outputPartitionId: decoded['partitionId'] as String, + outputoperationId: decoded['operationId'] as String, message: message, statusCode: res['statusCode'] as int, type: // this is hardcoded, butsince we are sure that it is correct. @@ -74,7 +74,7 @@ class LangSyncServerResultSSE extends LangSyncServerSSE { @override List get props => [ - outputPartitionId, + outputoperationId, super.message, super.type, super.statusCode, diff --git a/lib/src/etc/models/user_info.dart b/lib/src/etc/models/user_info.dart index 4ad08b0..ea86022 100644 --- a/lib/src/etc/models/user_info.dart +++ b/lib/src/etc/models/user_info.dart @@ -48,7 +48,7 @@ class UserInfo extends Equatable { 'Available API keys': apiKeysLength, 'Processed Localizations': localizationDocs.length, 'Most Recent Localization ID': localizationDocs.isNotEmpty - ? localizationDocs.last.partitionId + ? localizationDocs.last.operationId : 'You have no processed localizations.', 'Most Recent Localization Date': localizationDocs.isNotEmpty ? '${localizationDocs.last.createdAt.toProperHumanReadableDate()} - ${localizationDocs.last.createdAt.toIso8601String()}' diff --git a/lib/src/etc/networking/client.dart b/lib/src/etc/networking/client.dart index 0ab59d0..fb6bc6d 100644 --- a/lib/src/etc/networking/client.dart +++ b/lib/src/etc/networking/client.dart @@ -2,7 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:langsync/src/etc/models/api_key_res.dart'; import 'package:langsync/src/etc/models/lang_output.dart'; -import 'package:langsync/src/etc/models/partition.dart'; +import 'package:langsync/src/etc/models/operation.dart'; import 'package:langsync/src/etc/models/result_locale.dart'; import 'package:langsync/src/etc/models/user_info.dart'; import 'package:langsync/src/etc/networking/client_boilerplate.dart'; @@ -61,7 +61,7 @@ class NetClient extends NetClientBoilerPlate { } Future> retrieveJsonPartitionWithOutput({ - required String outputPartitionId, + required String outputoperationId, required String apiKey, }) { return makeRes( @@ -71,7 +71,7 @@ class NetClient extends NetClientBoilerPlate { 'Authorization': 'Bearer ${apiKey}', }, { - 'operationId': outputPartitionId, + 'operationId': outputoperationId, }, (res) { final output = (res['output'] as List) diff --git a/lib/src/etc/utils.dart b/lib/src/etc/utils.dart index 68cf9ed..0ce4c4f 100644 --- a/lib/src/etc/utils.dart +++ b/lib/src/etc/utils.dart @@ -8,11 +8,11 @@ import 'package:mason_logger/mason_logger.dart'; final utils = Utils(); class Utils { - final isDebugMode = false; + final isDebugMode = true; //! notice the "/" String get baseUrl => - isDebugMode ? 'http://192.168.0.4:5559' : 'http://api.langsync.app'; + isDebugMode ? 'http://192.168.0.11:5559' : 'http://api.langsync.app'; bool isValidApiKeyFormatted(String apiKey) { final isNotEmpty = apiKey.isNotEmpty;