Skip to content

Commit

Permalink
[ Edit ] applied changes from the server to match the new impl
Browse files Browse the repository at this point in the history
  • Loading branch information
anasfik committed Nov 29, 2023
1 parent e110a73 commit 3fd5459
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class ConfigCreateCommand extends Command<int> {
progress: creationProgress,
update:
'Something went wrong while creating the ${configFileController.configFileName} file, please try again.',
stacktrace: stacktrace,
);

try {
Expand Down
18 changes: 10 additions & 8 deletions lib/src/commands/start_command/start_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class StartCommand extends Command<int> {
logger.customErr(
progress: configFilesValidationProgress,
update: 'Something went wrong while validating your config file.',
stacktrace: stacktrace,
error: e,
);

Expand Down Expand Up @@ -119,14 +120,14 @@ class StartCommand extends Command<int> {
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
Expand All @@ -137,14 +138,14 @@ class StartCommand extends Command<int> {

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!');
Expand All @@ -153,6 +154,7 @@ class StartCommand extends Command<int> {
} catch (e, stacktrace) {
logger.customErr(
error: e,
stacktrace: stacktrace,
progress: savingSourceFileProgress,
update: 'Something went wrong, try again!',
);
Expand Down Expand Up @@ -197,7 +199,7 @@ class StartCommand extends Command<int> {
Future<void> _writeNewLocalizationFiles({
required List<LangOutput> outputList,
required Directory outputDir,
required String partitionId,
required String operationId,
}) async {
for (var index = 0; index < outputList.length; index++) {
final current = outputList[index];
Expand All @@ -224,7 +226,7 @@ class StartCommand extends Command<int> {
{
'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',
Expand Down Expand Up @@ -265,15 +267,15 @@ class StartCommand extends Command<int> {
Future<LangSyncServerResultSSE> aIProcessResult({
required String apiKey,
required Iterable<String> langs,
required String partitionId,
required String operationId,
required int? languageLocalizationMaxDelay,
}) async {
final completer = Completer<LangSyncServerResultSSE>();

final processStream = NetClient.instance.startAIProcess(
apiKey: apiKey,
langs: langs,
operationId: partitionId,
operationId: operationId,
languageLocalizationMaxDelay: languageLocalizationMaxDelay,
);

Expand Down
2 changes: 2 additions & 0 deletions lib/src/etc/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/etc/models/Localization_doc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ 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,
});

factory LocalizationDoc.fromJson(Map<String, dynamic> 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),
Expand All @@ -24,14 +24,14 @@ class LocalizationDoc extends Equatable {
}

final DateTime createdAt;
final String partitionId;
final String operationId;
final int jsonPartsLength;
final List<String>? outputLangs;

@override
List<Object?> get props => [
createdAt,
partitionId,
operationId,
jsonPartsLength,
outputLangs,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic> json) {
return PartitionResponse(
partitionId: json['partitionId'] as String,
operationId: json['operationId'] as String,
);
}

@override
List<Object?> get props => [
partitionId,
operationId,
];
}
8 changes: 4 additions & 4 deletions lib/src/etc/models/result_locale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -61,7 +61,7 @@ class LangSyncServerResultSSE extends LangSyncServerSSE {
final decoded = jsonDecode(message) as Map<String, dynamic>;

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.
Expand All @@ -74,7 +74,7 @@ class LangSyncServerResultSSE extends LangSyncServerSSE {

@override
List<Object?> get props => [
outputPartitionId,
outputoperationId,
super.message,
super.type,
super.statusCode,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/etc/models/user_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()}'
Expand Down
6 changes: 3 additions & 3 deletions lib/src/etc/networking/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -61,7 +61,7 @@ class NetClient extends NetClientBoilerPlate {
}

Future<List<LangOutput>> retrieveJsonPartitionWithOutput({
required String outputPartitionId,
required String outputoperationId,
required String apiKey,
}) {
return makeRes(
Expand All @@ -71,7 +71,7 @@ class NetClient extends NetClientBoilerPlate {
'Authorization': 'Bearer ${apiKey}',
},
{
'operationId': outputPartitionId,
'operationId': outputoperationId,
},
(res) {
final output = (res['output'] as List)
Expand Down
4 changes: 2 additions & 2 deletions lib/src/etc/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3fd5459

Please sign in to comment.