force close xhr after finish

This commit is contained in:
lxsang 2021-05-06 20:17:32 +02:00
parent a7cb8e06e1
commit 3f05659940
3 changed files with 20 additions and 18 deletions

Binary file not shown.

View File

@ -1135,7 +1135,7 @@ namespace OS {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
const q = announcer.getMID(); const q = announcer.getMID();
API.loading(q, p); API.loading(q, p);
return $.ajax({ const xhr = $.ajax({
type: "POST", type: "POST",
url: p, url: p,
contentType: "application/json", contentType: "application/json",
@ -1154,6 +1154,7 @@ namespace OS {
}) })
.done(function (data) { .done(function (data) {
API.loaded(q, p, "OK"); API.loaded(q, p, "OK");
xhr.abort();
return resolve(data); return resolve(data);
}) })
.fail(function (j, s, e) { .fail(function (j, s, e) {
@ -1222,7 +1223,7 @@ namespace OS {
const formd = new FormData(); const formd = new FormData();
formd.append("path", d); formd.append("path", d);
formd.append("upload", file); formd.append("upload", file);
return $.ajax({ const xhr = $.ajax({
url: p, url: p,
data: formd, data: formd,
type: "POST", type: "POST",
@ -1231,6 +1232,7 @@ namespace OS {
}) })
.done(function (data) { .done(function (data) {
tasks.push("OK"); tasks.push("OK");
xhr.abort();
if (tasks.length == n_files) if (tasks.length == n_files)
{ {
API.loaded(q, p, "OK"); API.loaded(q, p, "OK");

View File

@ -162,7 +162,7 @@ namespace OS {
* which contains an error or a list of FileInfoType * which contains an error or a list of FileInfoType
*/ */
export function scandir(p: string): Promise<RequestResult> { export function scandir(p: string): Promise<RequestResult> {
const path = `${REST}/VFS/scandir?__t=${(new Date()).getTime()}`; const path = `${REST}/VFS/scandir`;
return API.post(path, { path: p }); return API.post(path, { path: p });
} }
@ -176,7 +176,7 @@ namespace OS {
* which contains an error or true on success * which contains an error or true on success
*/ */
export function mkdir(p: string): Promise<RequestResult> { export function mkdir(p: string): Promise<RequestResult> {
const path = `${API.REST}/VFS/mkdir?__t=${(new Date()).getTime()}`; const path = `${API.REST}/VFS/mkdir`;
return API.post(path, { path: p }); return API.post(path, { path: p });
} }
@ -194,7 +194,7 @@ namespace OS {
p: string, p: string,
pub: boolean pub: boolean
): Promise<RequestResult> { ): Promise<RequestResult> {
const path = `${API.REST}/VFS/publish?__t=${(new Date()).getTime()}`; const path = `${API.REST}/VFS/publish`;
return API.post(path, { path: p, publish: pub }); return API.post(path, { path: p, publish: pub });
} }
@ -207,7 +207,7 @@ namespace OS {
* which contains an error or an object of FileInfoType * which contains an error or an object of FileInfoType
*/ */
export function fileinfo(p: string): Promise<RequestResult> { export function fileinfo(p: string): Promise<RequestResult> {
const path = `${API.REST}/VFS/fileinfo?__t=${(new Date()).getTime()}`; const path = `${API.REST}/VFS/fileinfo`;
return API.post(path, { path: p }); return API.post(path, { path: p });
} }
@ -244,7 +244,7 @@ namespace OS {
* which contains an error or a success response * which contains an error or a success response
*/ */
export function move(s: string, d: string): Promise<RequestResult> { export function move(s: string, d: string): Promise<RequestResult> {
const path = `${API.REST}/VFS/move?__t=${(new Date()).getTime()}`; const path = `${API.REST}/VFS/move`;
return API.post(path, { src: s, dest: d }); return API.post(path, { src: s, dest: d });
} }
@ -257,7 +257,7 @@ namespace OS {
* which contains an error or a success response * which contains an error or a success response
*/ */
export function remove(p: string): Promise<RequestResult> { export function remove(p: string): Promise<RequestResult> {
const path = `${API.REST}/VFS/delete?__t=${(new Date()).getTime()}`; const path = `${API.REST}/VFS/delete`;
return API.post(path, { path: p }); return API.post(path, { path: p });
} }
@ -283,7 +283,7 @@ namespace OS {
export function packages( export function packages(
d: PackageCommandType d: PackageCommandType
): Promise<RequestResult> { ): Promise<RequestResult> {
const path = `${API.REST}/system/packages?__t=${(new Date()).getTime()}`; const path = `${API.REST}/system/packages`;
return API.post(path, d); return API.post(path, d);
} }
@ -295,7 +295,7 @@ namespace OS {
* @returns {Promise<RequestResult>} a promise on a [[RequestResult]] * @returns {Promise<RequestResult>} a promise on a [[RequestResult]]
*/ */
export function upload(d: string): Promise<RequestResult> { export function upload(d: string): Promise<RequestResult> {
const path = `${API.REST}/VFS/upload?__t=${(new Date()).getTime()}`; const path = `${API.REST}/VFS/upload`;
return API.upload(path, d); return API.upload(path, d);
} }
@ -311,7 +311,7 @@ namespace OS {
p: string, p: string,
d: string d: string
): Promise<RequestResult> { ): Promise<RequestResult> {
const path = `${API.REST}/VFS/write?__t=${(new Date()).getTime()}`; const path = `${API.REST}/VFS/write`;
return API.post(path, { path: p, data: d }); return API.post(path, { path: p, data: d });
} }
@ -350,7 +350,7 @@ namespace OS {
if (ws) { if (ws) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
try { try {
const path = `${API.BASE_URI}/system/apigateway?ws=1&__t=${(new Date()).getTime()}`; const path = `${API.BASE_URI}/system/apigateway?ws=1`;
const proto = const proto =
window.location.protocol === "https:" window.location.protocol === "https:"
? "wss://" ? "wss://"
@ -362,7 +362,7 @@ namespace OS {
} }
}); });
} else { } else {
const path = `${API.REST}/system/apigateway?ws=0&__t=${(new Date()).getTime()}`; const path = `${API.REST}/system/apigateway?ws=0`;
return API.post(path, d); return API.post(path, d);
} }
} }
@ -375,7 +375,7 @@ namespace OS {
* contains an error or a [[UserSettingType]] object * contains an error or a [[UserSettingType]] object
*/ */
export function auth(): Promise<RequestResult> { export function auth(): Promise<RequestResult> {
const p = `${API.REST}/user/auth?__t=${(new Date()).getTime()}`; const p = `${API.REST}/user/auth`;
return API.post(p, {}); return API.post(p, {});
} }
@ -388,7 +388,7 @@ namespace OS {
* contains an error or a [[UserSettingType]] object * contains an error or a [[UserSettingType]] object
*/ */
export function login(d: UserLoginType): Promise<RequestResult> { export function login(d: UserLoginType): Promise<RequestResult> {
const p = `${API.REST}/user/login?__t=${(new Date()).getTime()}`; const p = `${API.REST}/user/login`;
return API.post(p, d); return API.post(p, d);
} }
@ -399,7 +399,7 @@ namespace OS {
* @returns {Promise<RequestResult>} a promise on a [[RequestResult]] * @returns {Promise<RequestResult>} a promise on a [[RequestResult]]
*/ */
export function logout(): Promise<RequestResult> { export function logout(): Promise<RequestResult> {
const p = `${API.REST}/user/logout?__t=${(new Date()).getTime()}`; const p = `${API.REST}/user/logout`;
return API.post(p, {}); return API.post(p, {});
} }
@ -410,7 +410,7 @@ namespace OS {
* @returns {Promise<RequestResult>} a promise on a [[RequestResult]] * @returns {Promise<RequestResult>} a promise on a [[RequestResult]]
*/ */
export function setting(): Promise<RequestResult> { export function setting(): Promise<RequestResult> {
const p = `${API.REST}/system/settings?__t=${(new Date()).getTime()}`; const p = `${API.REST}/system/settings`;
return API.post(p, OS.setting); return API.post(p, OS.setting);
} }
@ -463,7 +463,7 @@ namespace OS {
cmd: string, cmd: string,
d: GenericObject<any> d: GenericObject<any>
): Promise<RequestResult> { ): Promise<RequestResult> {
const path = `${API.REST}/VDB/${cmd}?__t=${(new Date()).getTime()}`; const path = `${API.REST}/VDB/${cmd}`;
return API.post(path, d); return API.post(path, d);
} }
} }