import axios from 'axios' ; import { analyseGithubRepo } from './github' ; export const serverEndpoint = 'https://discovery.autoai.dev/' ; function _get ( endpoint ) { return new Promise ( ( resolve , reject ) => { axios . get ( endpoint ) . then ( ( res ) => { resolve ( res ) ; } ) . catch ( ( err ) => { reject ( err ) ; } ) ; } ) ; } function _post ( endpoint , payload ) { return new Promise ( ( resolve , reject ) => { axios . post ( endpoint , payload ) . then ( ( res ) => { resolve ( res ) ; } ) . catch ( ( err ) => { reject ( err ) ; } ) ; } ) ; } export function findModelsByKeyword ( keyword ) { if ( keyword === "" ) { return _get ( serverEndpoint + "model/" ) ; } return _get ( serverEndpoint + "model/keyword/" + keyword ) ; } export async function analyseRepos ( repos , meta_only ) { for ( let i = 0 ; i < repos . length ; i ++ ) { if ( repos [ i ] . githubURL !== "" && repos [ i ] . githubURL ) { let vendor = repos [ i ] . githubURL . split ( "/" ) [ 3 ] ; let name = repos [ i ] . githubURL . split ( "/" ) [ 4 ] ; if ( ! meta_only ) { let result = await analyseGithubRepo ( vendor , name , repos [ i ] . _id ) ; repos [ i ] . analysis = result ; } } } return repos ; } export function getModelInfo ( vendor , name ) { return _get ( serverEndpoint + "model/info/" + vendor + "/" + name ) ; } export function postNewRepo ( repo ) { return _post ( serverEndpoint + "model/" , repo ) ; }