import express from "express" ; const router = express . Router ( ) ; import getReading from "../util/getReading" ; import db from "../db" ; import { getLists } from "../util/lists" ; import { List } from "../types" ; router . get ( "/" , async ( req , res ) => { const lists = await getLists ( ) ; const reading = await getReading ( ) ; res . render ( "lists" , { reading , lists , isLists : true } ) ; } ) ; router . get ( "/json" , async ( req , res ) => { res . header ( "Access-Control-Allow-Origin" , "*" ) ; const data = await getLists ( ) ; res . json ( { data : { lists : data } } ) ; } ) ; router . post ( "/set-home" , async ( req , res ) => { const listId = req . body . listId ; let value = req . body . value ; value = ! ! value ; const lists = await getLists ( ) ; const list = lists . find ( ( l ) => l . slug === listId ) ; if ( list ) list . showOnHome = value ; db . set ( "lists" , lists . filter ( ( l ) => ! l . byCreator ) . map ( removeData ) ) ; res . json ( { status : 200 } ) ; } ) ; export function removeData ( list ) { let l = Object . assign ( { } , list ) ; if ( ! list . byCreator ) { l . entries = l . entries . map ( ( entry ) => { return { provider : entry . provider , slug : entry . slug } ; } ) ; } return list ; } export default router ;