Copy uploaded paste links to clipboard
This commit is contained in:
parent
336443eeae
commit
0c5384441a
10 changed files with 100 additions and 5 deletions
4
CHANGELOG.md
Normal file
4
CHANGELOG.md
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# CHANGELOG
|
||||||
|
|
||||||
|
## 1.0.0+1
|
||||||
|
* Initial release
|
|
@ -27,4 +27,5 @@
|
||||||
android:name="flutterEmbedding"
|
android:name="flutterEmbedding"
|
||||||
android:value="2" />
|
android:value="2" />
|
||||||
</application>
|
</application>
|
||||||
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
8
android/fastlane/buildAndroidDebug.sh
Executable file
8
android/fastlane/buildAndroidDebug.sh
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
cd ../../;
|
||||||
|
flutter clean && \
|
||||||
|
flutter pub get &&
|
||||||
|
flutter packages pub run build_runner build --delete-conflicting-outputs;
|
||||||
|
|
||||||
|
flutter build apk --debug;
|
|
@ -31,6 +31,8 @@
|
||||||
"upload": "Upload",
|
"upload": "Upload",
|
||||||
"uploading_now": "Uploading...",
|
"uploading_now": "Uploading...",
|
||||||
"file_explorer_open": "Selecting files...",
|
"file_explorer_open": "Selecting files...",
|
||||||
|
"uploaded": "Uploaded! Copied links to clipboard.",
|
||||||
|
"dismiss": "Dismiss",
|
||||||
"multipaste": "multipaste",
|
"multipaste": "multipaste",
|
||||||
"errors": {
|
"errors": {
|
||||||
"not_found": "Not found"
|
"not_found": "Not found"
|
||||||
|
|
20
lib/core/models/rest/uploaded_multi.dart
Normal file
20
lib/core/models/rest/uploaded_multi.dart
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
part 'uploaded_multi.g.dart';
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class UploadedMulti {
|
||||||
|
@JsonKey(required: true)
|
||||||
|
final String url;
|
||||||
|
|
||||||
|
@JsonKey(required: true, name: "url_id")
|
||||||
|
final String urlId;
|
||||||
|
|
||||||
|
UploadedMulti({this.url, this.urlId});
|
||||||
|
|
||||||
|
// JSON Init
|
||||||
|
factory UploadedMulti.fromJson(Map<String, dynamic> json) => _$UploadedMultiFromJson(json);
|
||||||
|
|
||||||
|
// JSON Export
|
||||||
|
Map<String, dynamic> toJson() => _$UploadedMultiToJson(this);
|
||||||
|
}
|
22
lib/core/models/rest/uploaded_multi_response.dart
Normal file
22
lib/core/models/rest/uploaded_multi_response.dart
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
import 'uploaded_multi.dart';
|
||||||
|
|
||||||
|
part 'uploaded_multi_response.g.dart';
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class UploadedMultiResponse {
|
||||||
|
@JsonKey(required: true)
|
||||||
|
final String status;
|
||||||
|
|
||||||
|
@JsonKey(required: true)
|
||||||
|
final UploadedMulti data;
|
||||||
|
|
||||||
|
UploadedMultiResponse({this.status, this.data});
|
||||||
|
|
||||||
|
// JSON Init
|
||||||
|
factory UploadedMultiResponse.fromJson(Map<String, dynamic> json) => _$UploadedMultiResponseFromJson(json);
|
||||||
|
|
||||||
|
// JSON Export
|
||||||
|
Map<String, dynamic> toJson() => _$UploadedMultiResponseToJson(this);
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import '../models/rest/config.dart';
|
||||||
import '../models/rest/config_response.dart';
|
import '../models/rest/config_response.dart';
|
||||||
import '../models/rest/history.dart';
|
import '../models/rest/history.dart';
|
||||||
import '../models/rest/history_response.dart';
|
import '../models/rest/history_response.dart';
|
||||||
|
import '../models/rest/uploaded_multi_response.dart';
|
||||||
import '../models/rest/uploaded_response.dart';
|
import '../models/rest/uploaded_response.dart';
|
||||||
import '../services/api.dart';
|
import '../services/api.dart';
|
||||||
|
|
||||||
|
@ -42,6 +43,7 @@ class FileRepository {
|
||||||
multiPasteIds.putIfAbsent("ids[${ids.indexOf(element) + 1}]", () => element);
|
multiPasteIds.putIfAbsent("ids[${ids.indexOf(element) + 1}]", () => element);
|
||||||
});
|
});
|
||||||
|
|
||||||
await _api.post('/file/create_multipaste', fields: multiPasteIds);
|
var response = await _api.post('/file/create_multipaste', fields: multiPasteIds);
|
||||||
|
return UploadedMultiResponse.fromJson(json.decode(response.body));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import '../enums/viewstate.dart';
|
||||||
import '../error/rest_service_exception.dart';
|
import '../error/rest_service_exception.dart';
|
||||||
import '../error/service_exception.dart';
|
import '../error/service_exception.dart';
|
||||||
import '../models/rest/rest_error.dart';
|
import '../models/rest/rest_error.dart';
|
||||||
|
import '../models/rest/uploaded_multi_response.dart';
|
||||||
import '../models/rest/uploaded_response.dart';
|
import '../models/rest/uploaded_response.dart';
|
||||||
import '../services/file_service.dart';
|
import '../services/file_service.dart';
|
||||||
import '../util/logger.dart';
|
import '../util/logger.dart';
|
||||||
|
@ -73,10 +74,11 @@ class UploadModel extends BaseModel {
|
||||||
setState(ViewState.Idle);
|
setState(ViewState.Idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void upload() async {
|
Future<List<String>> upload() async {
|
||||||
setState(ViewState.Busy);
|
setState(ViewState.Busy);
|
||||||
setStateMessage(translate('upload.uploading_now'));
|
setStateMessage(translate('upload.uploading_now'));
|
||||||
|
|
||||||
|
List<String> uploadedPasteIds = [];
|
||||||
try {
|
try {
|
||||||
List<File> files;
|
List<File> files;
|
||||||
Map<String, String> additionalFiles;
|
Map<String, String> additionalFiles;
|
||||||
|
@ -91,14 +93,17 @@ class UploadModel extends BaseModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
UploadedResponse response = await _fileService.upload(files, additionalFiles);
|
UploadedResponse response = await _fileService.upload(files, additionalFiles);
|
||||||
|
uploadedPasteIds.addAll(response.data.ids);
|
||||||
|
|
||||||
if (createMulti && response.data.ids.length > 1) {
|
if (createMulti && response.data.ids.length > 1) {
|
||||||
await _fileService.createMulti(response.data.ids);
|
UploadedMultiResponse multiResponse = await _fileService.createMulti(response.data.ids);
|
||||||
|
uploadedPasteIds.add(multiResponse.data.urlId);
|
||||||
}
|
}
|
||||||
|
|
||||||
clearCachedFiles();
|
clearCachedFiles();
|
||||||
_pasteTextController.clear();
|
_pasteTextController.clear();
|
||||||
errorMessage = null;
|
errorMessage = null;
|
||||||
|
return uploadedPasteIds;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e is RestServiceException) {
|
if (e is RestServiceException) {
|
||||||
if (e.statusCode == HttpStatus.notFound) {
|
if (e.statusCode == HttpStatus.notFound) {
|
||||||
|
@ -132,6 +137,7 @@ class UploadModel extends BaseModel {
|
||||||
|
|
||||||
setStateMessage(null);
|
setStateMessage(null);
|
||||||
setState(ViewState.Idle);
|
setState(ViewState.Idle);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
|
import 'package:clipboard/clipboard.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_translate/flutter_translate.dart';
|
import 'package:flutter_translate/flutter_translate.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../../core/enums/viewstate.dart';
|
import '../../core/enums/viewstate.dart';
|
||||||
|
import '../../core/models/session.dart';
|
||||||
import '../../core/viewmodels/upload_model.dart';
|
import '../../core/viewmodels/upload_model.dart';
|
||||||
import '../shared/app_colors.dart';
|
import '../shared/app_colors.dart';
|
||||||
import '../widgets/centered_error_row.dart';
|
import '../widgets/centered_error_row.dart';
|
||||||
|
@ -13,6 +16,8 @@ class UploadView extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var url = Provider.of<Session>(context).url;
|
||||||
|
|
||||||
return BaseView<UploadModel>(
|
return BaseView<UploadModel>(
|
||||||
builder: (context, model, child) => Scaffold(
|
builder: (context, model, child) => Scaffold(
|
||||||
appBar: MyAppBar(title: Text(translate('titles.upload'))),
|
appBar: MyAppBar(title: Text(translate('titles.upload'))),
|
||||||
|
@ -96,7 +101,31 @@ class UploadView extends StatelessWidget {
|
||||||
borderRadius: BorderRadius.circular(24),
|
borderRadius: BorderRadius.circular(24),
|
||||||
),
|
),
|
||||||
color: primaryAccentColor,
|
color: primaryAccentColor,
|
||||||
onPressed: () => model.upload(),
|
onPressed: () async {
|
||||||
|
List<String> items = await model.upload();
|
||||||
|
|
||||||
|
if (items != null) {
|
||||||
|
var clipboardContent = '';
|
||||||
|
items.forEach((element) {
|
||||||
|
clipboardContent += '$url/$element\n';
|
||||||
|
});
|
||||||
|
|
||||||
|
FlutterClipboard.copy(clipboardContent).then((value) {
|
||||||
|
final snackBar = SnackBar(
|
||||||
|
action: SnackBarAction(
|
||||||
|
label: translate('upload.dismiss'),
|
||||||
|
textColor: Colors.blue,
|
||||||
|
onPressed: () {
|
||||||
|
Scaffold.of(context).hideCurrentSnackBar();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
content: Text(translate('upload.uploaded')),
|
||||||
|
duration: Duration(seconds: 10),
|
||||||
|
);
|
||||||
|
Scaffold.of(context).showSnackBar(snackBar);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
icon: Icon(Icons.upload_rounded, color: Colors.green),
|
icon: Icon(Icons.upload_rounded, color: Colors.green),
|
||||||
label: Text(
|
label: Text(
|
||||||
translate('upload.upload'),
|
translate('upload.upload'),
|
||||||
|
|
|
@ -25,7 +25,7 @@ dependencies:
|
||||||
flutter_translate: 1.6.0
|
flutter_translate: 1.6.0
|
||||||
provider: 4.3.3
|
provider: 4.3.3
|
||||||
provider_architecture: 1.1.1+1
|
provider_architecture: 1.1.1+1
|
||||||
get_it: 3.1.0 # major changes in 4.x
|
get_it: 3.1.0 # major changes > 3
|
||||||
logger: 0.9.4
|
logger: 0.9.4
|
||||||
shared_preferences: 0.5.12+4
|
shared_preferences: 0.5.12+4
|
||||||
http: 0.12.2
|
http: 0.12.2
|
||||||
|
@ -36,6 +36,7 @@ dependencies:
|
||||||
expandable: 4.1.4
|
expandable: 4.1.4
|
||||||
share: 0.6.5+4
|
share: 0.6.5+4
|
||||||
file_picker: 2.1.6
|
file_picker: 2.1.6
|
||||||
|
clipboard: 0.1.2+8
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
Loading…
Reference in a new issue