Initial commit

This commit is contained in:
2023-02-21 23:33:58 +01:00
commit defdfefb03
6 changed files with 97 additions and 0 deletions

46
js/ds.js Normal file
View File

@@ -0,0 +1,46 @@
'use strict';
const BASE_URL = 'http://150.145.56.132';
const RES_ENDPOINT = '/resources/';
/**
* @todo Query report links to determine resource type?
* @param {int} max Max number of resources to list
* (randomly selected)
*
* @returns {Array} An array with selected resource links
*/
export async function fetchResourceList(max = 20)
{
// TODO Errors!!
let req = new Request(`${BASE_URL}${RES_ENDPOINT}`);
const res = await fetch(req).catch();
const list = await res.json();
return list['ldp:contains'].slice(100, max + 100)
.map(e => e.replace(
'http://localhost:8000/resources',
`${BASE_URL}/report`));
}
/**
* Create links list
* @param {string[]} links The fetched resource links
* @param {string} id The ID of the UL element
*
*/
export function createLinks(links, id)
{
for (const link of links) {
const item = document.createElement('li');
item.innerHTML = `<a href="${link}">${link}</a>`;
document.querySelector(`#${id}`).appendChild(item);
}
}
/**
* Process JSON report...
*/
/**
* Query report links to determine
* resource instance type...
*/

8
js/index.js Normal file
View File

@@ -0,0 +1,8 @@
import {
fetchResourceList,
createLinks
} from "./ds.js";
document.addEventListener('readystatechange', async () => {
createLinks(await fetchResourceList(), 'links');
})