import { IMALSearchAnime , IMALUserListAnime , ISettings , MALStatus } from "../common" ; import { loadSettings } from "../utils" ; import MyAnimeListAPI from "./api" ; let api = new MyAnimeListAPI ( ) ; loadSettings ( [ "malUsername" , "malPassword" , ] ) . then ( ( settings ) => { if ( settings . malUsername !== undefined && settings . malPassword !== undefined ) { api . setCredentials ( settings . malUsername , settings . malPassword ) ; } } ) ; /**
 * Returns current date in MMDDYYYY format.
 */ export function malDate ( date = new Date ( ) ) { let year = date . getFullYear ( ) ; let month = "" ; let day = "" ; if ( date . getMonth ( ) + 1 < 10 ) { month = "0" + String ( date . getMonth ( ) + 1 ) ; } else { month = String ( date . getMonth ( ) + 1 ) ; } if ( date . getDate ( ) < 10 ) { day = "0" + String ( date . getDate ( ) ) ; } else { day = String ( date . getDate ( ) ) ; } return month + day + year ; } export async function getUserList ( ) { try { return ( await api . userList ( ) ) . myanimelist . anime ; } catch ( err ) { throw new Error ( err . message ) ; } } export async function search ( animeName ) { try { return ( await api . searchAnime ( animeName ) ) . anime . entry ; } catch ( err ) { throw new Error ( err . message ) ; } } export async function quickAdd ( animeId ) { try { await api . addAnime ( animeId , { entry : { date_start : malDate ( ) , episode : 1 , status : MALStatus . WATCHING , } , } ) ; } catch ( err ) { throw new Error ( err . message ) ; } } export async function quickUpdate ( animeId , episode ) { try { await api . updateAnime ( animeId , { entry : { episode , } , } ) ; } catch ( err ) { throw new Error ( err . message ) ; } } export async function verify ( username , password ) { try { await MyAnimeListAPI . verify ( username , password ) ; api . setCredentials ( username , password ) ; } catch ( err ) { throw new Error ( err . message ) ; } } export function removeCredentials ( ) { api . setCredentials ( "" , "" ) ; }