diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index bc8e5ad..4add4d8 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -1,5 +1,8 @@ +import 'dart:io'; + import 'package:desktop_drop/desktop_drop.dart'; import 'package:flutter/material.dart'; +import 'package:odin/services/data_service.dart'; import 'package:odin/widgets/window_top_bar.dart'; const backgroundStartColor = Color(0x55121212); @@ -13,8 +16,10 @@ class HomePage extends StatefulWidget { } class _HomePageState extends State { - final List _list = []; bool _dragging = false; + bool _loading = false; + String? _fileLink; + final _ds = DataService(); @override Widget build(BuildContext context) { @@ -31,9 +36,14 @@ class _HomePageState extends State { child: Stack( children: [ DropTarget( - onDragDone: (detail) { + onDragDone: (detail) async { + setState(() { + _loading = true; + }); + _fileLink = await _ds + .uploadFileAnonymous(File(detail.urls.first.toFilePath())); setState(() { - _list.addAll(detail.urls); + _loading = false; }); }, onDragEntered: (detail) { @@ -54,14 +64,20 @@ class _HomePageState extends State { ? Colors.blue.withOpacity(0.2) : Colors.transparent, child: Center( - child: Text( - _list.isEmpty ? 'Drop a file to start' : _list.join("\n"), - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.w100, - color: Colors.white.withOpacity(0.3), - ), - ), + child: _loading + ? CircularProgressIndicator( + backgroundColor: Colors.white.withOpacity(0.3), + ) + : Text( + _fileLink == null + ? 'Drop a file to start' + : _fileLink.toString(), + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.w100, + color: Colors.white.withOpacity(0.3), + ), + ), ), ), ), diff --git a/lib/services/data_service.dart b/lib/services/data_service.dart index d22d5ea..af9b45c 100644 --- a/lib/services/data_service.dart +++ b/lib/services/data_service.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:github/github.dart'; +import 'package:intl/intl.dart'; import 'package:path/path.dart' as path; class DataService { @@ -10,18 +11,17 @@ class DataService { final _gh = GitHub(auth: Authentication.withToken(dotenv.env['GITHUB_TOKEN'])); - Future uploadFileAnonymous(File file) async { - await _gh.repositories.createFile( + Future uploadFileAnonymous(File file) async { + final uploadTime = DateFormat('dd-MM-yyyy hh:mm:ss').format(DateTime.now()); + final _ghFile = 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)}'", + message: "☄️ -> '${path.basename(file.path)}' | $uploadTime", path: path.basename(file.path), ), ); + return _ghFile.content?.downloadUrl ?? ''; } } diff --git a/pubspec.lock b/pubspec.lock index b463a16..94594bf 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -158,6 +158,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.0.0" + intl: + dependency: "direct main" + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.17.0" json_annotation: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 28b102f..adee9f5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,6 +40,7 @@ dependencies: github: ^8.2.5 path: ^1.8.0 flutter_dotenv: ^5.0.2 + intl: ^0.17.0 dev_dependencies: flutter_test: