fix: download path order now Artist/Album/Quality/track
Quality folder was being prepended to the destination path by the frontend, resulting in Quality/Artist/Album/track. Now quality_dir is passed as a separate parameter through the full stack and inserted between album and filename by the backend path builder.
This commit is contained in:
5 files changed
+36
-22
No files matched your search
@@ -10227,6 +10227,7 @@ fn v2_purchase_target_path(
|
||||
destination: &str,
|
||||
artist_name: &str,
|
||||
album_title: &str,
|
||||
quality_dir: &str,
|
||||
track_number: u32,
|
||||
track_title: &str,
|
||||
ext: &str,
|
||||
@@ -10241,10 +10242,13 @@ fn v2_purchase_target_path(
|
||||
format!("{}.{}", title_clean, ext)
|
||||
};
|
||||
|
||||
PathBuf::from(destination)
|
||||
let mut path = PathBuf::from(destination)
|
||||
.join(artist_dir)
|
||||
.join(album_dir)
|
||||
.join(file_name)
|
||||
.join(album_dir);
|
||||
if !quality_dir.is_empty() {
|
||||
path = path.join(crate::offline_cache::metadata::sanitize_filename(quality_dir));
|
||||
}
|
||||
path.join(file_name)
|
||||
}
|
||||
|
||||
fn v2_apply_purchase_download_flags(
|
||||
@@ -10305,6 +10309,7 @@ async fn v2_download_purchase_track_impl(
|
||||
track_id: u64,
|
||||
format_id: u32,
|
||||
destination: &str,
|
||||
quality_dir: &str,
|
||||
app_state: &AppState,
|
||||
) -> Result<String, String> {
|
||||
let client = app_state.client.read().await;
|
||||
@@ -10335,6 +10340,7 @@ async fn v2_download_purchase_track_impl(
|
||||
destination,
|
||||
&artist_name,
|
||||
&album_title,
|
||||
quality_dir,
|
||||
track.track_number,
|
||||
&track.title,
|
||||
extension,
|
||||
@@ -10632,11 +10638,12 @@ pub async fn v2_purchases_download_track(
|
||||
trackId: u64,
|
||||
formatId: u32,
|
||||
destination: String,
|
||||
qualityDir: String,
|
||||
app_state: State<'_, AppState>,
|
||||
library_state: State<'_, LibraryState>,
|
||||
) -> Result<String, String> {
|
||||
let file_path =
|
||||
v2_download_purchase_track_impl(trackId, formatId, &destination, &app_state).await?;
|
||||
v2_download_purchase_track_impl(trackId, formatId, &destination, &qualityDir, &app_state).await?;
|
||||
|
||||
let guard = library_state.db.lock().await;
|
||||
let db = guard.as_ref().ok_or("No active session - please log in")?;
|
||||
@@ -10652,6 +10659,7 @@ pub async fn v2_purchases_download_album(
|
||||
albumId: String,
|
||||
formatId: u32,
|
||||
destination: String,
|
||||
qualityDir: String,
|
||||
app_state: State<'_, AppState>,
|
||||
library_state: State<'_, LibraryState>,
|
||||
) -> Result<(), String> {
|
||||
@@ -10670,7 +10678,7 @@ pub async fn v2_purchases_download_album(
|
||||
|
||||
let mut failures: Vec<String> = Vec::new();
|
||||
for track in tracks {
|
||||
match v2_download_purchase_track_impl(track.id, formatId, &destination, &app_state).await {
|
||||
match v2_download_purchase_track_impl(track.id, formatId, &destination, &qualityDir, &app_state).await {
|
||||
Ok(file_path) => {
|
||||
let guard = library_state.db.lock().await;
|
||||
let db = guard.as_ref().ok_or("No active session - please log in")?;
|
||||
|
||||
@@ -150,12 +150,11 @@
|
||||
});
|
||||
if (dest && typeof dest === 'string') {
|
||||
const qualityDir = qualityFolderName(selectedFormatId);
|
||||
const finalDest = qualityDir ? `${dest}/${qualityDir}` : dest;
|
||||
if (action === 'all') {
|
||||
const trackIds = (album.tracks?.items || []).map((track) => track.id);
|
||||
startAlbumDownload(albumId, trackIds, selectedFormatId, finalDest);
|
||||
startAlbumDownload(albumId, trackIds, selectedFormatId, dest, qualityDir);
|
||||
} else {
|
||||
startTrackDownload(albumId, action, selectedFormatId, finalDest);
|
||||
startTrackDownload(albumId, action, selectedFormatId, dest, qualityDir);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -422,8 +422,7 @@
|
||||
if (!dest || typeof dest !== 'string') return;
|
||||
|
||||
const qualityDir = formats[0].label.replace(/\//g, '-').trim();
|
||||
const finalDest = qualityDir ? `${dest}/${qualityDir}` : dest;
|
||||
startTrackDownload(track.album.id, track.id, formats[0].id, finalDest);
|
||||
startTrackDownload(track.album.id, track.id, formats[0].id, dest, qualityDir);
|
||||
} catch (err) {
|
||||
console.error('Track download error:', err);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,8 @@ export async function getFormats(
|
||||
export async function downloadAlbum(
|
||||
albumId: string,
|
||||
formatId: number,
|
||||
destination: string
|
||||
destination: string,
|
||||
qualityDir: string = ''
|
||||
): Promise<void> {
|
||||
if (USE_MOCK) {
|
||||
// In mock mode we just fire and forget the SSE stream
|
||||
@@ -103,14 +104,16 @@ export async function downloadAlbum(
|
||||
return invoke<void>('v2_purchases_download_album', {
|
||||
albumId,
|
||||
formatId,
|
||||
destination
|
||||
destination,
|
||||
qualityDir
|
||||
});
|
||||
}
|
||||
|
||||
export async function downloadTrack(
|
||||
trackId: number,
|
||||
formatId: number,
|
||||
destination: string
|
||||
destination: string,
|
||||
qualityDir: string = ''
|
||||
): Promise<string> {
|
||||
if (USE_MOCK) {
|
||||
await fetch(`${MOCK_URL}/purchases/download/track/${trackId}`, {
|
||||
@@ -121,7 +124,8 @@ export async function downloadTrack(
|
||||
return invoke<string>('v2_purchases_download_track', {
|
||||
trackId,
|
||||
formatId,
|
||||
destination
|
||||
destination,
|
||||
qualityDir
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ export function startAlbumDownload(
|
||||
albumId: string,
|
||||
trackIds: number[],
|
||||
formatId: number,
|
||||
destination: string
|
||||
destination: string,
|
||||
qualityDir: string = ''
|
||||
) {
|
||||
updateAlbumState(albumId, () => ({
|
||||
trackStatuses: {},
|
||||
@@ -50,14 +51,15 @@ export function startAlbumDownload(
|
||||
allComplete: false,
|
||||
destination,
|
||||
}));
|
||||
executeAlbumDownload(albumId, trackIds, formatId, destination);
|
||||
executeAlbumDownload(albumId, trackIds, formatId, destination, qualityDir);
|
||||
}
|
||||
|
||||
async function executeAlbumDownload(
|
||||
albumId: string,
|
||||
trackIds: number[],
|
||||
formatId: number,
|
||||
destination: string
|
||||
destination: string,
|
||||
qualityDir: string
|
||||
) {
|
||||
for (const trackId of trackIds) {
|
||||
updateAlbumState(albumId, (state) => ({
|
||||
@@ -66,7 +68,7 @@ async function executeAlbumDownload(
|
||||
}));
|
||||
|
||||
try {
|
||||
const filePath = await downloadTrack(trackId, formatId, destination);
|
||||
const filePath = await downloadTrack(trackId, formatId, destination, qualityDir);
|
||||
updateAlbumState(albumId, (state) => ({
|
||||
...state,
|
||||
trackStatuses: { ...state.trackStatuses, [trackId]: 'complete' },
|
||||
@@ -98,23 +100,25 @@ export function startTrackDownload(
|
||||
albumId: string,
|
||||
trackId: number,
|
||||
formatId: number,
|
||||
destination: string
|
||||
destination: string,
|
||||
qualityDir: string = ''
|
||||
) {
|
||||
updateAlbumState(albumId, (state) => ({
|
||||
...state,
|
||||
trackStatuses: { ...state.trackStatuses, [trackId]: 'downloading' },
|
||||
}));
|
||||
executeSingleTrackDownload(albumId, trackId, formatId, destination);
|
||||
executeSingleTrackDownload(albumId, trackId, formatId, destination, qualityDir);
|
||||
}
|
||||
|
||||
async function executeSingleTrackDownload(
|
||||
albumId: string,
|
||||
trackId: number,
|
||||
formatId: number,
|
||||
destination: string
|
||||
destination: string,
|
||||
qualityDir: string
|
||||
) {
|
||||
try {
|
||||
const filePath = await downloadTrack(trackId, formatId, destination);
|
||||
const filePath = await downloadTrack(trackId, formatId, destination, qualityDir);
|
||||
updateAlbumState(albumId, (state) => ({
|
||||
...state,
|
||||
trackStatuses: { ...state.trackStatuses, [trackId]: 'complete' },
|
||||
|
||||
Reference in new issue
Block a user