feat: search streaming fallback
This commit is contained in:
parent
9891e9db2d
commit
771170fe6c
@ -19,6 +19,8 @@ export default async function search(
|
|||||||
throw new StatusError("000 No connection", 0);
|
throw new StatusError("000 No connection", 0);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
// Try streaming approach first (modern browsers)
|
||||||
|
if (res.body && typeof res.body.pipeThrough === "function") {
|
||||||
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
|
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
|
||||||
let buffer = "";
|
let buffer = "";
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -46,6 +48,21 @@ export default async function search(
|
|||||||
}
|
}
|
||||||
if (done) break;
|
if (done) break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Fallback for browsers without streaming support (e.g., Safari)
|
||||||
|
const text = await res.text();
|
||||||
|
const lines = text.split(/\n/);
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line) {
|
||||||
|
const item = JSON.parse(line) as ResourceItem;
|
||||||
|
item.url = `/files${base}` + url.encodePath(item.path);
|
||||||
|
if (item.isDir) {
|
||||||
|
item.url += "/";
|
||||||
|
}
|
||||||
|
callback(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Check if the error is an intentional cancellation
|
// Check if the error is an intentional cancellation
|
||||||
if (e instanceof Error && e.name === "AbortError") {
|
if (e instanceof Error && e.name === "AbortError") {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user