spotube/bin/create-secrets.dart
Kingkor Roy Tirtho c27b497c4b Follow/Unfollow artist/playlist support
Save/Remove album support
Add/Remove track from favorite support
Easier way to create secrets locally
Updated contribution details according newest changes
2022-03-30 20:38:14 +06:00

34 lines
1.3 KiB
Dart

import 'dart:convert';
import 'dart:io';
import 'package:path/path.dart' as path;
void main(List<String> args) async {
List<String> val;
List<Map> val2;
final cwd = Directory.current.path;
final binSafe = cwd.endsWith("/bin") ? ".." : "";
if (args.isEmpty) {
throw ArgumentError("Expected 1-2 arguments but passed none");
}
if (args.contains("--local")) {
final secretFilePath = path.join(cwd, binSafe, "secrets.json");
final file = File(secretFilePath);
if (!file.existsSync()) throw Exception("secrets.json file not found");
final data = jsonDecode(await file.readAsString());
val = List.castFrom<dynamic, String>(data["LYRICS_SECRET"]);
val2 = List.castFrom<dynamic, Map>(data["SPOTIFY_SECRET"]);
} else {
final decodedLyricSecret = utf8.decode(base64Decode(args.first));
final decodedSpotifySecrete = utf8.decode(base64Decode(args.last));
val = List.castFrom<dynamic, String>(jsonDecode(decodedLyricSecret));
val2 = List.castFrom<dynamic, Map>(jsonDecode(decodedSpotifySecrete));
}
await File(path.join(cwd, binSafe, "lib/models/generated_secrets.dart"))
.writeAsString(
"final List<String> lyricsSecrets = ${jsonEncode(val)};\nfinal List<Map<String, dynamic>> spotifySecrets = ${jsonEncode(val2)};",
);
}