parent
e5f08b454c
commit
43198daba3
3 changed files with 35 additions and 5 deletions
|
@ -1,10 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
const nprogress = require('nprogress');
|
||||
const cookies = require('js-cookie');
|
||||
const request = require('superagent');
|
||||
const config = require('./config.js');
|
||||
const events = require('./events.js');
|
||||
const progress = require('./util/progress.js');
|
||||
|
||||
class Api extends events.EventTarget {
|
||||
constructor() {
|
||||
|
@ -259,18 +259,18 @@ class Api extends events.EventTarget {
|
|||
}
|
||||
|
||||
if (!options.noProgress) {
|
||||
nprogress.start();
|
||||
progress.start();
|
||||
}
|
||||
|
||||
abortFunction = () => {
|
||||
req.abort(); // does *NOT* call the callback passed in .end()
|
||||
nprogress.done();
|
||||
progress.done();
|
||||
reject(
|
||||
new Error('The request was aborted due to user cancel.'));
|
||||
};
|
||||
|
||||
req.end((error, response) => {
|
||||
nprogress.done();
|
||||
progress.done();
|
||||
abortFunction = () => {};
|
||||
if (error) {
|
||||
if (response && response.body) {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
const api = require('../api.js');
|
||||
const router = require('../router.js');
|
||||
const misc = require('../util/misc.js');
|
||||
const progress = require('../util/progress.js');
|
||||
const topNavigation = require('../models/top_navigation.js');
|
||||
const Post = require('../models/post.js');
|
||||
const PostUploadView = require('../views/post_upload_view.js');
|
||||
|
@ -83,6 +84,7 @@ class PostUploadController {
|
|||
}
|
||||
|
||||
_uploadSinglePost(uploadable, skipDuplicates) {
|
||||
progress.start();
|
||||
let reverseSearchPromise = Promise.resolve();
|
||||
if (!uploadable.lookalikesConfirmed) {
|
||||
reverseSearchPromise =
|
||||
|
@ -121,8 +123,12 @@ class PostUploadController {
|
|||
});
|
||||
this._lastCancellablePromise = savePromise;
|
||||
return savePromise;
|
||||
}).catch(error => {
|
||||
}).then(result => {
|
||||
progress.done();
|
||||
return Promise.resolve(result);
|
||||
}, error => {
|
||||
error.uploadable = uploadable;
|
||||
progress.done();
|
||||
return Promise.reject(error);
|
||||
});
|
||||
}
|
||||
|
|
24
client/js/util/progress.js
Normal file
24
client/js/util/progress.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
const nprogress = require('nprogress');
|
||||
|
||||
let nesting = 0;
|
||||
|
||||
function start() {
|
||||
if (!nesting) {
|
||||
nprogress.start();
|
||||
}
|
||||
nesting++;
|
||||
}
|
||||
|
||||
function done() {
|
||||
nesting--;
|
||||
if (nesting > 0) {
|
||||
nprogress.inc();
|
||||
} else {
|
||||
nprogress.done();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
start: start,
|
||||
done: done,
|
||||
};
|
Loading…
Reference in a new issue