Linting for API
This commit is contained in:
parent
6a59c9d1f1
commit
49c77d8d49
|
@ -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();
|
||||
|
|
|
@ -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<AwesomePrivacy> => {
|
||||
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<Service[]> => {
|
|||
export const findBySlug = <T extends { name: string }>(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);
|
||||
|
|
Loading…
Reference in New Issue