Skip to content

Commit 74ca717

Browse files
artongenextcloud-command
authored andcommitted
When double-clicking on a file, the behavior is:
First click: open the viewer Second click: close the viewer But the second click does not correctly close the Viewer, as the method used to cancel the requests does not work. This PR use modern API to cancel the requests. The requests are now correctly aborted, and the `openFile` method exit because the request call throws an exception. Fix #893 https://axios-http.com/docs/cancellation https://developer.mozilla.org/en-US/docs/Web/API/AbortController Signed-off-by: Louis Chemineau <louis@chmn.me> Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
1 parent b41b952 commit 74ca717

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

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
@@ -185,6 +185,7 @@ object-assign
185185
*
186186
* @author Marco Ambrosini <marcoambrosini@pm.me>
187187
* @author John Molakvoæ <skjnldsv@protonmail.com>
188+
* @author Louis Chemineau <louis@chmn.me>
188189
*
189190
* @license GNU AGPL version 3 or any later version
190191
*

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 GNU AGPL version 3 or any later version
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
* @returns {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)