diff --git a/site/i/t_192.png b/site/i/t_192.png new file mode 100644 index 0000000..63a8824 Binary files /dev/null and b/site/i/t_192.png differ diff --git a/site/i/t_48.png b/site/i/t_48.png new file mode 100644 index 0000000..07fc780 Binary files /dev/null and b/site/i/t_48.png differ diff --git a/site/i/t_96.png b/site/i/t_96.png new file mode 100644 index 0000000..d9a47b5 Binary files /dev/null and b/site/i/t_96.png differ diff --git a/site/index.html b/site/index.html new file mode 100644 index 0000000..d4f0e3f --- /dev/null +++ b/site/index.html @@ -0,0 +1,184 @@ + + + + + + media + + + + + + + + + + + + + + + + + + + + + + + + +

!! Please report errors, bugs and weird shit to Hajamieli !!

+ +
+

Upload a file

+
+
+ +
+ +

styles coming soon? propably...

+
+ + + + + + \ No newline at end of file diff --git a/site/manifest.json b/site/manifest.json new file mode 100644 index 0000000..291161c --- /dev/null +++ b/site/manifest.json @@ -0,0 +1,28 @@ +{ + "short_name": "hajamedia", + "name": "hajamielis file hosting app", + "description": "upload files", + "version": "0.1", + "background_color": "#010e1c", + "theme_color": "#010e1c", + "display": "standalone", + "orientation": "portrait", + "icons": [ + { + "src": "./i/t_48.png", + "type": "image/png", + "sizes": "48x48" + }, + { + "src": "./i/t_96.png", + "type": "image/png", + "sizes": "96x96" + }, + { + "src": "./i/t_192.png", + "type": "image/png", + "sizes": "192x192" + } + ], + "start_url": "/" +} \ No newline at end of file diff --git a/site/script.js b/site/script.js new file mode 100644 index 0000000..2f6afbe --- /dev/null +++ b/site/script.js @@ -0,0 +1,84 @@ +const form = document.getElementById("userform") +const submit = document.getElementById("submit") +const results = document.getElementById("results") + +const chunksize = 1000000; + +const splitter = (file, hash) => { + let numberofChunks = Math.ceil(file.byteLength/chunksize); + let left = 0 + let chunks = [] + + for (let i = 0; i < numberofChunks; i++) { + const chunkForm = new FormData(); + let contentRange = ""; + let chunk; + if(left+chunksize <= file.byteLength){ + contentRange = `${left}-${left+chunksize}` + chunk = file.slice(left,left+chunksize) + left += chunksize + } else { + contentRange = `${left}-${file.byteLength}` + chunk = file.slice(left,file.byteLength) + } + chunkForm.append('file', new Blob([chunk], {type:"video/webm"})) + + chunks.push( + fetch("/test", { + method: "POST", + headers: { + "Content-Number": i, + "Content-Range": `bytes ${contentRange}/${file.byteLength}`, + "File-Hash": hash + }, + body: chunkForm + })) + + } + return chunks +} + +async function digest(data){ + + const hash = await crypto.subtle.digest("SHA-256", data); + return hash + +} + +const processFile = file => { + const fr = new FileReader() + fr.readAsArrayBuffer(file) + + fr.addEventListener("loadend", e => { + + digest(e.target.result).then(digestBuffer => { + + const hashAsString = Array.from(new Uint8Array(digestBuffer)).map((b) => b.toString(16).padStart(2, "0")).join(""); // hex the buffer for readability + + Promise.all(splitter(e.target.result,hashAsString)) + .then((values) => { + fetch(`/finish`, { + method: "POST", + headers: { + "Content-Type": "json", + }, + body: JSON.stringify({"hash": hashAsString, "type": file.type}) + }) + }) + }) + }) + +} + +submit.addEventListener("click", e => { + e.preventDefault(); + let fd = new FormData(); + + for (const file of form.media.files){ + + processFile(file) + + fd.append('file', file) + console.log(file) + } +}) \ No newline at end of file diff --git a/site/sw.js b/site/sw.js new file mode 100644 index 0000000..ef11cf4 --- /dev/null +++ b/site/sw.js @@ -0,0 +1,3 @@ +self.addEventListener("fetch", function(event) { + console.log(`start server worker`) +}); \ No newline at end of file