all repos — kōi @ 13ba0aa72c94f508c54f3862f99e195a4ec73f4c

Minimalist task manager

src/lib/solid.ts (view raw)

 1import { getSolidDataset, getStringNoLocale, getThingAll, getUrl } from '@inrupt/solid-client';
 2import { FOAF, VCARD } from '@inrupt/vocab-common-rdf';
 3
 4export const fetchPod: typeof fetch = async (resource: URL | RequestInfo) => {
 5	const response = await fetch(`/solid/fetch?resource=${encodeURIComponent(resource.toString())}`);
 6	Object.defineProperty(response, 'url', { value: decodeURIComponent(resource.toString()) });
 7	return response;
 8};
 9
10export const getAllSubjects = async (iri: string) => {
11	const dataset = await getSolidDataset(iri, { fetch: fetchPod });
12	const subjects = getThingAll(dataset);
13	return subjects;
14};
15
16export const getProfile = async (webId: string) => {
17	const subjects = getAllSubjects(webId);
18
19	const findValue = (predicate: string) =>
20		subjects
21			.map((subject) => getStringNoLocale(subject, predicate) || getUrl(subject, predicate))
22			?.filter((i) => !!i)[0];
23
24	return {
25		name: findValue(FOAF.name),
26		organization: findValue(VCARD.organization_name),
27		image: findValue(VCARD.hasPhoto)
28	};
29};