nb/hide-http
Alex Kern 11 years ago
parent c4b63ec0e3
commit d8febe77be

@ -1,38 +1,46 @@
import ChunkedBlob from './ChunkedBlob';
import ChunkedBlob from './ChunkedBlob'
export default class DownloadFile {
constructor(name, size, type) {
this.name = name;
this.size = size;
this.type = type;
this.packets = new ChunkedBlob();
this.name = name
this.size = size
this.type = type
this.packets = new ChunkedBlob()
}
addPacket(b) {
this.packets.add(b);
this.packets.add(b)
}
clearPackets() {
this.packets = new ChunkedBlob();
this.packets = new ChunkedBlob()
}
isComplete() {
return this.packets.size === this.size;
return this.getProgress() === 1
}
getProgress() {
return this.packets.size / this.size;
return this.packets.size / this.size
}
download() {
let blob = this.packets.toBlob();
let url = URL.createObjectURL(blob);
let a = document.createElement('a');
a.download = this.name;
a.href = url;
a.click();
URL.revokeObjectURL(url);
let blob = this.packets.toBlob()
let url = URL.createObjectURL(blob)
let a = document.createElement('a')
a.download = this.name
a.href = url
a.click()
URL.revokeObjectURL(url)
}
toJSON() {
return {
name: this.name,
size: this.size,
type: this.type
}
}
}

@ -1,25 +1,33 @@
const packetSize = 16 * 1024;
const packetSize = 16 * 1024
export default class UploadFile {
constructor(file) {
this.name = file.name;
this.size = file.size;
this.type = file.type;
this.blob = file;
this.name = file.name
this.size = file.size
this.type = file.type
this.blob = file
}
countPackets() {
return Math.ceil(this.size / packetSize);
return Math.ceil(this.size / packetSize)
}
getPacket(i) {
if (i < 0 || i >= this.countPackets())
throw new Error('Packet out of bounds');
throw new Error('Packet out of bounds')
let start = i * packetSize;
let end = Math.min(start + packetSize, this.size);
return this.blob.slice(start, end);
let start = i * packetSize
let end = Math.min(start + packetSize, this.size)
return this.blob.slice(start, end)
}
toJSON() {
return {
name: this.name,
size: this.size,
type: this.type
}
}
}

@ -1,2 +1,2 @@
var Alt = require('alt');
export default new Alt();
import Alt from 'alt'
export default new Alt()

@ -15,9 +15,12 @@ export default alt.createStore(class DownloadStore {
this.progress = 0;
this.on('bootstrap', () => {
if (this.file && !(this.file instanceof DownloadFile))
this.file = new DownloadFile(this.file.name, this.file.size, this.file.type);
});
if (this.file && !(this.file instanceof DownloadFile)) {
this.file = new DownloadFile(this.file.name,
this.file.size,
this.file.type);
}
})
}
onRequestDownload() {
@ -40,6 +43,7 @@ export default alt.createStore(class DownloadStore {
conn.on('data', (data) => {
if (this.status !== 'downloading') return;
console.log(data.byteLength);
this.file.addPacket(data);
i++;

@ -53,6 +53,7 @@ export default alt.createStore(class UploadStore {
for (let j = 0; i < totalPackets && j < chunkSize; i++, j++) {
let packet = this.file.getPacket(i);
console.log(packet.size);
conn.send(packet);
}

@ -50,7 +50,7 @@ routes.use(function (req, res) {
ReactRouter.run(clientRoutes, req.url, function (Handler) {
var html = React.renderToString(<Handler data={alt.takeSnapshot()} />);
alt.recycle();
alt.flush();
res.write('<!DOCTYPE html>');
res.end(html);
});

File diff suppressed because one or more lines are too long

@ -51,9 +51,9 @@
}
.arrow.arrow-animated .arrow-border {
-webkit-animation: rotate 2s infinite linear;
-moz-animation: rotate 2s infinite linear;
animation: rotate 2s infinite linear;
-webkit-animation: rotate 5s infinite linear;
-moz-animation: rotate 5s infinite linear;
animation: rotate 5s infinite linear;
}
.arrow .arrow-image {

Loading…
Cancel
Save