Skip to content

Commit b4f3988

Browse files
authored
Merge pull request #1247 from nextcloud/fix/request_cancelation
Use modern API to cancel requests
2 parents 267fd25 + beb81f0 commit b4f3988

4 files changed

Lines changed: 8 additions & 12 deletions

File tree

js/viewer-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/viewer-main.js.LICENSE.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ object-assign
8282
*
8383
* @author Marco Ambrosini <marcoambrosini@pm.me>
8484
* @author John Molakvoæ <skjnldsv@protonmail.com>
85+
* @author Louis Chemineau <louis@chmn.me>
8586
*
8687
* @license AGPL-3.0-or-later
8788
*

js/viewer-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/CancelableRequest.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*
44
* @author Marco Ambrosini <marcoambrosini@pm.me>
55
* @author John Molakvoæ <skjnldsv@protonmail.com>
6+
* @author Louis Chemineau <louis@chmn.me>
67
*
78
* @license AGPL-3.0-or-later
89
*
@@ -21,20 +22,14 @@
2122
*
2223
*/
2324

24-
import axios from '@nextcloud/axios'
25-
2625
/**
2726
* Creates a cancelable axios 'request object'.
2827
*
2928
* @param {Function} request the axios promise request
3029
* @return {object}
3130
*/
3231
const CancelableRequest = function(request) {
33-
/**
34-
* Generate an axios cancel token
35-
*/
36-
const CancelToken = axios.CancelToken
37-
const source = CancelToken.source()
32+
const controller = new AbortController()
3833

3934
/**
4035
* Execute the request
@@ -45,12 +40,12 @@ const CancelableRequest = function(request) {
4540
const fetch = async function(url, options) {
4641
return request(
4742
url,
48-
Object.assign({ cancelToken: source.token }, { options })
43+
{ ...options, signal: controller.signal }
4944
)
5045
}
5146
return {
5247
request: fetch,
53-
cancel: source.cancel,
48+
cancel: () => controller.abort(),
5449
}
5550
}
5651

0 commit comments

Comments
 (0)