Skip to content

Commit 1cf1a16

Browse files
fix: binary file fetching error
1 parent 3377b67 commit 1cf1a16

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

app/lib/helpers/urlUtils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ export function resolveUrl(url: string, baseUrl: string): string {
4646
}
4747
}
4848

49+
/**
50+
* Checks if a URL represents a known binary/system file that shouldn't be fetched as RDF
51+
*/
52+
export function isBinaryFile(url: string): boolean {
53+
const urlLower = url.toLowerCase();
54+
// Common binary/system files that can't be converted to RDF
55+
const binaryPatterns = [
56+
'.ds_store', // macOS system file
57+
'thumbs.db', // Windows thumbnail cache
58+
'desktop.ini', // Windows folder settings
59+
'.git/', // Git directories
60+
'.svn/', // SVN directories
61+
'.hg/', // Mercurial directories
62+
];
63+
64+
// Check if URL ends with or contains these patterns
65+
return binaryPatterns.some(pattern =>
66+
urlLower.includes(pattern) || urlLower.endsWith(pattern)
67+
);
68+
}
69+
4970
/**
5071
* Checks if a URL has a file extension that indicates it's likely a file
5172
* @param url - The URL to check

app/lib/hooks/useBrowseStorage.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from "@inrupt/solid-client";
1515
import { DCTERMS, POSIX, RDFS } from "@inrupt/vocab-common-rdf";
1616
import { FileItemData } from "../../components/FileItem";
17-
import { extractNameFromUrl, resolveUrl, isLikelyFile } from "../helpers/urlUtils";
17+
import { extractNameFromUrl, resolveUrl, isLikelyFile, isBinaryFile } from "../helpers/urlUtils";
1818

1919
interface UseBrowseStorageResult {
2020
files: FileItemData[];
@@ -115,7 +115,8 @@ export function useBrowseStorage(containerUrl: string | null, refreshKey?: numbe
115115

116116
let finalIsContainer = isContainerUrl;
117117

118-
if (!isContainerUrl && !isLikelyFile(absoluteUrl)) {
118+
// Skip RDF fetch for known binary files or files with extensions
119+
if (!isContainerUrl && !isLikelyFile(absoluteUrl) && !isBinaryFile(absoluteUrl)) {
119120
try {
120121
const itemDataset = await getSolidDataset(absoluteUrl, {
121122
fetch: fetchFn,
@@ -137,6 +138,9 @@ export function useBrowseStorage(containerUrl: string | null, refreshKey?: numbe
137138
finalIsContainer = false;
138139
}
139140
}
141+
} else if (isBinaryFile(absoluteUrl)) {
142+
// Known binary file - treat as file without attempting RDF fetch
143+
finalIsContainer = false;
140144
}
141145

142146
fileItems.push({

0 commit comments

Comments
 (0)