-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ Edit ] major new edits and hange, exposing a flow for beta testers …
…to use langsync directly
- Loading branch information
Showing
18 changed files
with
178 additions
and
41 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
// TODO: add confirmation to logout command. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
lib/src/commands/account_command/sub_commands/api_key_command.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:args/command_runner.dart'; | ||
import 'package:langsync/src/etc/extensions.dart'; | ||
import 'package:langsync/src/etc/networking/client.dart'; | ||
import 'package:mason_logger/mason_logger.dart'; | ||
|
||
class ApiKeyCommand extends Command<int> { | ||
ApiKeyCommand({ | ||
required this.logger, | ||
}); | ||
|
||
final Logger logger; | ||
|
||
@override | ||
String get description => 'Create your unique API key'; | ||
|
||
@override | ||
String get name => 'apiKey'; | ||
|
||
@override | ||
FutureOr<int>? run() async { | ||
final userSure = logger.confirm( | ||
"You're about to create a brand new unique API key, do you want to continue?"); | ||
if (!userSure) { | ||
logger.info('Aborted!'); | ||
return 0; | ||
} | ||
|
||
logger.info('\n'); | ||
|
||
final userName = logger.prompt( | ||
'Please enter your desired username (will be used to identify you): '); | ||
|
||
if (userName.isEmpty) { | ||
logger.err("Username can't be empty!"); | ||
return 1; | ||
} | ||
|
||
final progress = logger.progress('Creating your API key...'); | ||
|
||
try { | ||
final apiKeyDoc = await NetClient.instance.createApiKey(userName); | ||
|
||
progress.complete('API key created successfully!'); | ||
logger.info('\n'); | ||
|
||
logger | ||
// ..info('Your username: ${apiKeyDoc.username}') | ||
..success('Your API key: ${apiKeyDoc.apiKey}') | ||
..info('\n') | ||
..warn( | ||
"Please make sure to save your API key somewhere safe, as you won't be able to retrieve it again!", | ||
) | ||
..info('\n') | ||
..info( | ||
"run 'langsync account auth' to configure LangSync with that API key to start using it.", | ||
); | ||
|
||
return ExitCode.success.code; | ||
} catch (e) { | ||
logger.customErr( | ||
progress: progress, | ||
update: 'Failed to create API key!', | ||
error: e, | ||
); | ||
|
||
return ExitCode.software.code; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:equatable/equatable.dart'; | ||
|
||
class LocalizationDoc extends Equatable { | ||
const LocalizationDoc({ | ||
required this.createdAt, | ||
required this.partitionId, | ||
required this.jsonPartsLength, | ||
this.outputLangs, | ||
}); | ||
|
||
final DateTime createdAt; | ||
final String partitionId; | ||
final int jsonPartsLength; | ||
final List<String>? outputLangs; | ||
|
||
@override | ||
List<Object?> get props => [ | ||
createdAt, | ||
partitionId, | ||
jsonPartsLength, | ||
outputLangs, | ||
]; | ||
|
||
factory LocalizationDoc.fromJson(Map<String, dynamic> json) { | ||
return LocalizationDoc( | ||
createdAt: DateTime.parse(json['createdAt'] as String), | ||
partitionId: json['partitionId'] as String, | ||
jsonPartsLength: json['jsonPartsLength'] is int | ||
? json['jsonPartsLength'] as int | ||
: int.parse(json['jsonPartsLength'] as String), | ||
outputLangs: json['outputLangs'] != null | ||
? (json['outputLangs'] as List<dynamic>) | ||
.map((dynamic e) => e as String) | ||
.toList() | ||
: null, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:equatable/equatable.dart'; | ||
|
||
class APIKeyResponse extends Equatable { | ||
const APIKeyResponse({ | ||
required this.username, | ||
required this.apiKey, | ||
}); | ||
|
||
factory APIKeyResponse.fromJson(Map<String, dynamic> json) { | ||
return APIKeyResponse( | ||
username: json['username'] as String, | ||
apiKey: json['apiKey'] as String, | ||
); | ||
} | ||
|
||
final String username; | ||
final String apiKey; | ||
|
||
@override | ||
List<Object?> get props => [username, apiKey]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,59 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:langsync/src/etc/extensions.dart'; | ||
import 'package:langsync/src/etc/models/Localization_doc.dart'; | ||
|
||
class UserInfo extends Equatable { | ||
const UserInfo({ | ||
required this.userId, | ||
required this.createdAt, | ||
required this.apiKeysLength, | ||
required this.localizationDocs, | ||
}); | ||
|
||
factory UserInfo.fromJson(Map<String, dynamic> json) { | ||
final userJson = json['user']; | ||
|
||
print(userJson['localizationDocs'].runtimeType); | ||
|
||
return UserInfo( | ||
userId: userJson['userId'] as String, | ||
createdAt: DateTime.parse(userJson['createdAt'] as String), | ||
apiKeysLength: userJson['apiKeysLength'] is int | ||
? userJson['apiKeysLength'] as int | ||
: int.parse(userJson['apiKeysLength'] as String), | ||
localizationDocs: (userJson['localizationDocs'] as List<dynamic>) | ||
.map((dynamic e) => | ||
LocalizationDoc.fromJson(e as Map<String, dynamic>)) | ||
.toList(), | ||
); | ||
} | ||
|
||
final String userId; | ||
final DateTime createdAt; | ||
final int apiKeysLength; | ||
final List<LocalizationDoc> localizationDocs; | ||
|
||
@override | ||
List<Object?> get props => [ | ||
userId, | ||
createdAt, | ||
apiKeysLength, | ||
localizationDocs, | ||
]; | ||
|
||
Map<String, dynamic> toJson() { | ||
return <String, dynamic>{ | ||
'User ID': userId, | ||
'User Account Creation Time': createdAt.toProperHumanReadableDate(), | ||
'available API keys': apiKeysLength, | ||
'User Account Creation Date': | ||
'${createdAt.toProperHumanReadableDate()} - ${createdAt.toIso8601String()}', | ||
'Available API keys': apiKeysLength, | ||
'Processed Localizations': localizationDocs.length, | ||
'Most Recent Localization ID': localizationDocs.isNotEmpty | ||
? localizationDocs.last.partitionId | ||
: 'You have no processed localizations.', | ||
'Most Recent Localization Date': localizationDocs.isNotEmpty | ||
? '${localizationDocs.last.createdAt.toProperHumanReadableDate()} - ${localizationDocs.last.createdAt.toIso8601String()}' | ||
: 'You have no processed localizations.', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
const packageVersion = '0.0.3'; | ||
const packageVersion = '0.0.6'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters