diff --git a/app/lib/class/ContainerDataset.ts b/app/lib/class/ContainerDataset.ts index 854ca4f..63bfb21 100644 --- a/app/lib/class/ContainerDataset.ts +++ b/app/lib/class/ContainerDataset.ts @@ -1,13 +1,21 @@ -import { DatasetWrapper } from "@rdfjs/wrapper" -import { Container } from "@/app/lib/class/Container" -import { LDP } from "@/app/lib/class/Vocabulary" +import { DatasetWrapper } from "@rdfjs/wrapper"; +import { Container } from "@/app/lib/class/Container"; +import { LDP } from "@/app/lib/class/Vocabulary"; export class ContainerDataset extends DatasetWrapper { - // TODO: Consider that this might be undefined if there are no contained resources. We might need different matching. - get container(): Container | undefined { - // Return the first container in the dataset - for (const s of this.subjectsOf(LDP.contains, Container)) { - return s; - } + get container(): Container | undefined { + // Non-empty containers advertise children via ldp:contains. + for (const s of this.subjectsOf(LDP.contains, Container)) { + return s; } + + // Empty containers have no ldp:contains; resolve via rdf:type instead. + for (const s of this.instancesOf(LDP.Container, Container)) { + return s; + } + + for (const s of this.instancesOf(LDP.BasicContainer, Container)) { + return s; + } + } } diff --git a/app/lib/class/Vocabulary.ts b/app/lib/class/Vocabulary.ts index 9e2df10..d4182c5 100644 --- a/app/lib/class/Vocabulary.ts +++ b/app/lib/class/Vocabulary.ts @@ -29,6 +29,8 @@ export const FOAF = { export const LDP = { contains: "http://www.w3.org/ns/ldp#contains", + Container: "http://www.w3.org/ns/ldp#Container", + BasicContainer: "http://www.w3.org/ns/ldp#BasicContainer", } as const export const PIM = { diff --git a/app/lib/hooks/useBrowseStorage.ts b/app/lib/hooks/useBrowseStorage.ts index f507317..7ae40ac 100644 --- a/app/lib/hooks/useBrowseStorage.ts +++ b/app/lib/hooks/useBrowseStorage.ts @@ -58,7 +58,7 @@ export function useBrowseStorage(containerUrl: string | null, refreshKey?: numbe .container if (container === undefined) { - throw new Error() // TODO: Handle properly + throw new Error("Could not identify the storage container in the listing response") } const fileItems: FileItemData[] = [];