omarod2in commited on
Commit
fa4ef05
·
verified ·
1 Parent(s): 4113c8b

return to Deepseek working after multiple failed

Browse files
Files changed (2) hide show
  1. server/index.js +34 -37
  2. src/App.tsx +4 -7
server/index.js CHANGED
@@ -1755,15 +1755,11 @@ app.get("/api/remote/test", async (req, res) => {
1755
 
1756
  app.get("/api/remote/list", async (req, res) => {
1757
  const baseUrl = String(req.query.url || "").trim().replace(/\/+$/, "");
 
 
1758
  const hfToken = String(req.query.hfToken || "").trim();
1759
  if (!baseUrl) return res.status(400).json({ error: "url query param is required" });
1760
-
1761
- // Extract and sanitize path
1762
- let rawPath = String(req.query.path || "").trim();
1763
- if (rawPath === "null" || rawPath === "undefined" || rawPath === "/") rawPath = "";
1764
- const remotePath = rawPath.replace(/^\//, "").replace(/\/+$/, "");
1765
- const listPath = remotePath ? "/" + remotePath : "";
1766
-
1767
  // Send response quickly - don't let HF gateway timeout
1768
  const startTime = Date.now();
1769
 
@@ -1843,59 +1839,60 @@ app.get("/api/remote/list", async (req, res) => {
1843
  }
1844
  }
1845
 
1846
- // Strategy 1: only for subdirectories (path required)
1847
- if (remotePath) {
1848
- try {
1849
- const fetchUrl1 = `${baseUrl}/files?path=${encodeURIComponent(listPath)}`;
1850
- console.log(`[Remote] Strategy 1: GET ${fetchUrl1}`);
1851
- const response = await fetchWithTimeout(fetchUrl1, {
1852
- headers: { "Accept": "application/json" },
1853
- }, 5000);
1854
- console.log(`[Remote] Strategy 1 response status: ${response.status}`);
1855
- if (response.ok) {
1856
- const text = await response.text();
1857
- console.log(`[Remote] Strategy 1 response length: ${text.length} chars`);
1858
- try {
1859
- entries = parseJsonListing(text);
1860
- console.log(`[Remote] Strategy 1 parsed ${entries.length} entries`);
1861
- } catch (parseErr) {
1862
- fetchError = `GET /files returned non-JSON: ${text.substring(0, 100)}`;
1863
- console.log(`[Remote] Strategy 1 parse failed: ${fetchError}`);
1864
- }
1865
- } else {
1866
- fetchError = `GET /files returned ${response.status}`;
1867
- console.log(`[Remote] Strategy 1 failed: ${fetchError}`);
1868
  }
1869
- } catch (err) {
1870
- fetchError = err.message || "Failed to connect";
1871
- console.log(`[Remote] Strategy 1 error: ${fetchError}`);
1872
  }
 
 
 
1873
  }
1874
 
1875
- // Strategy 2: If /files failed or root, try HTML directory listing
1876
  if (!entries || entries.length === 0) {
1877
  try {
1878
- const fetchUrl2 = remotePath ? `${baseUrl}/${remotePath}/` : `${baseUrl}/`;
1879
- console.log(`[Remote] Strategy 2: GET ${fetchUrl2}`);
1880
  const rootResponse = await fetchWithTimeout(fetchUrl2, {}, 5000);
1881
  console.log(`[Remote] Strategy 2 response status: ${rootResponse.status}`);
1882
  if (rootResponse.ok) {
1883
  const html = await rootResponse.text();
1884
  console.log(`[Remote] Strategy 2 response length: ${html.length} chars`);
 
1885
  try {
1886
  entries = parseJsonListing(html);
1887
  console.log(`[Remote] Strategy 2 parsed as JSON: ${entries.length} entries`);
1888
  } catch {
 
1889
  const htmlEntries = parseHtmlListing(html);
1890
  console.log(`[Remote] Strategy 2 parsed as HTML: ${htmlEntries.length} entries`);
1891
  if (htmlEntries.length > 0) {
1892
  entries = htmlEntries;
1893
- fetchError = null;
1894
  }
1895
  }
1896
  }
1897
  } catch (err) {
1898
  console.log(`[Remote] Strategy 2 error: ${err.message}`);
 
1899
  }
1900
  }
1901
 
@@ -2206,4 +2203,4 @@ app.listen(PORT, HOST, () => {
2206
  console.log(`Server running on http://${HOST}:${PORT}`);
2207
  console.log(`downloads: ${DOWNLOADS_DIR}`);
2208
  console.log(`encoded: ${ENCODED_DIR}`);
2209
- });
 
1755
 
1756
  app.get("/api/remote/list", async (req, res) => {
1757
  const baseUrl = String(req.query.url || "").trim().replace(/\/+$/, "");
1758
+ const remotePath = String(req.query.path || "").trim().replace(/^\//, "").replace(/\/+$/, "");
1759
+ const listPath = remotePath ? "/" + remotePath : "";
1760
  const hfToken = String(req.query.hfToken || "").trim();
1761
  if (!baseUrl) return res.status(400).json({ error: "url query param is required" });
1762
+
 
 
 
 
 
 
1763
  // Send response quickly - don't let HF gateway timeout
1764
  const startTime = Date.now();
1765
 
 
1839
  }
1840
  }
1841
 
1842
+ try {
1843
+ console.log(`[Remote] Strategy 1: GET ${baseUrl}/files${listPath ? "?path=" + encodeURIComponent(listPath) : ""}`);
1844
+ const fetchUrl1 = listPath ? `${baseUrl}/files?path=${encodeURIComponent(listPath)}` : `${baseUrl}/files`;
1845
+ const response = await fetchWithTimeout(fetchUrl1, {
1846
+ headers: { "Accept": "application/json" },
1847
+ }, 5000); // 5 second timeout
1848
+ console.log(`[Remote] Strategy 1 response status: ${response.status}`);
1849
+ if (response.ok) {
1850
+ const text = await response.text();
1851
+ console.log(`[Remote] Strategy 1 response length: ${text.length} chars`);
1852
+ try {
1853
+ entries = parseJsonListing(text);
1854
+ console.log(`[Remote] Strategy 1 parsed ${entries.length} entries`);
1855
+ } catch (parseErr) {
1856
+ // /files returned non-JSON, not a custom API server
1857
+ fetchError = `GET /files returned non-JSON: ${text.substring(0, 100)}`;
1858
+ console.log(`[Remote] Strategy 1 parse failed: ${fetchError}`);
 
 
 
 
 
1859
  }
1860
+ } else {
1861
+ fetchError = `GET /files returned ${response.status}`;
1862
+ console.log(`[Remote] Strategy 1 failed: ${fetchError}`);
1863
  }
1864
+ } catch (err) {
1865
+ fetchError = err.message || "Failed to connect";
1866
+ console.log(`[Remote] Strategy 1 error: ${fetchError}`);
1867
  }
1868
 
1869
+ // Strategy 2: If /files failed, try root URL for HTML directory listing
1870
  if (!entries || entries.length === 0) {
1871
  try {
1872
+ console.log(`[Remote] Strategy 2: GET ${baseUrl}/${listPath ? listPath.slice(1) + "/" : ""}`);
1873
+ const fetchUrl2 = listPath ? `${baseUrl}/${remotePath}/` : `${baseUrl}/`;
1874
  const rootResponse = await fetchWithTimeout(fetchUrl2, {}, 5000);
1875
  console.log(`[Remote] Strategy 2 response status: ${rootResponse.status}`);
1876
  if (rootResponse.ok) {
1877
  const html = await rootResponse.text();
1878
  console.log(`[Remote] Strategy 2 response length: ${html.length} chars`);
1879
+ // Try JSON first (maybe root returns JSON)
1880
  try {
1881
  entries = parseJsonListing(html);
1882
  console.log(`[Remote] Strategy 2 parsed as JSON: ${entries.length} entries`);
1883
  } catch {
1884
+ // Try HTML parsing
1885
  const htmlEntries = parseHtmlListing(html);
1886
  console.log(`[Remote] Strategy 2 parsed as HTML: ${htmlEntries.length} entries`);
1887
  if (htmlEntries.length > 0) {
1888
  entries = htmlEntries;
1889
+ fetchError = null; // HTML listing worked
1890
  }
1891
  }
1892
  }
1893
  } catch (err) {
1894
  console.log(`[Remote] Strategy 2 error: ${err.message}`);
1895
+ // Root fetch also failed
1896
  }
1897
  }
1898
 
 
2203
  console.log(`Server running on http://${HOST}:${PORT}`);
2204
  console.log(`downloads: ${DOWNLOADS_DIR}`);
2205
  console.log(`encoded: ${ENCODED_DIR}`);
2206
+ });
src/App.tsx CHANGED
@@ -1068,12 +1068,11 @@ const api = {
1068
  });
1069
  return r.json();
1070
  },
1071
- async remoteList(url: string, remotePath?: string): Promise<{ ok: boolean; entries: RemoteEntry[]; error?: string }> {
1072
  const controller = new AbortController();
1073
  const timeoutId = setTimeout(() => controller.abort(), 8000);
1074
  try {
1075
- const pathQuery = remotePath ? `&path=${encodeURIComponent(remotePath)}` : "";
1076
- const r = await fetch(`/api/remote/list?url=${encodeURIComponent(url)}${pathQuery}`, {
1077
  signal: controller.signal,
1078
  });
1079
  clearTimeout(timeoutId);
@@ -2145,7 +2144,6 @@ export default function App() {
2145
  const [remoteLoading, setRemoteLoading] = useState(false);
2146
  const [remoteError, setRemoteError] = useState<string | null>(null);
2147
  const [remoteSelected, setRemoteSelected] = useState<string[]>([]);
2148
- const [remotePath, setRemotePath] = useState("");
2149
  const remoteUploadRef = useRef<HTMLInputElement>(null);
2150
 
2151
  const remoteBucketMatch = remoteUrl.trim().match(/^(?:https?:\/\/)?huggingface\.co\/(?:api\/)?buckets\/([^\/]+)\/([^\/]+)(?:\/tree(?:\/(.*))?)?$/);
@@ -2550,13 +2548,12 @@ export default function App() {
2550
  setToast("Preset deleted");
2551
  };
2552
 
2553
- const browseRemote = async (dirPath?: string) => {
2554
  if (!remoteUrl.trim()) return;
2555
  setRemoteLoading(true);
2556
  setRemoteError(null);
2557
  try {
2558
- const targetPath = dirPath !== undefined ? dirPath : remotePath;
2559
- const res = await api.remoteList(remoteUrl.trim(), targetPath);
2560
  if (res.ok) {
2561
  setRemoteEntries(res.entries || []);
2562
  } else {
 
1068
  });
1069
  return r.json();
1070
  },
1071
+ async remoteList(url: string): Promise<{ ok: boolean; entries: RemoteEntry[]; error?: string }> {
1072
  const controller = new AbortController();
1073
  const timeoutId = setTimeout(() => controller.abort(), 8000);
1074
  try {
1075
+ const r = await fetch(`/api/remote/list?url=${encodeURIComponent(url)}`, {
 
1076
  signal: controller.signal,
1077
  });
1078
  clearTimeout(timeoutId);
 
2144
  const [remoteLoading, setRemoteLoading] = useState(false);
2145
  const [remoteError, setRemoteError] = useState<string | null>(null);
2146
  const [remoteSelected, setRemoteSelected] = useState<string[]>([]);
 
2147
  const remoteUploadRef = useRef<HTMLInputElement>(null);
2148
 
2149
  const remoteBucketMatch = remoteUrl.trim().match(/^(?:https?:\/\/)?huggingface\.co\/(?:api\/)?buckets\/([^\/]+)\/([^\/]+)(?:\/tree(?:\/(.*))?)?$/);
 
2548
  setToast("Preset deleted");
2549
  };
2550
 
2551
+ const browseRemote = async () => {
2552
  if (!remoteUrl.trim()) return;
2553
  setRemoteLoading(true);
2554
  setRemoteError(null);
2555
  try {
2556
+ const res = await api.remoteList(remoteUrl.trim());
 
2557
  if (res.ok) {
2558
  setRemoteEntries(res.entries || []);
2559
  } else {