pomf-rehost/worker.js

28 lines
699 B
JavaScript
Raw Normal View History

2016-01-18 05:12:37 +01:00
importScripts('formdata.js')
self.onmessage = function(event) {
var data = JSON.parse(event.data);
var request = new XMLHttpRequest();
request.open('GET', data.url, true);
request.responseType = 'arraybuffer';
request.onload = function(e) {
if (request.status == 200) {
uploadBuffer(data.pomfclone, request.response, data.filename);
}
};
request.send();
};
function uploadBuffer(pomfclone, buffer, filename) {
var formData = new FormData();
formData.append('files[]', buffer, filename);
var request = new XMLHttpRequest();
request.open('POST', pomfclone + '/upload.php', true);
request.onload = function(e) {
postMessage(request.response);
};
request.send(formData);
};