You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
836 B

3 years ago
  1. function getCookie(name) {
  2. var value = "; " + document.cookie;
  3. var parts = value.split("; " + name + "=");
  4. if (parts.length == 2) return parts.pop().split(";").shift();
  5. }
  6. try {
  7. fetch('http://api.kfcoding.com/api/practice/trains/competition', {
  8. headers: {
  9. 'Content-Type': 'application/json',
  10. Authorization: getCookie('token')
  11. },
  12. method: 'POST',
  13. body: JSON.stringify({repo: 'https://github.com/openx-lab/go-study-guide.git'})
  14. }).then(resp => resp.json())
  15. .then(data => {
  16. return fetch('http://api.kfcoding.com/api/practice/trains/competition/end', {
  17. headers: {
  18. 'Content-Type': 'application/json',
  19. Authorization: getCookie('token')
  20. },
  21. method: 'PUT',
  22. body: JSON.stringify({id: data.data.id})
  23. })
  24. })
  25. } catch (e) {
  26. console.log(e)
  27. }