Commit 49c77d8d49

49c77d8d49c0ead7ce62f1b601cddea2fd718c60

parent: 6a59c9d1f1

Unsigned

Alicia Sykes <alicia@omg.lol> · 2024-03-29 14:06 UTC

Linting for API

Layout: unified · split

api/src/api.ts −1
@@ -56,7 +56,6 @@ app.get('/search/:searchTerm', async (c) => {
5656 return c.json(mappedResults);
5757});
5858
59
6059/* Returns an array of all section IDs within a given category */
6160app.get('/:category', async (c) => {
6261 const { categories } = await fetchAwesomePrivacyData();
api/src/utils.ts +6 −5
@@ -2,13 +2,15 @@ import * as yaml from 'js-yaml';
22
33import type { AwesomePrivacy, Service } from './types';
44
5
65/* Given a category/section/listing title, return it's slug/ID */
76export const slugify = (title: string): string => title.toLowerCase().replace(/\s+/g, '-');
87
8/* Base path, for fetching static files from GitHub CDN */
9const ghCdnRoot = 'https://raw.githubusercontent.com/Lissy93/awesome-privacy';
10
911/* Fetches and parses Awesome Privacy source data from GitHub CDN */
1012export const fetchAwesomePrivacyData = async (): Promise<AwesomePrivacy> => {
11 const res = await fetch('https://raw.githubusercontent.com/Lissy93/awesome-privacy/main/awesome-privacy.yml');
13 const res = await fetch(`${ghCdnRoot}/main/awesome-privacy.yml`);
1214 const text = await res.text();
1315 return yaml.load(text) as AwesomePrivacy;
1416};
@@ -23,10 +25,9 @@ export const fetchAllServices = async (): Promise<Service[]> => {
2325export const findBySlug = <T extends { name: string }>(collection: T[], slug: string): T | undefined =>
2426 collection.find(item => slugify(item.name) === slug);
2527
26
28/* For the homepage root, fetch and render the Swagger docs */
2729export const renderRemoteIndex = async (ctx) => {
28 const indexHtmlUrl = 'https://raw.githubusercontent.com/Lissy93/awesome-privacy/main/api/public/index.html';
29 const response = await fetch(indexHtmlUrl);
30 const response = await fetch(`${ghCdnRoot}/main/api/public/index.html`);
3031 if (response.ok) {
3132 const htmlContent = await response.text();
3233 return ctx.html(htmlContent);