mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
Options: Download tab with transfer window, queue and bandwidth limits
Download folder via the File System Access API (Chromium; browser default elsewhere), "ask every time" save dialog, file transfer window with progress, completion pop-up, concurrent upload/download caps and connector-side bandwidth limits (new "ftlimit" stdin command / setTransferLimit message). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
1 parent
7b98cb2d7c
commit
d0fc97d921
11 files changed
+747
-23
No files matched your search
@@ -4679,3 +4679,61 @@
|
||||
.ts-stream-request-block {
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
/* Options -> Download, file transfer window */
|
||||
.ts-download-dir {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.ts-download-number {
|
||||
width: 5em;
|
||||
margin: 0 4px;
|
||||
}
|
||||
.ts-transfers-window {
|
||||
position: fixed;
|
||||
right: 16px;
|
||||
bottom: 48px;
|
||||
width: min(560px, calc(100vw - 32px));
|
||||
max-height: 50vh;
|
||||
z-index: 1100;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.ts-transfers-window .ts-dialog-body {
|
||||
overflow: auto;
|
||||
}
|
||||
.ts-transfers-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
.ts-transfers-table td {
|
||||
padding: 2px 4px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.ts-transfers-name {
|
||||
max-width: 180px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.ts-transfers-table progress {
|
||||
width: 100px;
|
||||
}
|
||||
.ts-transfer-error td {
|
||||
color: var(--log-error);
|
||||
}
|
||||
.ts-transfer-toast {
|
||||
position: fixed;
|
||||
right: 16px;
|
||||
bottom: 16px;
|
||||
z-index: 1200;
|
||||
padding: 8px 12px;
|
||||
background: var(--bg-toolbar-1);
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
+363
-15
@@ -151,6 +151,19 @@ import {
|
||||
type IconPack,
|
||||
} from "./iconpack";
|
||||
import { StillImg } from "./lib/still";
|
||||
import {
|
||||
DEFAULT_DOWNLOAD_SETTINGS,
|
||||
canPickFolder,
|
||||
clearDownloadDir,
|
||||
loadDownloadDir,
|
||||
loadDownloadSettings,
|
||||
pickDownloadDir,
|
||||
resolveSaveTarget,
|
||||
saveDownloadSettings,
|
||||
writeToTarget,
|
||||
type DownloadSettings,
|
||||
type SaveTarget,
|
||||
} from "./downloads";
|
||||
import {
|
||||
GREENTEASPEAK_THEME_ID,
|
||||
GreenteaSpeakChrome,
|
||||
@@ -688,6 +701,10 @@ const DisplayPrefsContext = createContext<{
|
||||
saveIconPacks: (packs: IconPack[]) => void;
|
||||
whisper: WhisperSettings;
|
||||
setWhisper: (next: WhisperSettings) => void;
|
||||
downloads: DownloadSettings;
|
||||
setDownloads: (next: DownloadSettings) => void;
|
||||
downloadDir: FileSystemDirectoryHandle | null;
|
||||
setDownloadDir: (dir: FileSystemDirectoryHandle | null) => void;
|
||||
}>({
|
||||
tree: DEFAULT_TREE_OPTIONS,
|
||||
setTree: () => {},
|
||||
@@ -697,6 +714,10 @@ const DisplayPrefsContext = createContext<{
|
||||
saveIconPacks: () => {},
|
||||
whisper: DEFAULT_WHISPER_SETTINGS,
|
||||
setWhisper: () => {},
|
||||
downloads: DEFAULT_DOWNLOAD_SETTINGS,
|
||||
setDownloads: () => {},
|
||||
downloadDir: null,
|
||||
setDownloadDir: () => {},
|
||||
});
|
||||
const DISCONNECT_MESSAGE_KEY = "webspeak3:disconnect-message";
|
||||
const COLLECTED_URLS_KEY = "webspeak3:collected-urls";
|
||||
@@ -985,10 +1006,82 @@ function formatRate(bytesPerSec: number): string {
|
||||
* into an actual browser download, without ever round-tripping through the
|
||||
* gateway's HTTP surface - it's all-in-memory via a Blob + object URL. */
|
||||
function triggerBrowserDownload(filename: string, base64Data: string): void {
|
||||
downloadBlob(base64Blob(base64Data), filename);
|
||||
}
|
||||
|
||||
function base64Blob(base64Data: string): Blob {
|
||||
const binary = atob(base64Data);
|
||||
const bytes = new Uint8Array(binary.length);
|
||||
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
||||
downloadBlob(new Blob([bytes]), filename);
|
||||
return new Blob([bytes]);
|
||||
}
|
||||
|
||||
/** One entry of the file transfer window (Options -> Download queue/limits). */
|
||||
interface Transfer {
|
||||
id: number;
|
||||
dir: "up" | "down";
|
||||
cid: number;
|
||||
path: string;
|
||||
name: string;
|
||||
size: number;
|
||||
done: number;
|
||||
status: "queued" | "running" | "done" | "error";
|
||||
/** Downloads: picked at click time. */
|
||||
target?: SaveTarget;
|
||||
/** Uploads. */
|
||||
file?: File;
|
||||
}
|
||||
|
||||
function FileTransfersWindow({
|
||||
transfers,
|
||||
onClearFinished,
|
||||
onClose,
|
||||
}: {
|
||||
transfers: Transfer[];
|
||||
onClearFinished: () => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const t = useT();
|
||||
return (
|
||||
<div className="ts-dialog ts-transfers-window" role="dialog" aria-label={t("transfers.title")}>
|
||||
<div className="ts-dialog-titlebar">
|
||||
<span>{t("transfers.title")}</span>
|
||||
<button onClick={onClose} title={t("dialog.close")} aria-label={t("dialog.close")}>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div className="ts-dialog-body">
|
||||
{transfers.length === 0 ? (
|
||||
<p className="ts-options-placeholder">{t("transfers.empty")}</p>
|
||||
) : (
|
||||
<table className="ts-transfers-table">
|
||||
<tbody>
|
||||
{transfers.map((x) => (
|
||||
<tr key={x.id} className={`ts-transfer-${x.status}`}>
|
||||
<td title={t(`transfers.${x.dir}`)}>{x.dir === "down" ? "⬇" : "⬆"}</td>
|
||||
<td className="ts-transfers-name" title={x.path}>
|
||||
{x.name}
|
||||
</td>
|
||||
<td>
|
||||
<progress value={x.done} max={x.size || 1} />
|
||||
</td>
|
||||
<td>
|
||||
{formatBytes(x.done)} / {formatBytes(x.size)}
|
||||
</td>
|
||||
<td>{t(`transfers.status.${x.status}`)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</div>
|
||||
<div className="ts-dialog-buttons">
|
||||
<div className="ts-dialog-buttons-right">
|
||||
<button onClick={onClearFinished}>{t("transfers.clearFinished")}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function downloadBlob(blob: Blob, filename: string) {
|
||||
@@ -6174,6 +6267,107 @@ function WhisperPanel({ onOpenWhisperLists }: { onOpenWhisperLists: () => void }
|
||||
);
|
||||
}
|
||||
|
||||
function DownloadsPanel() {
|
||||
const t = useT();
|
||||
const { downloads, setDownloads, downloadDir, setDownloadDir } = useContext(DisplayPrefsContext);
|
||||
const set = (patch: Partial<DownloadSettings>) => setDownloads({ ...downloads, ...patch });
|
||||
const limitRow = (key: "uploadLimit" | "downloadLimit") => (
|
||||
<fieldset className="ts-options-fieldset">
|
||||
<legend>{t(`downloadSettings.${key}`)}</legend>
|
||||
<label className="ts-options-radio">
|
||||
<input type="radio" checked={downloads[key] === 0} onChange={() => set({ [key]: 0 })} />
|
||||
{t("downloadSettings.unlimited")}
|
||||
</label>
|
||||
<label className="ts-options-radio">
|
||||
<input type="radio" checked={downloads[key] > 0} onChange={() => set({ [key]: 5 })} />
|
||||
{t("downloadSettings.limitedTo")}
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
className="ts-download-number"
|
||||
value={downloads[key] || 5}
|
||||
disabled={downloads[key] === 0}
|
||||
onChange={(e) => set({ [key]: Math.max(1, Number(e.target.value) || 1) })}
|
||||
/>
|
||||
KiB/s
|
||||
</label>
|
||||
</fieldset>
|
||||
);
|
||||
const countRow = (key: "maxUploads" | "maxDownloads") => (
|
||||
<fieldset className="ts-options-fieldset">
|
||||
<legend>{t(`downloadSettings.${key}`)}</legend>
|
||||
<label className="ts-options-field">
|
||||
{t("downloadSettings.limitedTo")}
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
className="ts-download-number"
|
||||
value={downloads[key]}
|
||||
onChange={(e) => set({ [key]: Math.max(1, Number(e.target.value) || 1) })}
|
||||
/>
|
||||
</label>
|
||||
</fieldset>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<h3>{t("options.section.downloads")}</h3>
|
||||
<p className="ts-options-subtitle">{t("downloadSettings.subtitle")}</p>
|
||||
<div className="ts-options-fields">
|
||||
<fieldset className="ts-options-fieldset">
|
||||
<legend>{t("downloadSettings.directory")}</legend>
|
||||
<div className="ts-download-dir">
|
||||
{t("downloadSettings.directoryLabel")} <strong>{downloadDir?.name ?? t("downloadSettings.browserDefault")}</strong>
|
||||
<button
|
||||
disabled={!canPickFolder}
|
||||
onClick={() => void pickDownloadDir().then((dir) => dir && setDownloadDir(dir))}
|
||||
>
|
||||
{t("downloadSettings.change")}
|
||||
</button>
|
||||
{downloadDir && (
|
||||
<button onClick={() => void clearDownloadDir().then(() => setDownloadDir(null))}>
|
||||
{t("downloadSettings.reset")}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<label className="ts-options-radio">
|
||||
<input type="radio" checked={downloads.saveMode === "dir"} onChange={() => set({ saveMode: "dir" })} />
|
||||
{t("downloadSettings.alwaysDir")}
|
||||
</label>
|
||||
<label className="ts-options-radio">
|
||||
<input
|
||||
type="radio"
|
||||
disabled={!canPickFolder}
|
||||
checked={downloads.saveMode === "ask"}
|
||||
onChange={() => set({ saveMode: "ask" })}
|
||||
/>
|
||||
{t("downloadSettings.askEachTime")}
|
||||
</label>
|
||||
{!canPickFolder && <p className="ts-options-hint">{t("downloadSettings.unsupported")}</p>}
|
||||
</fieldset>
|
||||
<fieldset className="ts-options-fieldset">
|
||||
<legend>{t("downloadSettings.interface")}</legend>
|
||||
{(["showWindowOnStart", "closeWindowWhenDone", "popupWhenDone"] as const).map((key) => (
|
||||
<label key={key} className="ts-options-checkbox">
|
||||
<input type="checkbox" checked={downloads[key]} onChange={(e) => set({ [key]: e.target.checked })} />
|
||||
{t(`downloadSettings.${key}`)}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
<div className="ts-design-native">
|
||||
<div className="ts-design-col">
|
||||
{limitRow("uploadLimit")}
|
||||
{countRow("maxUploads")}
|
||||
</div>
|
||||
<div className="ts-design-col">
|
||||
{limitRow("downloadLimit")}
|
||||
{countRow("maxDownloads")}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function DesignPanel({
|
||||
designSelection,
|
||||
onSelectionChange,
|
||||
@@ -7203,6 +7397,8 @@ function OptionsDialog({
|
||||
<NachrichtenPanel />
|
||||
) : active.id === "whispern" ? (
|
||||
<WhisperPanel onOpenWhisperLists={onOpenWhisperLists} />
|
||||
) : active.id === "downloads" ? (
|
||||
<DownloadsPanel />
|
||||
) : (
|
||||
<>
|
||||
<h3>{t(`options.section.${active.id}`)}</h3>
|
||||
@@ -7684,6 +7880,13 @@ function AppInner() {
|
||||
const [iconPacks, setIconPacks] = useState(loadIconPacks);
|
||||
const [iconPackId, setIconPackId] = useState(loadSelectedIconPack);
|
||||
const [whisperSettings, setWhisperSettings] = useState(loadWhisperSettings);
|
||||
const [downloadSettings, setDownloadSettings] = useState(loadDownloadSettings);
|
||||
const downloadSettingsRef = useRef(downloadSettings);
|
||||
downloadSettingsRef.current = downloadSettings;
|
||||
const [downloadDir, setDownloadDir] = useState<FileSystemDirectoryHandle | null>(null);
|
||||
useEffect(() => {
|
||||
void loadDownloadDir().then(setDownloadDir);
|
||||
}, []);
|
||||
const whisperSettingsRef = useRef(whisperSettings);
|
||||
whisperSettingsRef.current = whisperSettings;
|
||||
const displayPrefs = useMemo(
|
||||
@@ -7708,8 +7911,15 @@ function AppInner() {
|
||||
setWhisperSettings(next);
|
||||
localStorage.setItem(WHISPER_SETTINGS_KEY, JSON.stringify(next));
|
||||
},
|
||||
downloads: downloadSettings,
|
||||
setDownloads: (next: DownloadSettings) => {
|
||||
setDownloadSettings(next);
|
||||
saveDownloadSettings(next);
|
||||
},
|
||||
downloadDir,
|
||||
setDownloadDir,
|
||||
}),
|
||||
[treeOptions, iconPacks, iconPackId, whisperSettings]
|
||||
[treeOptions, iconPacks, iconPackId, whisperSettings, downloadSettings, downloadDir]
|
||||
);
|
||||
const iconPackStyle = iconPackCss(iconPacks.find((p) => p.id === iconPackId));
|
||||
const [micOn, setMicOn] = useState(false);
|
||||
@@ -8513,6 +8723,11 @@ function AppInner() {
|
||||
const pieces = downloadChunks.get(key);
|
||||
if (!pieces) return;
|
||||
pieces.push(data.data);
|
||||
const transfer = findTransfer("down", data.cid, data.path);
|
||||
if (transfer) {
|
||||
transfer.done = data.offset + (data.data.length * 3) / 4;
|
||||
commitTransfers();
|
||||
}
|
||||
if (!data.done) return;
|
||||
downloadChunks.delete(key);
|
||||
data = { type: "fileDownloadData", cid: data.cid, path: data.path, data: pieces.join("") };
|
||||
@@ -8821,8 +9036,15 @@ function AppInner() {
|
||||
}));
|
||||
break;
|
||||
}
|
||||
case "error":
|
||||
case "error": {
|
||||
logClient("error", "Connection", data.message);
|
||||
// ponytail: connector errors carry no transfer id, so the oldest running
|
||||
// transfer of that kind takes the blame. Add an id when that misfires.
|
||||
const msg = String(data.message);
|
||||
const kind = /^download/i.test(msg) ? "down" : /^upload/i.test(msg) ? "up" : /^file transfer/i.test(msg) ? "any" : null;
|
||||
const failed =
|
||||
kind && transfersRef.current.find((x) => x.status === "running" && (kind === "any" || x.dir === kind));
|
||||
if (failed) finishTransfer(failed, false);
|
||||
if (hasConnectedRef.current) {
|
||||
appendLog({ text: data.message, kind: "error" });
|
||||
} else {
|
||||
@@ -8831,6 +9053,7 @@ function AppInner() {
|
||||
updateTabMeta(sessionId, { connecting: false, connected: false });
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "clientConnectionInfo":
|
||||
setClientConnectionInfo({
|
||||
clientId: data.clientId,
|
||||
@@ -8912,14 +9135,26 @@ function AppInner() {
|
||||
setServerIconImages((prev) => ({ ...prev, [data.path]: data.data }));
|
||||
} else {
|
||||
const filename = data.path.split("/").filter(Boolean).pop() ?? "download";
|
||||
triggerBrowserDownload(filename, data.data);
|
||||
const transfer = findTransfer("down", data.cid, data.path);
|
||||
if (!transfer) {
|
||||
triggerBrowserDownload(filename, data.data);
|
||||
break;
|
||||
}
|
||||
const blob = base64Blob(data.data);
|
||||
void writeToTarget(transfer.target ?? null, blob).then((saved) => {
|
||||
if (!saved) downloadBlob(blob, filename);
|
||||
finishTransfer(transfer, true);
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "fileUploadDone":
|
||||
case "fileUploadDone": {
|
||||
const transfer = findTransfer("up", data.cid, data.path);
|
||||
if (transfer) finishTransfer(transfer, true);
|
||||
if (data.cid === 0) handleServerIconsRefresh();
|
||||
else handleFileBrowserRefresh();
|
||||
break;
|
||||
}
|
||||
case "permList":
|
||||
setPermissionsEditorEntries(data.entries);
|
||||
break;
|
||||
@@ -10803,15 +11038,92 @@ function AppInner() {
|
||||
window.setTimeout(handleFileBrowserRefresh, 300);
|
||||
};
|
||||
|
||||
const handleFileBrowserDownload = (entry: FileListEntry) => {
|
||||
// Options -> Download: queue, limits and the transfer window. transfersRef is
|
||||
// the source of truth because socket handlers keep old closures; the state
|
||||
// copy only drives re-renders.
|
||||
const transfersRef = useRef<Transfer[]>([]);
|
||||
const [transfers, setTransfers] = useState<Transfer[]>([]);
|
||||
const [transfersOpen, setTransfersOpen] = useState(false);
|
||||
const [transferToast, setTransferToast] = useState<{ name: string } | null>(null);
|
||||
const nextTransferIdRef = useRef(1);
|
||||
const commitTransfers = () => setTransfers([...transfersRef.current]);
|
||||
|
||||
const enqueueTransfer = (x: Omit<Transfer, "id" | "done" | "status">) => {
|
||||
transfersRef.current.push({ ...x, id: nextTransferIdRef.current++, done: 0, status: "queued" });
|
||||
if (downloadSettings.showWindowOnStart) setTransfersOpen(true);
|
||||
commitTransfers();
|
||||
};
|
||||
|
||||
const findTransfer = (dir: Transfer["dir"], cid: number, path: string) =>
|
||||
transfersRef.current.find((x) => x.status === "running" && x.dir === dir && x.cid === cid && x.path === path);
|
||||
|
||||
const finishTransfer = (x: Transfer, ok: boolean) => {
|
||||
x.status = ok ? "done" : "error";
|
||||
if (ok) x.done = x.size;
|
||||
const settings = downloadSettingsRef.current;
|
||||
if (ok && settings.popupWhenDone) setTransferToast({ name: x.name });
|
||||
if (settings.closeWindowWhenDone && transfersRef.current.every((y) => y.status === "done")) setTransfersOpen(false);
|
||||
commitTransfers();
|
||||
};
|
||||
|
||||
// Start queued transfers while under the "Gleichzeitige Uploads/Downloads" caps.
|
||||
useEffect(() => {
|
||||
let started = false;
|
||||
for (const dir of ["down", "up"] as const) {
|
||||
const max = dir === "down" ? downloadSettings.maxDownloads : downloadSettings.maxUploads;
|
||||
let running = transfersRef.current.filter((x) => x.dir === dir && x.status === "running").length;
|
||||
for (const x of transfersRef.current) {
|
||||
if (running >= max) break;
|
||||
if (x.dir !== dir || x.status !== "queued") continue;
|
||||
x.status = "running";
|
||||
running++;
|
||||
started = true;
|
||||
if (dir === "down")
|
||||
socketRef.current?.send(JSON.stringify({ type: "downloadFile", channelId: x.cid, path: x.path }));
|
||||
else void sendUpload(x.cid, x.path, x.file!, x);
|
||||
}
|
||||
}
|
||||
if (started) commitTransfers();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [transfers, downloadSettings.maxDownloads, downloadSettings.maxUploads]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!transferToast) return;
|
||||
const id = window.setTimeout(() => setTransferToast(null), 4000);
|
||||
return () => window.clearTimeout(id);
|
||||
}, [transferToast]);
|
||||
|
||||
// Bandwidth caps are enforced by the connector; resend for every new connection.
|
||||
const sentTransferLimitRef = useRef<{ socket: WebSocket | DemoSocket | null; payload: string }>({
|
||||
socket: null,
|
||||
payload: "",
|
||||
});
|
||||
useEffect(() => {
|
||||
const socket = socketRef.current;
|
||||
if (!connected || !socket) return;
|
||||
const payload = JSON.stringify({
|
||||
type: "setTransferLimit",
|
||||
up: downloadSettings.uploadLimit * 1024,
|
||||
down: downloadSettings.downloadLimit * 1024,
|
||||
});
|
||||
const sent = sentTransferLimitRef.current;
|
||||
if (sent.socket === socket && sent.payload === payload) return;
|
||||
socket.send(payload);
|
||||
sentTransferLimitRef.current = { socket, payload };
|
||||
}, [connected, activeSessionId, downloadSettings.uploadLimit, downloadSettings.downloadLimit]);
|
||||
|
||||
const handleFileBrowserDownload = async (entry: FileListEntry) => {
|
||||
if (!fileBrowserTarget) return;
|
||||
socketRef.current?.send(
|
||||
JSON.stringify({
|
||||
type: "downloadFile",
|
||||
channelId: fileBrowserTarget.channelId,
|
||||
path: ftJoinPath(fileBrowserPath, entry.name),
|
||||
})
|
||||
);
|
||||
const target = await resolveSaveTarget(downloadSettings, downloadDir, entry.name);
|
||||
if (target === "cancelled") return;
|
||||
enqueueTransfer({
|
||||
dir: "down",
|
||||
cid: fileBrowserTarget.channelId,
|
||||
path: ftJoinPath(fileBrowserPath, entry.name),
|
||||
name: entry.name,
|
||||
size: entry.size,
|
||||
target,
|
||||
});
|
||||
};
|
||||
|
||||
// The connector refuses anything bigger. Gateways without "chunkedUpload"
|
||||
@@ -10825,13 +11137,20 @@ function AppInner() {
|
||||
const handleFileBrowserUpload = (file: File) => {
|
||||
if (!fileBrowserTarget) return;
|
||||
if (rejectOversizedUpload(file)) return;
|
||||
void sendUpload(fileBrowserTarget.channelId, ftJoinPath(fileBrowserPath, file.name), file);
|
||||
enqueueTransfer({
|
||||
dir: "up",
|
||||
cid: fileBrowserTarget.channelId,
|
||||
path: ftJoinPath(fileBrowserPath, file.name),
|
||||
name: file.name,
|
||||
size: file.size,
|
||||
file,
|
||||
});
|
||||
};
|
||||
|
||||
// Small pieces keep the gateway from holding a whole file (several times
|
||||
// over) in memory. 192 KiB is a multiple of 3, so each piece base64-encodes
|
||||
// on its own without padding.
|
||||
const sendUpload = async (channelId: number, path: string, file: File) => {
|
||||
const sendUpload = async (channelId: number, path: string, file: File, transfer?: Transfer) => {
|
||||
const socket = socketRef.current;
|
||||
if (!gatewayFeatures.has("chunkedUpload")) {
|
||||
socket?.send(JSON.stringify({ type: "uploadFile", channelId, path, dataBase64: await readBase64(file) }));
|
||||
@@ -10842,6 +11161,10 @@ function AppInner() {
|
||||
for (let offset = 0; offset === 0 || offset < file.size; offset += chunkBytes) {
|
||||
const data = await readBase64(file.slice(offset, offset + chunkBytes));
|
||||
socket?.send(JSON.stringify({ type: "uploadFileChunk", channelId, path, offset, total: file.size, data }));
|
||||
if (transfer) {
|
||||
transfer.done = Math.min(file.size, offset + chunkBytes);
|
||||
commitTransfers();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11337,6 +11660,16 @@ function AppInner() {
|
||||
<span className="ts-menu-item-icon">🧑🤝🧑</span>
|
||||
<span className="ts-menu-item-label">{t("menu.extras.inviteFriend")}</span>
|
||||
</button>
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
onClick={() => {
|
||||
setTransfersOpen(true);
|
||||
setExtrasMenuOpen(false);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">⇅</span>
|
||||
<span className="ts-menu-item-label">{t("menu.extras.fileTransfers")}</span>
|
||||
</button>
|
||||
<div className="ts-menu-separator" />
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
@@ -11881,6 +12214,21 @@ function AppInner() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{transfersOpen && (
|
||||
<FileTransfersWindow
|
||||
transfers={transfers}
|
||||
onClearFinished={() => {
|
||||
transfersRef.current = transfersRef.current.filter((x) => x.status === "queued" || x.status === "running");
|
||||
commitTransfers();
|
||||
}}
|
||||
onClose={() => setTransfersOpen(false)}
|
||||
/>
|
||||
)}
|
||||
{transferToast && (
|
||||
<div className="ts-transfer-toast" role="status">
|
||||
{t("transfers.finished", { name: transferToast.name })}
|
||||
</div>
|
||||
)}
|
||||
{restartNotice && <RestartNoticeDialog message={restartNotice} onAck={() => setRestartNotice(null)} />}
|
||||
|
||||
{aboutOpen && (
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
/** Options -> Download (TS3's "Downloads" page). */
|
||||
export interface DownloadSettings {
|
||||
/** "dir": save into the picked folder (browser default when none); "ask": save dialog every time. */
|
||||
saveMode: "dir" | "ask";
|
||||
showWindowOnStart: boolean;
|
||||
closeWindowWhenDone: boolean;
|
||||
popupWhenDone: boolean;
|
||||
/** KiB/s, 0 = unlimited. */
|
||||
uploadLimit: number;
|
||||
downloadLimit: number;
|
||||
maxUploads: number;
|
||||
maxDownloads: number;
|
||||
}
|
||||
|
||||
export const DEFAULT_DOWNLOAD_SETTINGS: DownloadSettings = {
|
||||
saveMode: "dir",
|
||||
showWindowOnStart: true,
|
||||
closeWindowWhenDone: false,
|
||||
popupWhenDone: true,
|
||||
uploadLimit: 0,
|
||||
downloadLimit: 0,
|
||||
maxUploads: 2,
|
||||
maxDownloads: 2,
|
||||
};
|
||||
|
||||
const SETTINGS_KEY = "webspeak3:download-settings";
|
||||
|
||||
export function loadDownloadSettings(): DownloadSettings {
|
||||
try {
|
||||
return { ...DEFAULT_DOWNLOAD_SETTINGS, ...JSON.parse(localStorage.getItem(SETTINGS_KEY) ?? "{}") };
|
||||
} catch {
|
||||
return DEFAULT_DOWNLOAD_SETTINGS;
|
||||
}
|
||||
}
|
||||
|
||||
export function saveDownloadSettings(settings: DownloadSettings): void {
|
||||
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
|
||||
}
|
||||
|
||||
// File System Access API: Chromium only. Elsewhere downloads go wherever the browser puts them.
|
||||
type PickerWindow = Window & {
|
||||
showDirectoryPicker?: (options?: { mode?: "readwrite" }) => Promise<FileSystemDirectoryHandle>;
|
||||
showSaveFilePicker?: (options?: { suggestedName?: string }) => Promise<FileSystemFileHandle>;
|
||||
};
|
||||
type PermissionHandle = FileSystemHandle & {
|
||||
queryPermission?: (d: { mode: "readwrite" }) => Promise<PermissionState>;
|
||||
requestPermission?: (d: { mode: "readwrite" }) => Promise<PermissionState>;
|
||||
};
|
||||
|
||||
export const canPickFolder = typeof (window as PickerWindow).showDirectoryPicker === "function";
|
||||
|
||||
// A directory handle survives reloads only in IndexedDB (it can't be JSON'd).
|
||||
function withStore<T>(mode: IDBTransactionMode, run: (store: IDBObjectStore) => IDBRequest<T>): Promise<T> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const open = indexedDB.open("webspeak3-downloads", 1);
|
||||
open.onupgradeneeded = () => open.result.createObjectStore("handles");
|
||||
open.onerror = () => reject(open.error);
|
||||
open.onsuccess = () => {
|
||||
const req = run(open.result.transaction("handles", mode).objectStore("handles"));
|
||||
req.onsuccess = () => resolve(req.result);
|
||||
req.onerror = () => reject(req.error);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export async function loadDownloadDir(): Promise<FileSystemDirectoryHandle | null> {
|
||||
if (!canPickFolder) return null;
|
||||
try {
|
||||
return (await withStore("readonly", (s) => s.get("dir"))) ?? null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Opens the folder picker; null when cancelled. */
|
||||
export async function pickDownloadDir(): Promise<FileSystemDirectoryHandle | null> {
|
||||
try {
|
||||
const dir = await (window as PickerWindow).showDirectoryPicker!({ mode: "readwrite" });
|
||||
await withStore("readwrite", (s) => s.put(dir, "dir"));
|
||||
return dir;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function clearDownloadDir(): Promise<void> {
|
||||
await withStore("readwrite", (s) => s.delete("dir")).catch(() => {});
|
||||
}
|
||||
|
||||
/** Where a finished download goes; resolved at click time, while the user gesture
|
||||
* still lets us show a save dialog or ask for folder permission. null = browser default. */
|
||||
export type SaveTarget = FileSystemFileHandle | null;
|
||||
|
||||
export async function resolveSaveTarget(
|
||||
settings: DownloadSettings,
|
||||
dir: FileSystemDirectoryHandle | null,
|
||||
filename: string
|
||||
): Promise<SaveTarget | "cancelled"> {
|
||||
const w = window as PickerWindow;
|
||||
if (settings.saveMode === "ask" && w.showSaveFilePicker) {
|
||||
try {
|
||||
return await w.showSaveFilePicker({ suggestedName: filename });
|
||||
} catch {
|
||||
return "cancelled";
|
||||
}
|
||||
}
|
||||
if (!dir) return null;
|
||||
const handle = dir as PermissionHandle;
|
||||
try {
|
||||
if ((await handle.queryPermission?.({ mode: "readwrite" })) !== "granted" &&
|
||||
(await handle.requestPermission?.({ mode: "readwrite" })) !== "granted")
|
||||
return null;
|
||||
return await dir.getFileHandle(filename, { create: true });
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Writes into the chosen file; false means fall back to a normal browser download. */
|
||||
export async function writeToTarget(target: SaveTarget, blob: Blob): Promise<boolean> {
|
||||
if (!target) return false;
|
||||
try {
|
||||
const writable = await target.createWritable();
|
||||
await writable.write(blob);
|
||||
await writable.close();
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -743,5 +743,35 @@
|
||||
"about.text": "WebSpeak3 je TeamSpeak klient pro prohlížeč, open source a bez instalace.",
|
||||
"about.memorial.title": "Na památku Akima",
|
||||
"about.memorial.text": "Odešel přes duhový most 21. 10. 2026. 🌈🐾",
|
||||
"about.close": "Zavřít"
|
||||
"about.close": "Zavřít",
|
||||
"menu.extras.fileTransfers": "Přenosy souborů",
|
||||
"transfers.title": "Přenosy souborů",
|
||||
"transfers.empty": "Žádné přenosy.",
|
||||
"transfers.up": "Nahrávání",
|
||||
"transfers.down": "Stahování",
|
||||
"transfers.status.queued": "Čeká",
|
||||
"transfers.status.running": "Probíhá",
|
||||
"transfers.status.done": "Hotovo",
|
||||
"transfers.status.error": "Selhalo",
|
||||
"transfers.clearFinished": "Odstranit dokončené",
|
||||
"transfers.finished": "Přenos dokončen: {name}",
|
||||
"downloadSettings.subtitle": "Nastavení stahování",
|
||||
"downloadSettings.directory": "Složka pro stahování",
|
||||
"downloadSettings.directoryLabel": "Složka pro stažené soubory:",
|
||||
"downloadSettings.browserDefault": "Výchozí prohlížeče",
|
||||
"downloadSettings.change": "Změnit",
|
||||
"downloadSettings.reset": "Obnovit",
|
||||
"downloadSettings.alwaysDir": "Vždy ukládat do této složky",
|
||||
"downloadSettings.askEachTime": "Pokaždé se ptát na složku",
|
||||
"downloadSettings.unsupported": "Tento prohlížeč neumí vybrat složku; soubory se ukládají do složky stahování prohlížeče.",
|
||||
"downloadSettings.interface": "Rozhraní",
|
||||
"downloadSettings.showWindowOnStart": "Zobrazit okno přenosů při zahájení stahování",
|
||||
"downloadSettings.closeWindowWhenDone": "Zavřít okno přenosů po dokončení všech stahování",
|
||||
"downloadSettings.popupWhenDone": "Zobrazit oznámení po dokončení přenosu",
|
||||
"downloadSettings.uploadLimit": "Šířka pásma pro nahrávání",
|
||||
"downloadSettings.downloadLimit": "Šířka pásma pro stahování",
|
||||
"downloadSettings.maxUploads": "Souběžná nahrávání",
|
||||
"downloadSettings.maxDownloads": "Souběžná stahování",
|
||||
"downloadSettings.unlimited": "Neomezovat",
|
||||
"downloadSettings.limitedTo": "Omezit na"
|
||||
}
|
||||
+31
-1
@@ -743,5 +743,35 @@
|
||||
"about.text": "WebSpeak3 ist ein TeamSpeak-Client für den Browser, quelloffen und ohne Installation.",
|
||||
"about.memorial.title": "In Erinnerung an Akimo",
|
||||
"about.memorial.text": "Am 21.10.2026 über die Regenbogenbrücke gegangen. 🌈🐾",
|
||||
"about.close": "Schließen"
|
||||
"about.close": "Schließen",
|
||||
"menu.extras.fileTransfers": "Dateiübertragungen",
|
||||
"transfers.title": "Dateiübertragungen",
|
||||
"transfers.empty": "Keine Übertragungen.",
|
||||
"transfers.up": "Upload",
|
||||
"transfers.down": "Download",
|
||||
"transfers.status.queued": "Wartet",
|
||||
"transfers.status.running": "Läuft",
|
||||
"transfers.status.done": "Fertig",
|
||||
"transfers.status.error": "Fehlgeschlagen",
|
||||
"transfers.clearFinished": "Beendete entfernen",
|
||||
"transfers.finished": "Übertragung beendet: {name}",
|
||||
"downloadSettings.subtitle": "Download Einstellungen",
|
||||
"downloadSettings.directory": "Download Verzeichnis",
|
||||
"downloadSettings.directoryLabel": "Verzeichnis für Downloads:",
|
||||
"downloadSettings.browserDefault": "Browser-Standard",
|
||||
"downloadSettings.change": "Ändern",
|
||||
"downloadSettings.reset": "Zurücksetzen",
|
||||
"downloadSettings.alwaysDir": "Immer in dieses Verzeichnis speichern",
|
||||
"downloadSettings.askEachTime": "Jedesmal nach Downloadverzeichnis fragen",
|
||||
"downloadSettings.unsupported": "Dieser Browser kann keinen Ordner wählen; Downloads landen im Download-Ordner des Browsers.",
|
||||
"downloadSettings.interface": "Interface",
|
||||
"downloadSettings.showWindowOnStart": "Das Dateitransfer Fenster anzeigen, wenn ein Download startet",
|
||||
"downloadSettings.closeWindowWhenDone": "Das Dateitransfer Fenster schließen, wenn alle Downloads beendet wurden",
|
||||
"downloadSettings.popupWhenDone": "Pop-up bei beendeten Übertragungen einblenden",
|
||||
"downloadSettings.uploadLimit": "Upload-Bandbreite",
|
||||
"downloadSettings.downloadLimit": "Download-Bandbreite",
|
||||
"downloadSettings.maxUploads": "Gleichzeitige Uploads",
|
||||
"downloadSettings.maxDownloads": "Gleichzeitige Downloads",
|
||||
"downloadSettings.unlimited": "Nicht limitieren",
|
||||
"downloadSettings.limitedTo": "Limitiert auf"
|
||||
}
|
||||
+31
-1
@@ -743,5 +743,35 @@
|
||||
"about.text": "WebSpeak3 is a TeamSpeak client for the browser, open source and with nothing to install.",
|
||||
"about.memorial.title": "In memory of Akimo",
|
||||
"about.memorial.text": "Crossed the rainbow bridge on October 21, 2026. 🌈🐾",
|
||||
"about.close": "Close"
|
||||
"about.close": "Close",
|
||||
"menu.extras.fileTransfers": "File transfers",
|
||||
"transfers.title": "File transfers",
|
||||
"transfers.empty": "No transfers.",
|
||||
"transfers.up": "Upload",
|
||||
"transfers.down": "Download",
|
||||
"transfers.status.queued": "Queued",
|
||||
"transfers.status.running": "Running",
|
||||
"transfers.status.done": "Done",
|
||||
"transfers.status.error": "Failed",
|
||||
"transfers.clearFinished": "Remove finished",
|
||||
"transfers.finished": "Transfer finished: {name}",
|
||||
"downloadSettings.subtitle": "Download settings",
|
||||
"downloadSettings.directory": "Download directory",
|
||||
"downloadSettings.directoryLabel": "Directory for downloads:",
|
||||
"downloadSettings.browserDefault": "Browser default",
|
||||
"downloadSettings.change": "Change",
|
||||
"downloadSettings.reset": "Reset",
|
||||
"downloadSettings.alwaysDir": "Always save to this directory",
|
||||
"downloadSettings.askEachTime": "Ask for the download directory every time",
|
||||
"downloadSettings.unsupported": "This browser can't pick a folder; downloads go to the browser's download folder.",
|
||||
"downloadSettings.interface": "Interface",
|
||||
"downloadSettings.showWindowOnStart": "Show the file transfer window when a download starts",
|
||||
"downloadSettings.closeWindowWhenDone": "Close the file transfer window when all downloads are finished",
|
||||
"downloadSettings.popupWhenDone": "Show a pop-up when transfers finish",
|
||||
"downloadSettings.uploadLimit": "Upload bandwidth",
|
||||
"downloadSettings.downloadLimit": "Download bandwidth",
|
||||
"downloadSettings.maxUploads": "Simultaneous uploads",
|
||||
"downloadSettings.maxDownloads": "Simultaneous downloads",
|
||||
"downloadSettings.unlimited": "Unlimited",
|
||||
"downloadSettings.limitedTo": "Limited to"
|
||||
}
|
||||
+31
-1
@@ -742,5 +742,35 @@
|
||||
"about.text": "WebSpeak3 یک کلاینت TeamSpeak برای مرورگر است، متنباز و بدون نیاز به نصب.",
|
||||
"about.memorial.title": "به یاد Akimo",
|
||||
"about.memorial.text": "در ۲۱ اکتبر ۲۰۲۶ از پل رنگینکمان گذشت. 🌈🐾",
|
||||
"about.close": "بستن"
|
||||
"about.close": "بستن",
|
||||
"menu.extras.fileTransfers": "انتقال فایلها",
|
||||
"transfers.title": "انتقال فایلها",
|
||||
"transfers.empty": "انتقالی وجود ندارد.",
|
||||
"transfers.up": "آپلود",
|
||||
"transfers.down": "دانلود",
|
||||
"transfers.status.queued": "در صف",
|
||||
"transfers.status.running": "در حال انجام",
|
||||
"transfers.status.done": "تمام شد",
|
||||
"transfers.status.error": "ناموفق",
|
||||
"transfers.clearFinished": "حذف تمامشدهها",
|
||||
"transfers.finished": "انتقال تمام شد: {name}",
|
||||
"downloadSettings.subtitle": "تنظیمات دانلود",
|
||||
"downloadSettings.directory": "پوشه دانلود",
|
||||
"downloadSettings.directoryLabel": "پوشه برای دانلودها:",
|
||||
"downloadSettings.browserDefault": "پیشفرض مرورگر",
|
||||
"downloadSettings.change": "تغییر",
|
||||
"downloadSettings.reset": "بازنشانی",
|
||||
"downloadSettings.alwaysDir": "همیشه در این پوشه ذخیره شود",
|
||||
"downloadSettings.askEachTime": "هر بار پوشه دانلود پرسیده شود",
|
||||
"downloadSettings.unsupported": "این مرورگر نمیتواند پوشه انتخاب کند؛ دانلودها در پوشه دانلود مرورگر ذخیره میشوند.",
|
||||
"downloadSettings.interface": "رابط",
|
||||
"downloadSettings.showWindowOnStart": "نمایش پنجره انتقال فایل هنگام شروع دانلود",
|
||||
"downloadSettings.closeWindowWhenDone": "بستن پنجره انتقال فایل پس از پایان همه دانلودها",
|
||||
"downloadSettings.popupWhenDone": "نمایش پیام پس از پایان انتقال",
|
||||
"downloadSettings.uploadLimit": "پهنای باند آپلود",
|
||||
"downloadSettings.downloadLimit": "پهنای باند دانلود",
|
||||
"downloadSettings.maxUploads": "آپلودهای همزمان",
|
||||
"downloadSettings.maxDownloads": "دانلودهای همزمان",
|
||||
"downloadSettings.unlimited": "بدون محدودیت",
|
||||
"downloadSettings.limitedTo": "محدود به"
|
||||
}
|
||||
@@ -742,5 +742,35 @@
|
||||
"about.text": "WebSpeak3 是一款浏览器 TeamSpeak 客户端,开源且无需安装。",
|
||||
"about.memorial.title": "纪念 Akimo",
|
||||
"about.memorial.text": "于 2026 年 10 月 21 日走过彩虹桥。🌈🐾",
|
||||
"about.close": "关闭"
|
||||
"about.close": "关闭",
|
||||
"menu.extras.fileTransfers": "文件传输",
|
||||
"transfers.title": "文件传输",
|
||||
"transfers.empty": "没有传输。",
|
||||
"transfers.up": "上传",
|
||||
"transfers.down": "下载",
|
||||
"transfers.status.queued": "排队中",
|
||||
"transfers.status.running": "进行中",
|
||||
"transfers.status.done": "完成",
|
||||
"transfers.status.error": "失败",
|
||||
"transfers.clearFinished": "移除已完成",
|
||||
"transfers.finished": "传输完成:{name}",
|
||||
"downloadSettings.subtitle": "下载设置",
|
||||
"downloadSettings.directory": "下载目录",
|
||||
"downloadSettings.directoryLabel": "下载目录:",
|
||||
"downloadSettings.browserDefault": "浏览器默认",
|
||||
"downloadSettings.change": "更改",
|
||||
"downloadSettings.reset": "重置",
|
||||
"downloadSettings.alwaysDir": "始终保存到此目录",
|
||||
"downloadSettings.askEachTime": "每次询问下载目录",
|
||||
"downloadSettings.unsupported": "此浏览器无法选择文件夹;下载将保存到浏览器的下载文件夹。",
|
||||
"downloadSettings.interface": "界面",
|
||||
"downloadSettings.showWindowOnStart": "开始下载时显示文件传输窗口",
|
||||
"downloadSettings.closeWindowWhenDone": "所有下载完成后关闭文件传输窗口",
|
||||
"downloadSettings.popupWhenDone": "传输完成时显示弹出提示",
|
||||
"downloadSettings.uploadLimit": "上传带宽",
|
||||
"downloadSettings.downloadLimit": "下载带宽",
|
||||
"downloadSettings.maxUploads": "同时上传数",
|
||||
"downloadSettings.maxDownloads": "同时下载数",
|
||||
"downloadSettings.unlimited": "不限制",
|
||||
"downloadSettings.limitedTo": "限制为"
|
||||
}
|
||||
Reference in new issue
Block a user