forked from OpenTTD/bananas-frontend-web
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
__pycache__/ | ||
*.pyc | ||
/.env | ||
/node_modules | ||
/package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "bananas3", | ||
"version": "1.0.0", | ||
"description": "bananas-frontend-web", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/OpenTTD/bananas-frontend-web.git" | ||
}, | ||
"author": "", | ||
"license": "GPL-2.0", | ||
"bugs": { | ||
"url": "https://github.com/OpenTTD/bananas-frontend-web/issues" | ||
}, | ||
"homepage": "https://github.com/OpenTTD/bananas-frontend-web#readme", | ||
"dependencies": { | ||
"tus-js-client": "^1.8.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../node_modules/tus-js-client/dist/tus.min.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"use strict"; | ||
|
||
var more_files = document.querySelector("li[id='more_files']"); | ||
var input = document.querySelector("input[id='start_upload']"); | ||
input.addEventListener("change", add_upload); | ||
|
||
var upload_file = null | ||
var upload_token = null | ||
var upload_instance = null | ||
|
||
function add_upload() { | ||
if (input.value == "") return; | ||
var i; | ||
for (i = 0; i < input.files.length; i++) { | ||
var file = input.files[i]; | ||
if (filelist.find(item => item[0] == file.name)) return; | ||
filelist.push([file.name, file, null, false]); | ||
var new_li = document.createElement("li"); | ||
new_li.id = "upload_" + file; | ||
new_li.appendChild(document.createTextNode(file)); | ||
more_files.parentNode.insertBefore(new_li, more_files); | ||
} | ||
input.value = ""; | ||
if (upload_instance == null) start_next_upload(); | ||
} | ||
|
||
function start_next_upload() { | ||
var i; | ||
for (i = 0; i < filelist.length; i++) { | ||
if (!filelist[i][3]) { | ||
upload_file = filelist[i][1]; | ||
break; | ||
} | ||
} | ||
|
||
if (upload_file == null) return; | ||
|
||
var options = { | ||
endpoint: tus_url, | ||
retryDelays: [0, 1000, 3000, 5000], | ||
metadata: { | ||
filename: upload_file.name, | ||
filetype: upload_file.type | ||
}, | ||
onError : function(error) { | ||
update_status(upload_file.name, "Failed: " + error); | ||
upload_file = null; | ||
upload_token = null; | ||
upload_instance = null; | ||
}, | ||
onProgress: function(bytesUploaded, bytesTotal) { | ||
var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2); | ||
update_status(upload_file.name, "Uploading: " + percentage + " %"); | ||
}, | ||
onSuccess: function() { | ||
update_status(upload_file.name, "Done"); | ||
var item = filelist.find(item => item[0] == upload_file.name); | ||
if (item != null) item[3] = true; | ||
upload_file = null; | ||
upload_token = null; | ||
upload_instance = null; | ||
start_next_upload(); | ||
} | ||
}; | ||
|
||
upload_instance = new tus.Upload(upload_file, options); | ||
upload.start(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters