Skip to content

Commit

Permalink
Formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleyg authored Jun 7, 2022
1 parent f78df4a commit 99af5b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
3 changes: 2 additions & 1 deletion s3direct/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
['token', 'secret_key', 'access_key'])
SESSION = None
if session is not None:
SESSION=session.get_session()
SESSION = session.get_session()


def get_s3direct_destinations():
"""Returns s3direct destinations.
Expand Down
51 changes: 24 additions & 27 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const request = (method, url, data, headers, el, cb) => {
let req = new XMLHttpRequest();
req.open(method, url, true);

Object.keys(headers).forEach(key => {
Object.keys(headers).forEach((key) => {
req.setRequestHeader(key, headers[key]);
});

Expand All @@ -26,11 +26,11 @@ const request = (method, url, data, headers, el, cb) => {
req.send(data);
};

const parseNameFromUrl = url => {
const parseNameFromUrl = (url) => {
return decodeURIComponent((url + '').replace(/\+/g, '%20'));
};

const parseJson = json => {
const parseJson = (json) => {
let data;
try {
data = JSON.parse(json);
Expand All @@ -53,7 +53,7 @@ const error = (el, msg) => {

let concurrentUploads = 0;

const disableSubmit = status => {
const disableSubmit = (status) => {
const submitRow = document.querySelector('.submit-row');
if (!submitRow) return;

Expand All @@ -64,7 +64,7 @@ const disableSubmit = status => {
if (status === true) concurrentUploads++;
else concurrentUploads--;

[].forEach.call(buttons, el => {
[].forEach.call(buttons, (el) => {
el.disabled = concurrentUploads !== 0;
});
};
Expand All @@ -74,25 +74,21 @@ const finishUpload = (element, endpoint, bucket, objectKey) => {
const url = element.querySelector('.file-url');
url.value = endpoint + '/' + bucket + '/' + objectKey;
link.setAttribute('href', url.value);
link.innerHTML = parseNameFromUrl(url.value)
.split('/')
.pop();
link.innerHTML = parseNameFromUrl(url.value).split('/').pop();
element.className = 's3direct link-active';
element.querySelector('.bar').style.width = '0%';
disableSubmit(false);
};

const computeMd5 = data => {
const computeMd5 = (data) => {
return btoa(SparkMD5.ArrayBuffer.hash(data, true));
};

const computeSha256 = data => {
return createHash('sha256')
.update(data, 'utf-8')
.digest('hex');
const computeSha256 = (data) => {
return createHash('sha256').update(data, 'utf-8').digest('hex');
};

const getCsrfToken = element => {
const getCsrfToken = (element) => {
const cookieInput = element.querySelector('.csrf-cookie-name');
const input = document.querySelector('input[name=csrfmiddlewaretoken]');
const token = input ? input.value : Cookies.get(cookieInput.value);
Expand All @@ -109,7 +105,7 @@ const generateAmzInitHeaders = (acl, serverSideEncryption, sessionToken) => {
return headers;
};

const generateAmzCommonHeaders = sessionToken => {
const generateAmzCommonHeaders = (sessionToken) => {
const headers = {};
if (sessionToken) headers['x-amz-security-token'] = sessionToken;
return headers;
Expand Down Expand Up @@ -162,7 +158,7 @@ const initiateUpload = (element, signingUrl, uploadParameters, file, dest) => {
partSize: 20 * 1024 * 1024,
logging: true,
allowS3ExistenceOptimization: uploadParameters.allow_existence_optimization,
s3FileCacheHoursAgo: uploadParameters.allow_existence_optimization ? 12 : 0
s3FileCacheHoursAgo: uploadParameters.allow_existence_optimization ? 12 : 0,
};

const addConfig = {
Expand All @@ -182,7 +178,7 @@ const initiateUpload = (element, signingUrl, uploadParameters, file, dest) => {
if (msg.includes('InvalidAccessKeyId')) {
error(element, msg);
}
}
},
};

const optHeaders = {};
Expand All @@ -197,22 +193,22 @@ const initiateUpload = (element, signingUrl, uploadParameters, file, dest) => {

addConfig['notSignedHeadersAtInitiate'] = optHeaders;

Evaporate.create(createConfig).then(evaporate => {
Evaporate.create(createConfig).then((evaporate) => {
disableSubmit(true);

element.className = 's3direct progress-active';

const cancelButton = element.querySelector('.cancel-button');

const cancelUpload = e => {
const cancelUpload = (e) => {
e.preventDefault();
evaporate.cancel(`${uploadParameters.bucket}/${addConfig.name}`);
};

cancelButton.addEventListener('click', cancelUpload, false);

evaporate.add(addConfig).then(
s3Objkey => {
(s3Objkey) => {
cancelButton.removeEventListener('click', cancelUpload);
finishUpload(
element,
Expand All @@ -221,15 +217,15 @@ const initiateUpload = (element, signingUrl, uploadParameters, file, dest) => {
s3Objkey
);
},
reason => {
(reason) => {
cancelButton.removeEventListener('click', cancelUpload);
return error(element, reason);
}
);
});
};

const checkFileAndInitiateUpload = event => {
const checkFileAndInitiateUpload = (event) => {
const element = event.target.parentElement;
const file = element.querySelector('.file-input').files[0];
const dest = element.querySelector('.file-dest').value;
Expand Down Expand Up @@ -260,15 +256,15 @@ const checkFileAndInitiateUpload = event => {
});
};

const removeUpload = e => {
const removeUpload = (e) => {
e.preventDefault();
const el = e.target.parentElement;
el.querySelector('.file-url').value = '';
el.querySelector('.file-input').value = '';
el.className = 's3direct form-active';
};

const addHandlers = el => {
const addHandlers = (el) => {
const url = el.querySelector('.file-url');
const input = el.querySelector('.file-input');
const remove = el.querySelector('.file-remove');
Expand All @@ -279,7 +275,8 @@ const addHandlers = el => {
input.addEventListener('change', checkFileAndInitiateUpload, false);
};

const observer = new MutationObserver(function (m) {[].forEach.call(document.querySelectorAll('.s3direct'), addHandlers);});
const observer_config = {childList: true, subtree: true};
const observer = new MutationObserver(function (m) {
[].forEach.call(document.querySelectorAll('.s3direct'), addHandlers);
});
const observer_config = { childList: true, subtree: true };
observer.observe(document.body, observer_config);

0 comments on commit 99af5b3

Please sign in to comment.