all repos — tabemono @ main

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 getProfile = async (webId: string) => {
11	const dataset = await getSolidDataset(webId, { fetch: fetchPod });
12	const subjects = getThingAll(dataset);
13
14	const findValue = (predicate: string) =>
15		subjects
16			.map((subject) => getStringNoLocale(subject, predicate) || getUrl(subject, predicate))
17			?.filter((i) => !!i)[0];
18
19	return {
20		name: findValue(FOAF.name),
21		organization: findValue(VCARD.organization_name),
22		image: findValue(VCARD.hasPhoto)
23	};
24};