CCExtractor / rutorrent-flutter

A ruTorrent-based client in Flutter
MIT License
125 stars 111 forks source link

FormatException in Explorer window #110

Closed rj-since-2000 closed 3 years ago

rj-since-2000 commented 3 years ago

Opening Explorer screen shows no files even though some files are downloaded and saved. Log

I/flutter (29990): FormatException: Unexpected character (at character 1)
I/flutter (29990): <html>
I/flutter (29990): ^

Upon more debug I found the complete response which shows status code 404 from rutorrent backend.

I/flutter (29990): <html>
I/flutter (29990): <head><title>404 Not Found</title></head>
I/flutter (29990): <body>
I/flutter (29990): <center><h1>404 Not Found</h1></center>
I/flutter (29990): <hr><center>nginx</center>
I/flutter (29990): </body>
I/flutter (29990): </html>

The function causing this

  /// Gets Disk Files
  static Future<List<DiskFile>> getDiskFiles(Api api, String path) async {
    try {
      var response = await api.ioClient.post(Uri.parse(api.explorerPluginUrl),
          headers: api.getAuthHeader(),
          body: {
            'cmd': 'get',
            'src': path,
          });
      print(response.body);
      var files = jsonDecode(response.body)['files'];

      List<DiskFile> diskFiles = [];

      for (var file in files) {
        DiskFile diskFile = DiskFile();

        diskFile.isDirectory = file['is_dir'];
        diskFile.name = file['data']['name'];
        diskFiles.add(diskFile);
      }

      return diskFiles;
    } on Exception catch (e) {
      print(e.toString());
      return null;
    }
  }

@harchani-ritik Seems some problem with the file path !?

harchani-ritik commented 3 years ago

Opening Explorer screen shows no files even though some files are downloaded and saved. Log

I/flutter (29990): FormatException: Unexpected character (at character 1)
I/flutter (29990): <html>
I/flutter (29990): ^

Upon more debug I found the complete response which shows status code 404 from rutorrent backend.

I/flutter (29990): <html>
I/flutter (29990): <head><title>404 Not Found</title></head>
I/flutter (29990): <body>
I/flutter (29990): <center><h1>404 Not Found</h1></center>
I/flutter (29990): <hr><center>nginx</center>
I/flutter (29990): </body>
I/flutter (29990): </html>

The function causing this

  /// Gets Disk Files
  static Future<List<DiskFile>> getDiskFiles(Api api, String path) async {
    try {
      var response = await api.ioClient.post(Uri.parse(api.explorerPluginUrl),
          headers: api.getAuthHeader(),
          body: {
            'cmd': 'get',
            'src': path,
          });
      print(response.body);
      var files = jsonDecode(response.body)['files'];

      List<DiskFile> diskFiles = [];

      for (var file in files) {
        DiskFile diskFile = DiskFile();

        diskFile.isDirectory = file['is_dir'];
        diskFile.name = file['data']['name'];
        diskFiles.add(diskFile);
      }

      return diskFiles;
    } on Exception catch (e) {
      print(e.toString());
      return null;
    }
  }

@harchani-ritik Seems some problem with the file path !?

This is actually, a seedbox only feature, so it would be great if you can just show a "feature not available" kinda message, when the app is logged in with the account in which there are no credentials (username & password) required.

Suggestion: You can keep a boolean in api_conf to check whether it is a seedbox account (if username & password are entered) or not as this will be used at some other places too. Please check this once, I have noticed if you put whitespace in username/pass while logging from a local account, the app malfunctions, so, correct this also.