import axios from 'axios'
import { defAxios as request } from '@/utils/http'

const baseUrl = window.settings.apis
const BASE_URL = 'https://celestrak.org'

function getTleDataFromExternal(path = '') {
  let uri = `${BASE_URL}/NORAD/elements/gp.php?GROUP=${path}&FORMAT=tle`
  return axios.get(uri).then(res => {
    if (res.status === 200) {
      return Promise.resolve(res.data)
    } else {
      console.log('获取TLE失败')
      return Promise.reject(res.statusText)
    }
  })
}

export function getSatellite() {
  return request({
    url: `${baseUrl}/satellite/list`,
    method: 'get',
  })
}

export { getTleDataFromExternal }
