-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
102 lines (89 loc) · 2.79 KB
/
Copy pathscript.js
File metadata and controls
102 lines (89 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const BASE_URL = "https://bitsend.herokuapp.com/"
$(document).ready(function() {
let typed = new Typed('.title', {
strings: ["Your personal file courier service"],
typeSpeed: 40
});
$('form input').change(function() {
$('form p').text(this.files[0].name + " selected");
});
});
async function upload(){
let file = document.getElementById("files").files[0];
let b64, contentId;
try {
b64 = await getBase64(file);
}
catch(e){
console.log(e);
}
try {
contentId = await fetch(BASE_URL + "store", {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': "text/plain"
},
body: b64
});
contentId = await contentId.json();
}
catch(e){
console.log(e);
}
console.log(contentId);
contentId = contentId.success;
if (contentId != null){
let accessUrl = `${window.location.href.substring(0, str.length - 1)}#${contentId}`;
let copyHTML = `
<div class="input-group" style=" margin: 15vh 0px; width: 100%; ">
<input style="margin-right: 40px;width: 50%;" id="foo" value="${accessUrl}">
<button class="btn" type="button" data-clipboard-demo="" data-clipboard-target="#foo">
Copy
</button>
</div>
`;
$("#bitstream").html(copyHTML);
alert(`You have 5 minutes to visit the following link in your browser: \n${accessUrl}`);
}
}
async function getFile(fileID){
let content;
try{
const rawResponse = await fetch(BASE_URL + `get/${fileID}`);
content = await rawResponse.json();
let data = content.data;
if (data.indexOf("image")){
$("html").html(`<img src="${data}" style="max-height: 100vh;max-width: 100%;">`);
}
else{
document.getElementById('content-frame').src = data;
$("#content-frame").show();
$("main").hide();
}
}
catch(e){
console.error(e);
alert(e);
}
}
function getBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = error => reject(error);
});
}
if(window.location.hash) {
let hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
if (hash.length != 8){
alert(`We detected a request to get the following id: ${hash}, but it seems like there was a typo.`);
}
else{
getFile(hash);
}
// hash found
} else {
// No hash found
}