'use strict'; export 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!! const list = await fetch(`${BASE_URL}${RES_ENDPOINT}`) .then(res => res.json()) .catch(); // Arbitrary slice... return list['ldp:contains'].slice(100, max + 100); } /** * Create links list * @param {string[]} links The fetched resource links * @param {string} id The ID of the UL element * @param {string} replace The string that should replace loalhost... * */ export function createLinks(links, id, replace) { /* links = links.map(e => e.replace( 'http://localhost:8000/resources/', replace )); */ for (const link of links) { const item = document.createElement('li'); item.innerHTML = ` ${link.substring(link.lastIndexOf('/')+1)} `; document.querySelector(`#${id}`).appendChild(item); } } /** * Fetch JSON report... * @param {string} uuid The resource's UUID in Arches * * @return {object} */ export async function fetchReport(uuid) { // TODO Errors!! const jsonRep = await fetch(`${BASE_URL}${RES_ENDPOINT}${uuid}?format=json&indent=2`) .then(res => res.json()) .catch(); // Arbitrary slice... return jsonRep; } /** * Query report links to determine * resource instance type... */