Skip to content

Commit

Permalink
fix username handling for special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
vauvenal5 committed Jan 8, 2021
1 parent df26ea3 commit 6ec9bb5
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/1603.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- fix username handling with special characters
15 changes: 6 additions & 9 deletions lib/services/isolateable/nextcloud_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:yaga/utils/forground_worker/isolateable.dart';
import 'package:yaga/utils/forground_worker/messages/init_msg.dart';
import 'package:yaga/utils/logger.dart';
import 'package:yaga/utils/nextcloud_client_factory.dart';
import 'package:yaga/utils/uri_utils.dart';

class NextCloudService
with Service<NextCloudService>, Isolateable<NextCloudService>
Expand Down Expand Up @@ -50,7 +51,7 @@ class NextCloudService

@override
Stream<NcFile> list(Uri dir) {
String basePath = "files/${_client.username}";
String basePath = "files/${this.username}";
return this
._client
.webDav
Expand All @@ -61,11 +62,7 @@ class NextCloudService
(event) => event.isDirectory || event.mimeType.startsWith("image"))
.map((webDavFile) {
var path = webDavFile.path.replaceFirst("/$basePath", "");
Uri uri = Uri(
scheme: this.scheme,
userInfo: _client.username,
host: _host.host,
path: path);
Uri uri = UriUtils.fromUri(uri: getOrigin(), path: path);

NcFile file = NcFile(uri);
file.isDirectory = webDavFile.isDirectory;
Expand All @@ -84,7 +81,7 @@ class NextCloudService
Future<Uint8List> getAvatar() => this
._client
.avatar
.getAvatar(_client.username, 100)
.getAvatar(this.username, 100)
.then((value) => base64.decode(value));

Future<Uint8List> getPreview(Uri file) {
Expand All @@ -101,14 +98,14 @@ class NextCloudService

Future<Uint8List> downloadImage(Uri file) {
String basePath =
"files/${_client.username}"; //todo: add proper logging and check if download gets called on real device multiple times
"files/${this.username}"; //todo: add proper logging and check if download gets called on real device multiple times
return this._client.webDav.download(basePath + file.path);
}

Uri getOrigin() {
return Uri(
scheme: this.scheme,
userInfo: _client.username,
userInfo: Uri.encodeComponent(this.username),
host: _host.host,
path: "/");
}
Expand Down
5 changes: 3 additions & 2 deletions lib/views/screens/browse_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ class BrowseView extends StatelessWidget {
if (getIt.get<NextCloudService>().isLoggedIn()) {
Uri origin = getIt.get<NextCloudService>().getOrigin();
children.add(ListTile(
isThreeLine: false,
isThreeLine: true,
leading: AvatarWidget.command(
getIt.get<NextCloudManager>().updateAvatarCommand,
),
title: Text(origin.authority),
title: Text(getIt.get<NextCloudService>().username),
subtitle: Text(origin.host),
onTap: () => getIt
.get<NavigationManager>()
.showDirectoryNavigation(_getArgs(context, origin)),
Expand Down
2 changes: 1 addition & 1 deletion lib/views/screens/nc_login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class NextCloudLoginScreen extends StatelessWidget {

getIt.get<NextCloudManager>().loginCommand(NextCloudLoginData(
Uri.parse(ncParas[NextCloudLoginDataKeys.server]),
ncParas[NextCloudLoginDataKeys.user],
Uri.decodeComponent(ncParas[NextCloudLoginDataKeys.user]),
ncParas[NextCloudLoginDataKeys.password]));

Navigator.popUntil(
Expand Down
2 changes: 1 addition & 1 deletion lib/views/widgets/preferences/uri_preference_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class UriPreferenceWidget extends StatelessWidget {
listTileBuilder: (context, pref) => ListTile(
enabled: pref.enabled,
title: Text(pref.title),
subtitle: Text(pref.value.toString()),
subtitle: Text(Uri.decodeComponent(pref.value.toString())),
onTap: () => _pushToNavigation(context, pref, pref.value),
),
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: A Nextcloud gallary app.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.16.2+1602
version: 0.16.3+1603

environment:
sdk: ">=2.7.0 <3.0.0"
Expand Down

0 comments on commit 6ec9bb5

Please sign in to comment.