1
0
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:
diminator 2015-07-23 15:33:54 +02:00
commit 5c3d57ff3a
5 changed files with 67 additions and 3 deletions

View File

@ -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">

View File

@ -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());
}

View File

@ -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
View 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();
}

View File

@ -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",