download status & api status code fixes
Mserver/src/index.ts
@@ -53,7 +53,7 @@ const downloadHandler: DownloadHandler = async ({ headers, params, set, request
const filePath = path.join(musicRoot, decodeURI(params["*"]));
const fileScan = await getPathInfo(filePath);
if (!fileScan || fileScan instanceof ServerError) {
set.status = fileScan?.error ? "Internal Server Error" : "Bad Request";
set.status = fileScan?.status || "Internal Server Error";
return fileScan?.error || "Not a file";
}
if (!matchesType(fileScan.mimeType, allowedTypes)) {
@@ -111,7 +111,7 @@ const app = setup
const filePath = path.join(musicRoot, decodeURI(params["*"]));
const fileScan = await getPathInfo(filePath);
if (!fileScan || fileScan instanceof ServerError) {
set.status = fileScan?.error ? "Internal Server Error" : "Bad Request";
set.status = fileScan?.status || "Internal Server Error";
return fileScan?.error || "Not a file";
}
if (!matchesType(fileScan.mimeType, allowedTypes)) {
Mwebclient/src/offline.ts
@@ -281,10 +281,10 @@ async function downloadFile(
const initialProgress = downloadStatusMap[path];
if (typeof initialProgress === "object" && "bytes" in initialProgress) return; // download already in progress
const db = await openDB();
let mimeType: string | undefined;
try {
setDownloadStatusMap(path, { bytes: 0 });
const db = await openDB();
let mimeType: string | undefined;
downloadSemaphore.setMaxConcurrency(options.enableTranscoding ? options.maxTranscodes : options.maxDownloads);
let blob: Blob;
@@ -353,10 +353,10 @@ export async function download(
fetchFiles: ResourceActions<FileListing>,
) {
const fullPath = joinPath(basePath, fileName);
setDownloadStatusMap(fullPath, undefined);
if ("metadata" in item) {
await downloadFile(fullPath, currentDir, options, item, fetchFiles);
} else {
const initialProgress = downloadStatusMap[fullPath];
setDownloadStatusMap(fullPath, "DirectoryProgress");
await getCover(fullPath, false);
try {
@@ -367,7 +367,7 @@ export async function download(
await Promise.allSettled(promises);
setDownloadStatusMap(fullPath, "SyncedFile");
} catch {
setDownloadStatusMap(fullPath, undefined);
setDownloadStatusMap(fullPath, initialProgress === "SyncedFile" ? "SyncedFile" : undefined);
}
}
}