Skip to content

Commit 2a374ec

Browse files
committed
magic local uploads
1 parent 01f9fc1 commit 2a374ec

File tree

6 files changed

+172
-0
lines changed

6 files changed

+172
-0
lines changed

cloudsave.zip

441 KB
Binary file not shown.

hosts/hotfile.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//uses multipart helper function.
2+
Hosts.hotfile = function uploadHotfile(file, callback){
3+
//http://api.hotfile.com/?action=getuploadserver
4+
5+
var xhr = new XMLHttpRequest();
6+
xhr.open("GET", https()+"api.hotfile.com/?action=getuploadserver");
7+
xhr.send();
8+
xhr.onload = function(){
9+
var post_url = https()+xhr.responseText.trim()+'/upload.cgi?'+(+new Date);
10+
11+
var xhr2 = new XMLHttpRequest();
12+
xhr2.open("POST", post_url);
13+
14+
xhr2.onerror = function(){
15+
callback('error: hotfile hosting error')
16+
}
17+
xhr2.onload = function(){
18+
var url = xhr2.responseText.match(/value="(http.*?)"/);
19+
if(url) callback({url: url[1]});
20+
console.log(xhr2, url)
21+
}
22+
xhr2.sendMultipart({
23+
iagree: 'on',
24+
'uploads[]': file
25+
})
26+
27+
}
28+
xhr.onerror = function(){
29+
callback('error: hotfile could not get upload server');
30+
}
31+
32+
}

hosts/imageshack.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//uses multipart helper function.
2+
//magic totally obfuscated key that you shall never see
3+
//39ACEJNQa5b92fbce7fd90b1cb6f1104d728eccb
4+
//does not support https
5+
6+
7+
Hosts.imageshack = function uploadImageshack(file, callback){
8+
var xhr = new XMLHttpRequest();
9+
xhr.open("POST", "http://www.imageshack.us/upload_api.php");
10+
xhr.onload = function(){
11+
try{
12+
var link = xhr.responseXML.getElementsByTagName('image_link');
13+
callback({url: link[0].childNodes[0].nodeValue});
14+
}catch(err){
15+
callback('error: imageshack uploading failed')
16+
}
17+
}
18+
xhr.onerror = function(){
19+
callback('error: imageshack uploading failed')
20+
}
21+
xhr.sendMultipart({
22+
key: Keys.imageshack,
23+
fileupload: file
24+
})
25+
}
26+
27+

hosts/imgur.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//*
2+
Hosts.imgur = function uploadImgur(req, callback){
3+
console.log('using new version of imgur');
4+
var xhr = new XMLHttpRequest();
5+
xhr.open("POST", https()+"api.imgur.com/2/upload.json", true);
6+
xhr.onload = function(){
7+
var data = JSON.parse(xhr.responseText);
8+
callback({
9+
direct: data.upload.links.original,
10+
url: data.upload.links.imgur_page,
11+
thumb: data.upload.links.small_square //or maybe large_thumbnail
12+
})
13+
}
14+
xhr.sendMultipart({
15+
key: Keys.imgur,
16+
image: req
17+
})
18+
19+
}
20+
21+
//*/

hosts/immio.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//https://chrome.google.com/extensions/detail/mdddabjhelpilpnpgondfmehhcplpiin (A stretch, but it introduced me to the imm.io hosting service and I made my implementation by sniffing traffic data)
2+
3+
4+
Hosts.immio = function uploadImmio(req, callback){
5+
var xhr = new XMLHttpRequest();
6+
xhr.open('POST', 'http://imm.io/?callback=true&name=drag2up');
7+
xhr.onload = function(){
8+
if(xhr.responseText.indexOf('ERR:') != -1){
9+
callback('error: could not upload to immio (multipart) '+ xhr.responseText);
10+
}else{
11+
var url = xhr.responseText;
12+
13+
callback({
14+
url: url,
15+
direct: url.replace(/^(.*)\/(..)(.*)$/,'$1/media/$2/$2$3.')+req.name.replace(/^.*\./g,'')
16+
})
17+
}
18+
}
19+
xhr.sendMultipart({
20+
image: req
21+
})
22+
}
23+

settings.html

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Cloud Save Settings</title>
5+
<style>
6+
body {
7+
font-family: sans-serif, helvetica, arial;
8+
margin-right: 50px;
9+
margin-left: 120px;
10+
background: url(icon/64.png) no-repeat;
11+
background-position: 30px 30px;
12+
}
13+
</style>
14+
15+
</head>
16+
<body>
17+
<h2 id="progress">Cloud Save Settings</h2>
18+
<p>
19+
Please excuse the fact that this settings page is mostly empty.
20+
</p>
21+
<p>
22+
<input type="checkbox" id="moar" onchange="toggle_additional(this.checked)"> <label for="moar">Enable Additional Hosts</label>
23+
</p>
24+
<p>
25+
Local File Upload (Beta):
26+
</p>
27+
<p>
28+
<select id="hostselect"></select>
29+
<input type="file" onchange="upload(this.files)" multiple>
30+
</p>
31+
<script>
32+
function toggle_additional(state){
33+
localStorage.additional = state ? 'yes': '';
34+
chrome.extension.getBackgroundPage().install_additional(state);
35+
}
36+
document.getElementById('moar').checked = localStorage.additional=='yes'
37+
38+
var titles = chrome.extension.getBackgroundPage().title_map;
39+
for(var host in titles){
40+
var opt = document.createElement('option');
41+
opt.innerHTML = titles[host];
42+
opt.value = host;
43+
document.getElementById('hostselect').appendChild(opt);
44+
}
45+
46+
function upload(files){
47+
for(var i = 0; i < files.length; i++){
48+
var url, file = files[i];
49+
if(window.createObjectURL){
50+
url = window.createObjectURL(file)
51+
}else if(window.createBlobURL){
52+
url = window.createBlobURL(file)
53+
}else if(window.URL && window.URL.createObjectURL){
54+
url = window.URL.createObjectURL(file)
55+
}else if(window.webkitURL && window.webkitURL.createObjectURL){
56+
url = window.webkitURL.createObjectURL(file)
57+
}
58+
chrome.extension.getBackgroundPage().upload(document.getElementById('hostselect').value, url, file.name);
59+
}
60+
}
61+
62+
</script>
63+
<hr>
64+
<div style="font-size: small">
65+
Part of the <a href="https://github.com/antimatter15/cloudsave">Cloud Save project</a>. Written by <a href="http://twitter.com/antimatter15">@antimatter15</a> (please follow me on twitter). Email comments and concerns to antimatter15@gmail.com.
66+
</div>
67+
68+
</body>
69+
</html>

0 commit comments

Comments
 (0)