Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to export multiple .torrents at once #8230

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 165 additions & 10 deletions src/tribler/ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/tribler/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"i18next": "^23.11.4",
"javascript-time-ago": "^2.5.10",
"js-cookie": "^3.0.5",
"jszip": "^3.10.1",
"lucide-react": "^0.292.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
29 changes: 28 additions & 1 deletion src/tribler/ui/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import zh from 'javascript-time-ago/locale/zh'
import Cookies from "js-cookie";
import { useTranslation } from "react-i18next";
import { triblerService } from "@/services/tribler.service";
import { FileTreeItem } from "@/models/file.model";
import { FileLink, FileTreeItem } from "@/models/file.model";
import { CheckedState } from "@radix-ui/react-checkbox";
import JSZip from "jszip";

TimeAgo.setDefaultLocale(en.locale)
TimeAgo.addLocale(en)
Expand Down Expand Up @@ -225,3 +226,29 @@ export const getSelectedFilesFromTree = (tree: FileTreeItem, included: boolean =
selectedFiles.push(tree.index);
return selectedFiles;
}

export function downloadFile(file: FileLink) {
var link = document.createElement("a");
link.download = file.name;
link.href = file.uri;
link.click();
}

export async function downloadFilesAsZip(files: FileLink[], zipName: string) {
const zip = new JSZip();
for (let i = 0; i < files.length; i++) {
const response = await fetch(files[i].uri);
if (response.status != 200) continue;
const blob = await response.blob();

zip.file(files[i].name, blob);

if (i == files.length - 1) {
const zipData = await zip.generateAsync({ type: "blob" });
const link = document.createElement("a");
link.href = window.URL.createObjectURL(zipData);
link.download = zipName;
link.click();
}
}
}
5 changes: 5 additions & 0 deletions src/tribler/ui/src/models/file.model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ export interface FileTreeItem {
included?: CheckedState;
subRows?: FileTreeItem[];
}

export interface FileLink {
uri: string;
name: string;
}
Loading