|
1 | 1 | import $ from 'jquery';
|
2 | 2 | import {hideElem, showElem} from '../utils/dom.js';
|
| 3 | +import {POST} from '../modules/fetch.js'; |
3 | 4 |
|
4 |
| -const {csrfToken} = window.config; |
5 |
| - |
6 |
| -function getArchive($target, url, first) { |
7 |
| - $.ajax({ |
8 |
| - url, |
9 |
| - type: 'POST', |
10 |
| - data: { |
11 |
| - _csrf: csrfToken, |
12 |
| - }, |
13 |
| - complete(xhr) { |
14 |
| - if (xhr.status === 200) { |
15 |
| - if (!xhr.responseJSON) { |
16 |
| - // XXX Shouldn't happen? |
17 |
| - $target.closest('.dropdown').children('i').removeClass('loading'); |
18 |
| - return; |
19 |
| - } |
| 5 | +async function getArchive($target, url, first) { |
| 6 | + try { |
| 7 | + const response = await POST(url); |
| 8 | + if (response.status === 200) { |
| 9 | + const data = await response.json(); |
| 10 | + if (!data) { |
| 11 | + // XXX Shouldn't happen? |
| 12 | + $target.closest('.dropdown').children('i').removeClass('loading'); |
| 13 | + return; |
| 14 | + } |
20 | 15 |
|
21 |
| - if (!xhr.responseJSON.complete) { |
22 |
| - $target.closest('.dropdown').children('i').addClass('loading'); |
23 |
| - // Wait for only three quarters of a second initially, in case it's |
24 |
| - // quickly archived. |
25 |
| - setTimeout(() => { |
26 |
| - getArchive($target, url, false); |
27 |
| - }, first ? 750 : 2000); |
28 |
| - } else { |
29 |
| - // We don't need to continue checking. |
30 |
| - $target.closest('.dropdown').children('i').removeClass('loading'); |
31 |
| - window.location.href = url; |
32 |
| - } |
| 16 | + if (!data.complete) { |
| 17 | + $target.closest('.dropdown').children('i').addClass('loading'); |
| 18 | + // Wait for only three quarters of a second initially, in case it's |
| 19 | + // quickly archived. |
| 20 | + setTimeout(() => { |
| 21 | + getArchive($target, url, false); |
| 22 | + }, first ? 750 : 2000); |
| 23 | + } else { |
| 24 | + // We don't need to continue checking. |
| 25 | + $target.closest('.dropdown').children('i').removeClass('loading'); |
| 26 | + window.location.href = url; |
33 | 27 | }
|
34 |
| - }, |
35 |
| - }); |
| 28 | + } |
| 29 | + } catch { |
| 30 | + $target.closest('.dropdown').children('i').removeClass('loading'); |
| 31 | + } |
36 | 32 | }
|
37 | 33 |
|
38 | 34 | export function initRepoArchiveLinks() {
|
|
0 commit comments