vomebook commited on
Commit ·
e68c837
1
Parent(s): d749c51
Keep folder preview available during load failures
Browse files- static/app.js +12 -2
- tests/test_browser.py +8 -0
static/app.js
CHANGED
|
@@ -2952,14 +2952,24 @@ async function renderBrowser(path, routeId) {
|
|
| 2952 |
if ((!routeId || routeId === routeRenderId) && STATE.mode === "repo" && STATE.browserPath === path) {
|
| 2953 |
const retryKey = STATE.repo + "|" + (path || "");
|
| 2954 |
const tries = sidebarRetryCounts.get(retryKey) || 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2955 |
if (tries < 2) {
|
| 2956 |
sidebarRetryCounts.set(retryKey, tries + 1);
|
| 2957 |
-
|
| 2958 |
setTimeout(() => {
|
| 2959 |
if ((!routeId || routeId === routeRenderId) && STATE.mode === "repo" && STATE.browserPath === path) renderBrowser(path, routeId || routeRenderId);
|
| 2960 |
}, 1200);
|
| 2961 |
} else {
|
| 2962 |
-
|
| 2963 |
}
|
| 2964 |
}
|
| 2965 |
}
|
|
|
|
| 2952 |
if ((!routeId || routeId === routeRenderId) && STATE.mode === "repo" && STATE.browserPath === path) {
|
| 2953 |
const retryKey = STATE.repo + "|" + (path || "");
|
| 2954 |
const tries = sidebarRetryCounts.get(retryKey) || 0;
|
| 2955 |
+
const showError = text => {
|
| 2956 |
+
let message = displayedData?.folders?.length ? list.querySelector(".sidebar-loading") : null;
|
| 2957 |
+
if (!message && displayedData?.folders?.length) {
|
| 2958 |
+
message = document.createElement("div");
|
| 2959 |
+
message.className = "sidebar-loading";
|
| 2960 |
+
list.appendChild(message);
|
| 2961 |
+
}
|
| 2962 |
+
if (message) message.textContent = text;
|
| 2963 |
+
else list.innerHTML = `<div class="sidebar-loading">${text}</div>`;
|
| 2964 |
+
};
|
| 2965 |
if (tries < 2) {
|
| 2966 |
sidebarRetryCounts.set(retryKey, tries + 1);
|
| 2967 |
+
showError("加载失败,正在重试...");
|
| 2968 |
setTimeout(() => {
|
| 2969 |
if ((!routeId || routeId === routeRenderId) && STATE.mode === "repo" && STATE.browserPath === path) renderBrowser(path, routeId || routeRenderId);
|
| 2970 |
}, 1200);
|
| 2971 |
} else {
|
| 2972 |
+
showError("加载失败");
|
| 2973 |
}
|
| 2974 |
}
|
| 2975 |
}
|
tests/test_browser.py
CHANGED
|
@@ -343,6 +343,13 @@ class BrowserInteractionTests(unittest.TestCase):
|
|
| 343 |
}))
|
| 344 |
page.locator('.browser-item[data-type="file"] .browser-name').wait_for()
|
| 345 |
self.assertEqual(page.locator('.browser-item[data-type="file"] .browser-name').text_content(), "nested.txt")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
self.assertEqual(errors, [])
|
| 347 |
finally:
|
| 348 |
context.close()
|
|
@@ -1102,6 +1109,7 @@ class BrowserInteractionTests(unittest.TestCase):
|
|
| 1102 |
page.evaluate("url => navigateToReader(url)", first_url)
|
| 1103 |
page.frame_locator("iframe.reader-overlay").locator("#back").wait_for()
|
| 1104 |
reader_frame = next(frame for frame in page.frames if frame.parent_frame is not None and "/static/reader.html" in frame.url)
|
|
|
|
| 1105 |
reader_frame.evaluate("""async (readerUrl) => VoiceOfMLReaderStore.put({
|
| 1106 |
url: 'https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/second.txt',
|
| 1107 |
title: '第二本.txt', extension: 'txt', readerUrl, page: 1, pageCount: 0, lastReadAt: Date.now()
|
|
|
|
| 343 |
}))
|
| 344 |
page.locator('.browser-item[data-type="file"] .browser-name').wait_for()
|
| 345 |
self.assertEqual(page.locator('.browser-item[data-type="file"] .browser-name').text_content(), "nested.txt")
|
| 346 |
+
page.evaluate("API._browserCache.delete('Test|docs')")
|
| 347 |
+
page.route(self.base_url + "/api/folders/Test/contents?path=docs",
|
| 348 |
+
lambda route: route.fulfill(status=500, body='{}'))
|
| 349 |
+
page.evaluate("ROUTER.navigate('repo', 'Test', 'docs')")
|
| 350 |
+
page.locator('.browser-list .sidebar-loading').filter(has_text="正在重试").wait_for(timeout=5000)
|
| 351 |
+
page.locator('.browser-item[data-type="folder"][data-path="docs/nested"]').click()
|
| 352 |
+
page.locator('.browser-item[data-type="file"] .browser-name').filter(has_text="nested.txt").wait_for()
|
| 353 |
self.assertEqual(errors, [])
|
| 354 |
finally:
|
| 355 |
context.close()
|
|
|
|
| 1109 |
page.evaluate("url => navigateToReader(url)", first_url)
|
| 1110 |
page.frame_locator("iframe.reader-overlay").locator("#back").wait_for()
|
| 1111 |
reader_frame = next(frame for frame in page.frames if frame.parent_frame is not None and "/static/reader.html" in frame.url)
|
| 1112 |
+
page.wait_for_function("() => !!document.querySelector('iframe.reader-overlay')?.contentWindow?.VoiceOfMLReaderStore")
|
| 1113 |
reader_frame.evaluate("""async (readerUrl) => VoiceOfMLReaderStore.put({
|
| 1114 |
url: 'https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/second.txt',
|
| 1115 |
title: '第二本.txt', extension: 'txt', readerUrl, page: 1, pageCount: 0, lastReadAt: Date.now()
|