import chalk from "chalk" ; import fetch from "node-fetch-extra" ; import updateManga from "../util/updateManga" ; import db from "../db" ; import { List } from "../types" ; let recommendedLists = [ ] ; async function updateRecommended ( ) { console . info ( chalk . yellowBright ( "[RECOMMENDATIONS]" ) + ` Updating recommendations at ${ new Date ( ) . toLocaleString ( ) }` ) ; const suggestionsUrl = "https://gist.githubusercontent.com/JipFr/17fabda0f0515965cbe1c73b75b7ed71/raw" ; const recommended = await ( await fetch ( suggestionsUrl ) ) . json ( ) ; recommendedLists = recommended . map ( ( recommendedItem ) => { recommendedItem . byCreator = true ; return recommendedItem ; } ) ; console . info ( chalk . green ( "[RECOMMENDATIONS]" ) + " Updated recommendations" ) ; } updateRecommended ( ) ; setInterval ( updateRecommended , 1e3 * 60 * 60 * 12 ) ; export async function getLists ( justHome = false ) { let lists = db . get ( "lists" ) ; lists = lists . filter ( ( l ) => ! l . byCreator ) ; lists = lists . filter ( ( l ) => ( justHome && l . showOnHome ) || ! justHome ) ; let updatedLists = Object . assign ( [ ] , [ ... recommendedLists , ... lists ] ) ; updatedLists = updatedLists . filter ( ( l ) => ( justHome ? l . showOnHome : true ) ) ; updatedLists = await Promise . all ( updatedLists . map ( async ( list ) => { list . entries = await Promise . all ( list . entries . map ( async ( entry ) => { entry . data = await updateManga ( entry . provider ?? "mangasee" , entry . slug ) ; return entry ; } ) ) ; return list ; } ) ) ; return updatedLists ; }