Skip to content

Commit

Permalink
Clean filenames in zip too for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bookbonobo committed Jun 30, 2023
1 parent 7581ecf commit 0f57fa8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libby-download-extension",
"version": "0.4.1",
"version": "0.4.2",
"description": "Firefox extension to download Libby audiobooks for transfer to unsupported devices",
"scripts": {
"start": "webpack --watch --config webpack.dev.js",
Expand Down
7 changes: 4 additions & 3 deletions src/processor/mp3-with-cue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChapterBounds, downloadZip, getMp3Meta, getSpine, MP3Meta, Spine, zeroPad } from "./utils";
import { ChapterBounds, cleanFilename, downloadZip, getMp3Meta, getSpine, MP3Meta, Spine, zeroPad } from "./utils";
import JSZip from "jszip";
import NodeID3 from "node-id3";
import { LoadState } from "../state";
Expand Down Expand Up @@ -26,8 +26,9 @@ export async function mp3WithCUE(state: LoadState) {
const tagged = NodeID3.update(mp3Meta.tags, <Buffer>mergedContent);

// Add both files to the zip and download
zip.file(`${mp3Meta.title}.cue`, processed.cueContent);
zip.file(`${mp3Meta.title}.mp3`, tagged.buffer);
const filename = cleanFilename(mp3Meta.title);
zip.file(`${filename}.cue`, processed.cueContent);
zip.file(`${filename}.mp3`, tagged.buffer);
console.log(mp3Meta);
await downloadZip(zip, `${mp3Meta.title.slice(0, Math.min(25, mp3Meta.title.length))}`, state.expires);
}
Expand Down
12 changes: 10 additions & 2 deletions src/processor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ export function zeroPad(index: number): string {
* @param expiration Loan expiration
*/
export async function downloadZip(zip: any, title: string, expiration: Date) {
let zipName = `${title}_DUE_${expiration.toDateString()}.zip`;
zipName = zipName.replace(/[/\\?%*:|"<>]/g, "");
const zipName = cleanFilename(`${title}_DUE_${expiration.toDateString()}.zip`);
const processTask = await addTask(new Task(zipName, "Downloading Zip", "Running"));
const archive = await zip.generateAsync({ type: "blob" });
const archiveUrl = URL.createObjectURL(archive);
Expand All @@ -192,6 +191,15 @@ export async function downloadZip(zip: any, title: string, expiration: Date) {
URL.revokeObjectURL(archiveUrl);
}

/**
* Sanitize reserved path characters
*
* @param filename
*/
export function cleanFilename(filename: string): string {
return filename.replace(/[/\\?%*:|"<>]/g, "");
}

/**
* Parse table of contents
*
Expand Down
2 changes: 1 addition & 1 deletion static/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Libby Download",
"version": "0.4.1",
"version": "0.4.2",
"description": "Downloads Audiobooks for transfer to unsupported devices",
"icons": {
"48": "icons/music-player-fill.svg",
Expand Down

0 comments on commit 0f57fa8

Please sign in to comment.