<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>YMO netdisk</title>
</head>
<body>
<h1>welcome to YMO netdisk</h1>
<p>upload here</p>
<p>warning:YMO does NOT protect your data, it can be easily read or modified by anyone who has access to this page</p>
<input type="file" id="f">
<button onclick="up()">Upload</button>
<div id="r"></div>
<a href="/download/">visit /download/ for download</a>
<script>
function up(){
    var file=document.getElementById("f").files[0];
    if(!file){alert("选文件");return;}
    var xhr=new XMLHttpRequest();
    var r=document.getElementById("r");
    var start=Date.now();
    var last=0;
    xhr.upload.onprogress=function(e){
        if(!e.lengthComputable)return;
        var now=Date.now();
        var speed=(e.loaded-last)/((now-start)/1000);
        last=e.loaded;
        r.innerText="少女祈祷中... "+(e.loaded/1024/1024).toFixed(2)+"MB/"+(e.total/1024/1024).toFixed(2)+"MB left, speed: "+(speed/1024).toFixed(1)+"KB/s";
    };
    xhr.open("PUT","/files/"+encodeURIComponent(file.name),true);
    xhr.onload=function(){
        var msg;
        if(xhr.status==201)msg="ll!OK!NB!6!zl!";
        else if(xhr.status==200||xhr.status==204)msg="ll!EXIST!COVER?OK!NB!6!zl!";
        else msg="Fail:"+xhr.status;
        r.innerText=msg;
    };
    xhr.send(file);
}
</script>
</body>
</html>