Minor method refactor, release 1.3.3+12

This commit is contained in:
Varakh 2021-05-09 10:59:14 +02:00
parent 9ec215cbf4
commit aa07d61a3c
7 changed files with 28 additions and 20 deletions

View file

@ -1,7 +1,8 @@
# CHANGELOG
## 1.3.3+12 - UNRELEASED
## 1.3.3+12
* Automatically switch to initial tab when coming from the share menu
* Upgraded internal dependencies
## 1.3.2+11
* Add a slash to copied URLs

View file

@ -27,16 +27,16 @@ class FileRepository {
return parsedResponse.data;
}
Future delete(String id) async {
Future<void> postDelete(String id) async {
await _api.post('/file/delete', fields: {'ids[1]': id});
}
Future<UploadedResponse> upload(List<File> files, Map<String, String> additionalFiles) async {
Future<UploadedResponse> postUpload(List<File> files, Map<String, String> additionalFiles) async {
var response = await _api.post('/file/upload', files: files, additionalFiles: additionalFiles);
return UploadedResponse.fromJson(json.decode(response.body));
}
Future createMulti(List<String> ids) async {
Future<UploadedMultiResponse> postCreateMultiPaste(List<String> ids) async {
Map<String, String> multiPasteIds = Map();
ids.forEach((element) {

View file

@ -8,7 +8,7 @@ import '../services/api.dart';
class UserRepository {
Api _api = locator<Api>();
Future<CreateApiKeyResponse> createApiKey(
Future<CreateApiKeyResponse> postApiKey(
String url, String username, String password, String accessLevel, String comment) async {
_api.setUrl(url);

View file

@ -3,27 +3,31 @@ import 'dart:io';
import '../../core/repositories/file_repository.dart';
import '../../locator.dart';
import '../models/rest/config.dart';
import '../models/rest/history.dart';
import '../models/rest/uploaded_multi_response.dart';
import '../models/rest/uploaded_response.dart';
class FileService {
final FileRepository _fileRepository = locator<FileRepository>();
Future getConfig(String url) async {
Future<Config> getConfig(String url) async {
return await _fileRepository.getConfig(url);
}
Future getHistory() async {
Future<History> getHistory() async {
return await _fileRepository.getHistory();
}
Future deletePaste(String id) async {
return await _fileRepository.delete(id);
Future<void> deletePaste(String id) async {
return await _fileRepository.postDelete(id);
}
Future upload(List<File> files, Map<String, String> additionalFiles) async {
return await _fileRepository.upload(files, additionalFiles);
Future<UploadedResponse> uploadPaste(List<File> files, Map<String, String> additionalFiles) async {
return await _fileRepository.postUpload(files, additionalFiles);
}
Future createMulti(List<String> ids) async {
return await _fileRepository.createMulti(ids);
Future<UploadedMultiResponse> uploadMultiPaste(List<String> ids) async {
return await _fileRepository.postCreateMultiPaste(ids);
}
}

View file

@ -3,6 +3,8 @@ import 'dart:async';
import '../../locator.dart';
import '../enums/error_code.dart';
import '../error/service_exception.dart';
import '../models/rest/apikeys_response.dart';
import '../models/rest/create_apikey_response.dart';
import '../repositories/user_repository.dart';
import 'file_service.dart';
@ -10,16 +12,17 @@ class UserService {
final FileService _fileService = locator<FileService>();
final UserRepository _userRepository = locator<UserRepository>();
Future createApiKey(String url, String username, String password, String accessLevel, String comment) async {
return await _userRepository.createApiKey(url, username, password, accessLevel, comment);
Future<CreateApiKeyResponse> createApiKey(
String url, String username, String password, String accessLevel, String comment) async {
return await _userRepository.postApiKey(url, username, password, accessLevel, comment);
}
Future getApiKeys() async {
Future<ApiKeysResponse> getApiKeys() async {
return await _userRepository.getApiKeys();
}
/// Use 'getHistory' to check currently used API key to require 'apikey' access level
Future checkAccessLevelIsAtLeastApiKey() async {
Future<void> checkAccessLevelIsAtLeastApiKey() async {
try {
await _fileService.getHistory();
} catch (e) {

View file

@ -120,7 +120,7 @@ class LoginModel extends BaseModel {
success = await _sessionService.login(url, apiKeyResponse.data['new_key']);
} else {
_sessionService.setApiConfig(url, apiKey);
success = await _userService.checkAccessLevelIsAtLeastApiKey();
await _userService.checkAccessLevelIsAtLeastApiKey();
success = await _sessionService.login(url, apiKey);
}
errorMessage = null;

View file

@ -208,13 +208,13 @@ class UploadModel extends BaseModel {
files = paths.map((e) => new File(e.path)).toList();
}
UploadedResponse response = await _fileService.upload(files, additionalFiles);
UploadedResponse response = await _fileService.uploadPaste(files, additionalFiles);
response.data.ids.forEach((element) {
uploadedPasteIds.putIfAbsent(element, () => false);
});
if (createMulti && response.data.ids.length > 1) {
UploadedMultiResponse multiResponse = await _fileService.createMulti(response.data.ids);
UploadedMultiResponse multiResponse = await _fileService.uploadMultiPaste(response.data.ids);
uploadedPasteIds.putIfAbsent(multiResponse.data.urlId, () => true);
}