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) => {
56 return c.json(mappedResults); 56 return c.json(mappedResults);
57}); 57});
58 58
59
60/* Returns an array of all section IDs within a given category */ 59/* Returns an array of all section IDs within a given category */
61app.get('/:category', async (c) => { 60app.get('/:category', async (c) => {
62 const { categories } = await fetchAwesomePrivacyData(); 61 const { categories } = await fetchAwesomePrivacyData();
api/src/utils.ts +6 −5
@@ -2,13 +2,15 @@ import * as yaml from 'js-yaml';
2 2
3import type { AwesomePrivacy, Service } from './types'; 3import type { AwesomePrivacy, Service } from './types';
4 4
5
6/* Given a category/section/listing title, return it's slug/ID */ 5/* Given a category/section/listing title, return it's slug/ID */
7export const slugify = (title: string): string => title.toLowerCase().replace(/\s+/g, '-'); 6export const slugify = (title: string): string => title.toLowerCase().replace(/\s+/g, '-');
8 7
8/* Base path, for fetching static files from GitHub CDN */
9const ghCdnRoot = 'https://raw.githubusercontent.com/Lissy93/awesome-privacy';
10
9/* Fetches and parses Awesome Privacy source data from GitHub CDN */ 11/* Fetches and parses Awesome Privacy source data from GitHub CDN */
10export const fetchAwesomePrivacyData = async (): Promise<AwesomePrivacy> => { 12export 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`);
12 const text = await res.text(); 14 const text = await res.text();
13 return yaml.load(text) as AwesomePrivacy; 15 return yaml.load(text) as AwesomePrivacy;
14}; 16};
@@ -23,10 +25,9 @@ export const fetchAllServices = async (): Promise<Service[]> => {
23export const findBySlug = <T extends { name: string }>(collection: T[], slug: string): T | undefined => 25export const findBySlug = <T extends { name: string }>(collection: T[], slug: string): T | undefined =>
24 collection.find(item => slugify(item.name) === slug); 26 collection.find(item => slugify(item.name) === slug);
25 27
26 28/* For the homepage root, fetch and render the Swagger docs */
27export const renderRemoteIndex = async (ctx) => { 29export const renderRemoteIndex = async (ctx) => {
28 const indexHtmlUrl = 'https://raw.githubusercontent.com/Lissy93/awesome-privacy/main/api/public/index.html'; 30 const response = await fetch(`${ghCdnRoot}/main/api/public/index.html`);
29 const response = await fetch(indexHtmlUrl);
30 if (response.ok) { 31 if (response.ok) {
31 const htmlContent = await response.text(); 32 const htmlContent = await response.text();
32 return ctx.html(htmlContent); 33 return ctx.html(htmlContent);