From cd95d6c2fe08ca09516d011a478655203280b9d8 Mon Sep 17 00:00:00 2001 From: Abhay Maurya Date: Sat, 13 Nov 2021 17:13:33 +0530 Subject: [PATCH] add data service --- .gitignore | 3 +++ lib/main.dart | 2 ++ lib/services/data_service.dart | 27 +++++++++++++++++++++++++ pubspec.lock | 37 +++++++++++++++++++++++++++++++++- pubspec.yaml | 7 +++++-- 5 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 lib/services/data_service.dart diff --git a/.gitignore b/.gitignore index 0fa6b67..be82281 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release + +# Environment Variables +*.env \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 44a577a..9512d0f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,10 +1,12 @@ import 'package:bitsdojo_window/bitsdojo_window.dart'; import 'package:flutter/material.dart'; import 'package:flutter_acrylic/flutter_acrylic.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:odin/pages/home_page.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); + await dotenv.load(); await Window.initialize(); await Window.setEffect( effect: WindowEffect.acrylic, diff --git a/lib/services/data_service.dart b/lib/services/data_service.dart new file mode 100644 index 0000000..d22d5ea --- /dev/null +++ b/lib/services/data_service.dart @@ -0,0 +1,27 @@ +import 'dart:convert'; +import 'dart:io'; + +import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:github/github.dart'; +import 'package:path/path.dart' as path; + +class DataService { + final _env = dotenv.env; + final _gh = + GitHub(auth: Authentication.withToken(dotenv.env['GITHUB_TOKEN'])); + + Future uploadFileAnonymous(File file) async { + await _gh.repositories.createFile( + RepositorySlug( + _env['GITHUB_USERNAME'] ?? '', _env['GITHUB_REPO_NAME'] ?? ''), + CreateFile( + branch: _env['GITHUB_BRANCH_NAME'], + committer: CommitUser( + _env['GITHUB_COMMIT_USER_NAME'], _env['GITHUB_COMMIT_USER_EMAIL']), + content: base64Encode(file.readAsBytesSync()), + message: "☄️ -> '${path.basename(file.path)}'", + path: path.basename(file.path), + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 86c4668..b463a16 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -118,6 +118,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.0" + flutter_dotenv: + dependency: "direct main" + description: + name: flutter_dotenv + url: "https://pub.dartlang.org" + source: hosted + version: "5.0.2" flutter_lints: dependency: "direct dev" description: @@ -130,6 +137,34 @@ packages: description: flutter source: sdk version: "0.0.0" + github: + dependency: "direct main" + description: + name: github + url: "https://pub.dartlang.org" + source: hosted + version: "8.2.5" + http: + dependency: transitive + description: + name: http + url: "https://pub.dartlang.org" + source: hosted + version: "0.13.4" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.0" + json_annotation: + dependency: transitive + description: + name: json_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "4.3.0" lints: dependency: transitive description: @@ -152,7 +187,7 @@ packages: source: hosted version: "1.7.0" path: - dependency: transitive + dependency: "direct main" description: name: path url: "https://pub.dartlang.org" diff --git a/pubspec.yaml b/pubspec.yaml index 7678d6c..28b102f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,6 +37,9 @@ dependencies: bitsdojo_window: ^0.1.1+1 flutter_acrylic: ^0.1.0 desktop_drop: ^0.1.2 + github: ^8.2.5 + path: ^1.8.0 + flutter_dotenv: ^5.0.2 dev_dependencies: flutter_test: @@ -61,8 +64,8 @@ flutter: uses-material-design: true # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg + assets: + - .env # - images/a_dot_ham.jpeg # An image asset can refer to one or more resolution-specific "variants", see