mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 18:35:09 +01:00
Merged in AD-604-non-owner-cannot-download-pdfs-an (pull request #19)
Ad 604 non owner cannot download pdfs an
This commit is contained in:
commit
5c3d57ff3a
@ -62,6 +62,7 @@ let MediaContainer = React.createClass({
|
||||
encodingStatus={this.props.content.digital_work.isEncoding} />
|
||||
<p className="text-center">
|
||||
<AclProxy
|
||||
show={['video', 'audio', 'image'].indexOf(mimetype) === -1 || this.props.content.acl.acl_download}
|
||||
aclObject={this.props.content.acl}
|
||||
aclName="acl_download">
|
||||
<Button bsSize="xsmall" className="ascribe-margin-1px" href={this.props.content.digital_work.url} target="_blank">
|
||||
|
@ -45,7 +45,7 @@ let Form = React.createClass({
|
||||
this.setState({submitted: true});
|
||||
this.clearErrors();
|
||||
let action = (this.httpVerb && this.httpVerb()) || 'post';
|
||||
this[action]();
|
||||
window.setTimeout(() => this[action](), 100);
|
||||
},
|
||||
post(){
|
||||
requests
|
||||
@ -59,6 +59,7 @@ let Form = React.createClass({
|
||||
for (let ref in this.refs){
|
||||
data[this.refs[ref].props.name] = this.refs[ref].state.value;
|
||||
}
|
||||
|
||||
if ('getFormData' in this.props){
|
||||
data = mergeOptionsWithDuplicates(data, this.props.getFormData());
|
||||
}
|
||||
|
@ -484,7 +484,6 @@ var ReactS3FineUploader = React.createClass({
|
||||
this.state.uploader.addFiles(files);
|
||||
let oldFiles = this.state.filesToUpload;
|
||||
let oldAndNewFiles = this.state.uploader.getUploads();
|
||||
|
||||
// Add fineuploader specific information to new files
|
||||
for(let i = 0; i < oldAndNewFiles.length; i++) {
|
||||
for(let j = 0; j < files.length; j++) {
|
||||
@ -543,6 +542,7 @@ var ReactS3FineUploader = React.createClass({
|
||||
this.setState(newState);
|
||||
},
|
||||
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
|
61
js/utils/file_utils.js
Normal file
61
js/utils/file_utils.js
Normal file
@ -0,0 +1,61 @@
|
||||
'use strict';
|
||||
|
||||
import SparkMD5 from 'spark-md5';
|
||||
|
||||
/**
|
||||
* Takes a string, creates a text file and returns the URL
|
||||
*
|
||||
* @param {string} text regular javascript string
|
||||
* @return {string} regular javascript string
|
||||
*/
|
||||
export function makeTextFile(text) {
|
||||
let data = new Blob([text], {type: 'text/plain'});
|
||||
return window.URL.createObjectURL(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a file Object, computes the MD5 hash and returns the URL of the textfile with the hash
|
||||
*
|
||||
* @param {File} file javascript File object
|
||||
* @return {string} regular javascript string
|
||||
*/
|
||||
export function computeHashOfFile(file) {
|
||||
let blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice,
|
||||
chunkSize = 2097152, // Read in chunks of 2MB
|
||||
chunks = Math.ceil(file.size / chunkSize),
|
||||
currentChunk = 0,
|
||||
spark = new SparkMD5.ArrayBuffer(),
|
||||
fileReader = new FileReader();
|
||||
|
||||
let startTime = new Date();
|
||||
fileReader.onload = function (e) {
|
||||
//console.log('read chunk nr', currentChunk + 1, 'of', chunks);
|
||||
spark.append(e.target.result); // Append array buffer
|
||||
currentChunk++;
|
||||
|
||||
if (currentChunk < chunks) {
|
||||
loadNext();
|
||||
} else {
|
||||
let fileHash = spark.end();
|
||||
console.info('computed hash %s (took %d s)',
|
||||
fileHash,
|
||||
Math.round(((new Date() - startTime) / 1000) % 60)); // Compute hash
|
||||
let hashFile = this.makeTextFile(fileHash);
|
||||
console.info('hash: ', hashFile);
|
||||
return hashFile;
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
fileReader.onerror = function () {
|
||||
console.warn('oops, something went wrong.');
|
||||
};
|
||||
function loadNext() {
|
||||
var start = currentChunk * chunkSize,
|
||||
end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;
|
||||
|
||||
fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
|
||||
}
|
||||
|
||||
loadNext();
|
||||
|
||||
}
|
@ -83,7 +83,8 @@
|
||||
"vinyl-buffer": "^1.0.0",
|
||||
"vinyl-source-stream": "^1.1.0",
|
||||
"watchify": "^3.1.2",
|
||||
"yargs": "^3.10.0"
|
||||
"yargs": "^3.10.0",
|
||||
"spark-md5": "~1.0.0"
|
||||
},
|
||||
"jest": {
|
||||
"scriptPreprocessor": "node_modules/babel-jest",
|
||||
|
Loading…
Reference in New Issue
Block a user