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 # CHANGELOG
## 1.3.3+12 - UNRELEASED ## 1.3.3+12
* Automatically switch to initial tab when coming from the share menu * Automatically switch to initial tab when coming from the share menu
* Upgraded internal dependencies
## 1.3.2+11 ## 1.3.2+11
* Add a slash to copied URLs * Add a slash to copied URLs

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -208,13 +208,13 @@ class UploadModel extends BaseModel {
files = paths.map((e) => new File(e.path)).toList(); 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) { response.data.ids.forEach((element) {
uploadedPasteIds.putIfAbsent(element, () => false); uploadedPasteIds.putIfAbsent(element, () => false);
}); });
if (createMulti && response.data.ids.length > 1) { 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); uploadedPasteIds.putIfAbsent(multiResponse.data.urlId, () => true);
} }