fix: Improve path sanitizing by replacing dash
This commit is contained in:
parent
87117f2e9e
commit
68cc740251
|
@ -3,6 +3,7 @@ import 'dart:io';
|
|||
import 'package:dio/dio.dart';
|
||||
import 'package:funkblubber/funkentity.dart';
|
||||
import 'package:funkblubber/console.dart' as console;
|
||||
import 'package:funkblubber/string_utils.dart' as utils;
|
||||
|
||||
Future<bool> download({
|
||||
required final FunkObject object,
|
||||
|
@ -40,7 +41,7 @@ Future<bool> _downloadArtist(
|
|||
'refresh=false',
|
||||
);
|
||||
|
||||
final String pathAppend = response.data['name'];
|
||||
final String pathAppend = utils.sanitizePath(response.data['name']);
|
||||
bool folderCreated = true;
|
||||
try {
|
||||
await Directory('$path/$pathAppend').create();
|
||||
|
@ -87,7 +88,9 @@ Future<bool> _downloadAlbum(
|
|||
'page=1&page_size=16&scope=all',
|
||||
);
|
||||
|
||||
final String pathAppend = response.data['results'][0]['album']['title'];
|
||||
final String pathAppend = utils.sanitizePath(
|
||||
response.data['results'][0]['album']['title'],
|
||||
);
|
||||
bool folderCreated = true;
|
||||
try {
|
||||
await Directory('$path/$pathAppend').create();
|
||||
|
@ -102,7 +105,7 @@ Future<bool> _downloadAlbum(
|
|||
|
||||
final List<Future<bool>> results = [];
|
||||
for (final songResponse in response.data['results']) {
|
||||
final String songTitle = songResponse['title'];
|
||||
final String songTitle = utils.sanitizePath(songResponse['title']);
|
||||
final String ext = songResponse['uploads'][0]['extension'];
|
||||
final result = _downloadTrackObject(
|
||||
FunkObject(
|
||||
|
@ -128,7 +131,7 @@ Future<bool> _downloadTrack(
|
|||
'https://${object.domain}/api/v1/tracks/${object.id}/?refresh=false',
|
||||
);
|
||||
|
||||
final String songTitle = response.data['title'];
|
||||
final String songTitle = utils.sanitizePath(response.data['title']);
|
||||
final String ext = response.data['uploads'][0]['extension'];
|
||||
return _downloadTrackObject(
|
||||
FunkObject(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:funkblubber/funkentity.dart';
|
||||
import 'package:funkblubber/console.dart' as console;
|
||||
import 'package:funkblubber/string_utils.dart' as utils;
|
||||
|
||||
enum Action {
|
||||
download,
|
||||
|
@ -203,9 +204,6 @@ StageResult _onDomainStage(
|
|||
return StageResult(result: result, stage: currentStage);
|
||||
}
|
||||
|
||||
String _cutTrailingDash(final String path) =>
|
||||
path.endsWith('/') ? path.substring(0, path.length - 1) : path;
|
||||
|
||||
StageResult _onPathStage(
|
||||
final String arg,
|
||||
final ParseResult previousResult,
|
||||
|
@ -216,7 +214,7 @@ StageResult _onPathStage(
|
|||
|
||||
currentStage = ParsingStage.nothing;
|
||||
result = ParseResult(
|
||||
localPath: _cutTrailingDash(arg),
|
||||
localPath: utils.cutTrailingDash(arg),
|
||||
action: previousResult.action,
|
||||
success: true,
|
||||
object: previousResult.object,
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
String cutTrailingDash(final String path) =>
|
||||
path.endsWith('/') && path.length > 1
|
||||
? path.substring(0, path.length - 1)
|
||||
: path;
|
||||
|
||||
String sanitizePath(final String rawPath) => rawPath.replaceAll('/', '\\');
|
Loading…
Reference in New Issue