From 1d09eb451e27cf1ed0e9ba1a53135add50f0eebb Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sat, 26 Mar 2022 10:02:29 +0600 Subject: [PATCH] made the secret creating part easy & documented --- README.md | 31 ++++++++++++++++++++++++++----- bin/create-secrets.dart | 27 +++++++++++++++++++++------ pubspec.lock | 7 +++++++ pubspec.yaml | 1 + 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 5bb01180..6fdf2223 100644 --- a/README.md +++ b/README.md @@ -158,13 +158,34 @@ Download the [Mac OS Disk Image (.dmg) file](https://github.com/KRTirtho/spotube - Install Development dependencies in linux - `libwebkit2gtk-4.0-dev`, `libkeybinder-3.0-0` & `libkeybinder-3.0-0-dev` (for Debian/Ubuntu) - `webkit2gtk` & `libkeybinder3` (for Arch/Manjaro) -- Clone the Repo - +- Clone the Repo & run + ```bash + $ flutter pub get + ``` +- Create a `.env` file containing 2 secrets `LYRICS_SECRET` & `SPOTIFY_SECRET`. These secrets should be a **base64 encoded JSON string** + - Structure of `LYRICS_SECRET` json string: + ```jsonc + [ + "", + // and so on... + ] + ``` + - Structure of `SPOTIFY_SECRET` json string: + ```jsonc + [ + {"clientId": "", "clientSecret": ""}, + // and so on .... + ] + ``` + > You can base64 encode the JSON [here](https://www.base64encode.org/) +- Run following in the terminal to generate secrets for your fork + ```bash + $ dart bin/create-secrets.dart --loadEnv + ``` +Finally, to start the app run: ```bash -$ flutter pub get -$ flutter run -d +$ flutter run -d ``` - # Things that don't work - Shows & Podcasts aren't supported as it'd require premium anyway diff --git a/bin/create-secrets.dart b/bin/create-secrets.dart index 10a6317b..f464c2ad 100644 --- a/bin/create-secrets.dart +++ b/bin/create-secrets.dart @@ -2,16 +2,31 @@ import 'dart:convert'; import 'dart:io'; import 'package:path/path.dart' as path; +import 'package:dotenv/dotenv.dart'; void main(List args) async { + String lyricSecret; + String spotifySecret; + if (args.isEmpty) { - throw ArgumentError( - "Expected 2 arguments but passed ${args.length < 2 || args.length > 2 ? args.length : "none"}"); + throw ArgumentError("Expected 2 arguments but passed none"); + } + if (args.contains("--loadEnv")) { + load(); + if (env["SPOTIFY_SECRET"] == null || env["LYRICS_SECRET"] == null) { + throw Exception( + "'LYRICS_SECRET' or 'SPOTIFY_SECRET' environmental variable aren't set correctly "); + } + lyricSecret = env["LYRICS_SECRET"]!; + spotifySecret = env["SPOTIFY_SECRET"]!; + } else { + lyricSecret = args.first; + spotifySecret = args.last; } - final decodedSecret = utf8.decode(base64Decode(args.first)); - final decodedSpotifySecrete = utf8.decode(base64Decode(args.last)); - final val = jsonDecode(decodedSecret); + final decodedLyricSecret = utf8.decode(base64Decode(lyricSecret)); + final decodedSpotifySecrete = utf8.decode(base64Decode(spotifySecret)); + final val = jsonDecode(decodedLyricSecret); final val2 = jsonDecode(decodedSpotifySecrete); if (val is! List || (val2 is! List && (val2 as List).first is! Map)) { throw Exception( @@ -21,6 +36,6 @@ void main(List args) async { await File(path.join( Directory.current.path, "lib/models/generated_secrets.dart")) .writeAsString( - "final List lyricsSecrets = $decodedSecret;\nfinal List> spotifySecrets = $decodedSpotifySecrete;", + "final List lyricsSecrets = $decodedLyricSecret;\nfinal List> spotifySecrets = $decodedSpotifySecrete;", ); } diff --git a/pubspec.lock b/pubspec.lock index 67861104..1c7467e7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -169,6 +169,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.4" + dotenv: + dependency: "direct dev" + description: + name: dotenv + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" fake_async: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index ca90635d..b16ebdf1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -70,6 +70,7 @@ dev_dependencies: # rules and activating additional ones. flutter_lints: ^1.0.0 flutter_launcher_icons: ^0.9.2 + dotenv: ^3.0.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec