1
0
mirror of https://github.com/ascribe/onion.git synced 2025-02-14 21:10:27 +01:00

use standard promises instead of fineuploaders'

This commit is contained in:
Tim Daubenschütz 2015-07-27 09:28:50 +02:00
parent d71111b6f1
commit 5da577caca

View File

@ -221,75 +221,73 @@ var ReactS3FineUploader = React.createClass({
}, },
requestKey(fileId) { requestKey(fileId) {
let defer = new fineUploader.Promise();
let filename = this.state.uploader.getName(fileId); let filename = this.state.uploader.getName(fileId);
let uuid = this.state.uploader.getUuid(fileId); let uuid = this.state.uploader.getUuid(fileId);
window.fetch(this.props.keyRoutine.url, { return Q.Promise((resolve, reject) => {
method: 'post', window.fetch(this.props.keyRoutine.url, {
headers: { method: 'post',
'Accept': 'application/json', headers: {
'Content-Type': 'application/json', 'Accept': 'application/json',
'X-CSRFToken': getCookie(AppConstants.csrftoken) 'Content-Type': 'application/json',
}, 'X-CSRFToken': getCookie(AppConstants.csrftoken)
credentials: 'include', },
body: JSON.stringify({ credentials: 'include',
'filename': filename, body: JSON.stringify({
'category': this.props.keyRoutine.fileClass, 'filename': filename,
'uuid': uuid, 'category': this.props.keyRoutine.fileClass,
'piece_id': this.props.keyRoutine.pieceId 'uuid': uuid,
'piece_id': this.props.keyRoutine.pieceId
})
}) })
}) .then((res) => {
.then((res) => { return res.json();
return res.json(); })
}) .then((res) =>{
.then((res) =>{ resolve(res.key);
defer.success(res.key); })
}) .catch((err) => {
.catch((err) => { reject(err);
defer.failure(err); });
}); });
return defer;
}, },
createBlob(file) { createBlob(file) {
let defer = new fineUploader.Promise(); return Q.Promise((resolve, reject) => {
window.fetch(this.props.createBlobRoutine.url, {
window.fetch(this.props.createBlobRoutine.url, { method: 'post',
method: 'post', headers: {
headers: { 'Accept': 'application/json',
'Accept': 'application/json', 'Content-Type': 'application/json',
'Content-Type': 'application/json', 'X-CSRFToken': getCookie(AppConstants.csrftoken)
'X-CSRFToken': getCookie(AppConstants.csrftoken) },
}, credentials: 'include',
credentials: 'include', body: JSON.stringify({
body: JSON.stringify({ 'filename': file.name,
'filename': file.name, 'key': file.key,
'key': file.key, 'piece_id': this.props.createBlobRoutine.pieceId
'piece_id': this.props.createBlobRoutine.pieceId })
}) })
}) .then((res) => {
.then((res) => { return res.json();
return res.json(); })
}) .then((res) =>{
.then((res) =>{ if(res.otherdata) {
if(res.otherdata) { file.s3Url = res.otherdata.url_safe;
file.s3Url = res.otherdata.url_safe; file.s3UrlSafe = res.otherdata.url_safe;
file.s3UrlSafe = res.otherdata.url_safe; } else if(res.digitalwork) {
} else if(res.digitalwork) { file.s3Url = res.digitalwork.url_safe;
file.s3Url = res.digitalwork.url_safe; file.s3UrlSafe = res.digitalwork.url_safe;
file.s3UrlSafe = res.digitalwork.url_safe; } else {
} else { throw new Error(getLangText('Could not find a url to download.'));
throw new Error(getLangText('Could not find a url to download.')); }
} resolve(res.key);
defer.success(res.key); })
}) .catch((err) => {
.catch((err) => { reject(err);
defer.failure(err); console.logGlobal(err);
console.logGlobal(err); });
}); });
return defer;
}, },
/* FineUploader specific callback function handlers */ /* FineUploader specific callback function handlers */