Skip to content

Commit df844ac

Browse files
committed
update frontend
1 parent 4d39237 commit df844ac

1 file changed

Lines changed: 111 additions & 6 deletions

File tree

frontend/bootloader.html

Lines changed: 111 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
</style>
1414
<!-- /Page CSS -->
1515
<!-- Head HTML -->
16-
16+
<!-- metro (baseComponent/metro) -->
17+
<script src="https://cdn.jsdelivr.net/npm/@muze-nl/metro@0.6.19/dist/browser.js"></script>
18+
<script src="https://cdn.jsdelivr.net/npm/@muze-nl/oldm@0.3.6/dist/oldm.js"></script>
19+
<script src="https://cdn.jsdelivr.net/npm/@muze-nl/metro-oauth2@0.7.4/dist/browser.js"></script>
20+
<script src="https://cdn.jsdelivr.net/npm/@muze-nl/metro-oidc@0.5.3/dist/browser.js"></script>
1721
<!-- /Head HTML -->
1822
<script>
1923
var simplyDataApi = {};
@@ -27,13 +31,99 @@
2731
/* End of Raw API */
2832
/* Data API */
2933
simplyDataApi = {
34+
// component/AppLauncher
35+
"appLocation" : async function(webID){
36+
let preferenceOLDM = await simplyDataApi.getPreferences(webID)
37+
if (
38+
preferenceOLDM.subjects[webID] &&
39+
preferenceOLDM.subjects[webID].solid$launcher
40+
) {
41+
return preferenceOLDM.subjects[webID].solid$launcher.id
42+
} else {
43+
return "https://solid-launcher.dev.muze.nl/"
44+
}
45+
},
46+
// component/AppLauncher
47+
"getPreferences" : async function(webID){
48+
49+
let issuer = ""
50+
let profileTurtle
51+
52+
const context = oldm.context({
53+
prefixes: {
54+
'ldp': 'http://www.w3.org/ns/ldp#',
55+
'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
56+
'dct': 'http://purl.org/dc/terms/',
57+
'stat': 'http://www.w3.org/ns/posix/stat#',
58+
'turtle': 'http://www.w3.org/ns/iana/media-types/text/turtle#',
59+
'schem': 'https://schema.org/',
60+
'solid': 'http://www.w3.org/ns/solid/terms#',
61+
'acl': 'http://www.w3.org/ns/auth/acl#',
62+
'pims': 'http://www.w3.org/ns/pim/space#',
63+
'vcard': 'http://www.w3.org/2006/vcard/ns#',
64+
'foaf': 'http://xmlns.com/foaf/0.1/'
65+
},
66+
parser: oldm.n3Parser,
67+
writer: oldm.n3Writer
68+
})
69+
70+
//fetch profile to retrieve issuer
71+
const profileURL = webID;
72+
try {
73+
const responseProfile = await fetch(profileURL);
74+
if (!responseProfile.ok) {
75+
throw new Error(`Response status: ${responseProfile.status}`);
76+
}
77+
profileTurtle = await responseProfile.text();
78+
} catch (error) {
79+
console.error(error.message);
80+
}
81+
82+
let podContent = context.parse(profileTurtle, webID, 'text/turtle')
83+
84+
issuer = podContent.primary?.solid$oidcIssuer?.id
85+
let preferenceFileURL = podContent.primary?.pims$preferencesFile?.id
86+
87+
const oidcOptions = {
88+
// authorize_callback: metro.oauth2.authorizePopup,
89+
force_authorization: true,
90+
client_info: {
91+
client_name: 'Solid Bootloader',
92+
redirect_uris: [
93+
window.location.origin + window.location.pathname
94+
]
95+
},
96+
issuer: issuer
97+
}
98+
if (window.location.protocol !== "https") {
99+
// needed to allow app.simplyapp:// as redirect uri
100+
oidcOptions['client_info']['application_type'] = 'native';
101+
}
30102

103+
let client = metro.client().with(metro.oidc.oidcmw(oidcOptions))
104+
105+
let preferenceResponse = await client.get(preferenceFileURL)
106+
107+
if (!preferenceResponse.ok) {
108+
throw new Error(preferenceResponse.status+':'+preferenceResponse.statusText)
109+
}
110+
111+
const preferenceTurtle = await preferenceResponse.text()
112+
let preferenceOLDM = context.parse(preferenceTurtle, preferenceFileURL, 'text/turtle')
113+
114+
return preferenceOLDM
115+
116+
}
31117
};
32118
/* End of Data API */
33119
simplyApp = simply.app({
34120
/* Actions */
35121
actions: {
36-
122+
// component/AppLauncher
123+
"getLauncherLocation" : async function (webID){
124+
let appLauncherPath = await simplyDataApi.appLocation(webID)
125+
return appLauncherPath
126+
}
37127
},
38128
/* /Actions */
39129
/* Commands */
@@ -49,8 +139,23 @@
49139
/* Routes */
50140
routes: {
51141
// page/home
52-
"/" : function(params) {
53-
document.location.href="https://solid-launcher.dev.muze.nl/";
142+
"#webID/:webID" : async function(params) {
143+
let webID = params.webID
144+
webID = decodeURIComponent(webID)
145+
localStorage['bootloader:webID'] = webID
146+
let appLauncherPath = await simplyApp.actions.getLauncherLocation(webID)
147+
document.location.href = appLauncherPath
148+
},
149+
// page/home
150+
"/" : async function() {
151+
if (
152+
document.location.search.match("code") ||
153+
document.location.search.match("state")
154+
) {
155+
let webID = localStorage['bootloader:webID']
156+
let appLauncherPath = await simplyApp.actions.getLauncherLocation(webID)
157+
document.location.href = appLauncherPath
158+
}
54159
}
55160
}
56161
/* /Routes */
@@ -79,7 +184,7 @@
79184

80185
<!-- /Page HTML templates -->
81186
</div>
82-
<script src="https://unpkg.com/simplyview@2.1.1/dist/simply.everything.js"></script>
187+
<script src="https://unpkg.com/simplyview@3.5.5/dist/simply.everything.js"></script>
83188
<script src="https://canary.simplyedit.io/1/simply-edit.js" data-simply-storage="none" data-api-key="simply-edit-0011"></script>
84189
<script>
85190
/* Transformers */
@@ -106,4 +211,4 @@
106211

107212
<!-- /Foot HTML -->
108213
</body>
109-
</html>
214+
</html>

0 commit comments

Comments
 (0)