@@ -41,29 +41,51 @@ export function getPod (): NamedNode {
4141 return sym ( document . location . origin ) . site ( )
4242}
4343/**
44- * @ignore exporting this only for the unit test
4544 */
4645export async function getPodOwner ( pod : NamedNode , store : IndexedFormula ) : Promise < NamedNode | null > {
47- // @@ TODO: This is given the structure that NSS provides - might need to change for other Pod servers
48- const podOwner = sym ( `${ pod . uri } profile/card#me` )
46+ // This is a massive guess. In future
47+ // const podOwner = sym(`${pod.uri}profile/card#me`)
4948
5049 try {
51- if ( store . fetcher ) {
52- await store . fetcher . load ( podOwner . doc ( ) )
53- } else {
54- throw new Error ( 'There was a problem loading the Fetcher' )
55- }
56- // @@ TODO: check back links to storage
50+ store . fetcher . load ( pod )
5751 } catch ( err ) {
58- throw new Error ( 'Did NOT find pod owners profile at ' + podOwner )
52+ console . error ( 'Error loading pod ' + pod + ': ' + err )
53+ return null
5954 }
55+ if ( ! store . holds ( pod , ns . rdf ( 'type' ) , ns . space ( 'Storage' ) , pod ) {
56+ console . warn ( 'Pod ' + pod ' does not declare itself as a space:Storage' )
57+ return null
58+ }
59+ const podOwner = store . any ( null , ns . space ( 'storage' ) , pod , pod )
6060 if ( podOwner ) {
61- const storageIsListedInPodOwnersProfile = store . holds ( podOwner , ns . space ( 'storage' ) , pod , podOwner . doc ( ) )
62- if ( ! storageIsListedInPodOwnersProfile ) {
63- throw new Error ( `** Pod owner ${ podOwner } does NOT list pod ${ pod } as storage` )
61+ try {
62+ store . fetcher . load ( podOwner . doc ( ) )
63+ } catch ( err ) {
64+ console . warn ( 'Unable to load profile of pod owner ' + podOwner )
65+ return null
66+ }
67+ if ( ! store . holds ( podOwner , ns . space ( 'storage' ) , pod , podOwner . doc ( ) ) {
68+ console . warn ( `Pod owner ${ podOwner } does NOT list pod ${ pod } as their storage` )
69+ }
70+ return podOwner // Success!
71+ } else // pod ownder not declared in pod
72+ // @@ TODO: This is given the structure that NSS provides
73+
74+ {
75+ // This is a massive guess. For old pods which don't have owner link
76+ const guess = sym ( `${ pod . uri } profile/card#me` )
77+ try {
78+ store . fetcher . load ( guess )
79+ } else ( err ) {
80+ console . error ( `Ooops. Guessed wrong pod owner webid {$guess} : can't load it.` )
81+ return null
82+ }
83+ if ( store . holds ( guess , ns . space ( 'storage' ) , pod , guess . doc ( ) ) ) {
84+ console . warn ( `Using guessed pod owner webid but it links back.` )
85+ return guess
6486 }
87+ return null
6588 }
66- return podOwner
6789}
6890/**
6991 * @ignore exporting this only for the unit test
0 commit comments