From 49c77d8d49c0ead7ce62f1b601cddea2fd718c60 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Fri, 29 Mar 2024 14:06:00 +0000 Subject: [PATCH] Linting for API --- api/src/api.ts | 1 - api/src/utils.ts | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/src/api.ts b/api/src/api.ts index 5cc0191..18b362b 100644 --- a/api/src/api.ts +++ b/api/src/api.ts @@ -56,7 +56,6 @@ app.get('/search/:searchTerm', async (c) => { return c.json(mappedResults); }); - /* Returns an array of all section IDs within a given category */ app.get('/:category', async (c) => { const { categories } = await fetchAwesomePrivacyData(); diff --git a/api/src/utils.ts b/api/src/utils.ts index 16e3265..264af4d 100644 --- a/api/src/utils.ts +++ b/api/src/utils.ts @@ -2,13 +2,15 @@ import * as yaml from 'js-yaml'; import type { AwesomePrivacy, Service } from './types'; - /* Given a category/section/listing title, return it's slug/ID */ export const slugify = (title: string): string => title.toLowerCase().replace(/\s+/g, '-'); +/* Base path, for fetching static files from GitHub CDN */ +const ghCdnRoot = 'https://raw.githubusercontent.com/Lissy93/awesome-privacy'; + /* Fetches and parses Awesome Privacy source data from GitHub CDN */ export const fetchAwesomePrivacyData = async (): Promise => { - const res = await fetch('https://raw.githubusercontent.com/Lissy93/awesome-privacy/main/awesome-privacy.yml'); + const res = await fetch(`${ghCdnRoot}/main/awesome-privacy.yml`); const text = await res.text(); return yaml.load(text) as AwesomePrivacy; }; @@ -23,10 +25,9 @@ export const fetchAllServices = async (): Promise => { export const findBySlug = (collection: T[], slug: string): T | undefined => collection.find(item => slugify(item.name) === slug); - +/* For the homepage root, fetch and render the Swagger docs */ export const renderRemoteIndex = async (ctx) => { - const indexHtmlUrl = 'https://raw.githubusercontent.com/Lissy93/awesome-privacy/main/api/public/index.html'; - const response = await fetch(indexHtmlUrl); + const response = await fetch(`${ghCdnRoot}/main/api/public/index.html`); if (response.ok) { const htmlContent = await response.text(); return ctx.html(htmlContent);