@@ -21,3 +21,86 @@ var settings={
2121 return typeof localStorage . user != "undefined" ?localStorage . user :"guest" ;
2222 } ,
2323}
24+
25+
26+ //upload
27+ $ ( "#upload .choose-file" ) . click (
28+ function ( ) {
29+ $ ( "#upload .input_file" ) . trigger ( 'click' )
30+ }
31+ )
32+
33+ $ ( "#upload .input_file" ) . change (
34+ function ( ) {
35+ var filePath = $ ( "#upload .input_file" ) . val ( )
36+ var pos = filePath . lastIndexOf ( "\\" ) ;
37+ var fileName = filePath . substring ( pos + 1 ) ;
38+ $ ( "#upload .choose-file .input-group-field" ) . val ( fileName )
39+ }
40+ )
41+
42+ $ ( "#upload" ) . find ( "form .button" ) . click ( function ( ) {
43+ if ( ! $ ( "#upload .input_file" ) . val ( ) ) {
44+ return false
45+ }
46+ if ( ! ( document . querySelector ( "#upload .input_file" ) . files [ 0 ] . name . endsWith ( '.mp4' ) ) ) {
47+ $ ( ".flex-center" ) . show ( )
48+ $ ( ".flex-center h6" ) . html ( "Please choose mp4 file" )
49+ $ ( ".flex-center .input-group-bar" ) . hide ( )
50+ return false
51+ } else {
52+ upload ( )
53+ }
54+ } ) ;
55+
56+ function upload ( ) {
57+ $ ( ".flex-center" ) . show ( )
58+ $ ( ".flex-center .input-group-bar" ) . show ( )
59+ const LENGTH = 1024 * 1024 * 10 ;
60+ var timeStamp = new Date ( ) . getTime ( ) ;
61+ var fileName = $ ( "#upload .choose-file .input-group-field" ) . val ( ) ;
62+ var file = document . querySelector ( '#upload .input_file' ) . files [ 0 ] ;
63+ var totalSize = file . size ;
64+ var start = 0 ;
65+ var end = start + LENGTH ;
66+ var fd = null ;
67+ var blob = null ;
68+ var xhr = null ;
69+ var sum = Math . ceil ( totalSize / LENGTH )
70+ var count = 0
71+ var timer = setInterval ( function ( ) {
72+ if ( start < totalSize ) {
73+ fd = new FormData ( ) ;
74+ xhr = new XMLHttpRequest ( ) ;
75+ xhr . open ( 'POST' , '/upload/' , false ) ;
76+ blob = file . slice ( start , end ) ;
77+ fd . append ( 'file' , blob ) ;
78+ fd . append ( 'fileName' , fileName ) ;
79+ fd . append ( 'timeStamp' , timeStamp ) ;
80+ if ( end >= totalSize ) {
81+ fd . append ( 'uploadStatus' , 'end' )
82+ }
83+ xhr . send ( fd ) ;
84+ if ( xhr . status != 200 && xhr . status != 0 ) {
85+ $ ( ".flex-center h6" ) . html ( "Error, Please try again" )
86+ $ ( ".flex-center .input-group-bar" ) . hide ( )
87+ return false
88+ }
89+ count += 1
90+ $ ( ".flex-center h6" ) . html ( "Upload " + parseInt ( count * 100 / sum ) + "%" )
91+ $ ( ".flex-center .bar" ) . width ( parseInt ( count * 100 / sum ) + "%" )
92+ start = end ;
93+ end = start + LENGTH ;
94+ } else {
95+ $ ( ".flex-center h6" ) . html ( "Upload 0%" )
96+ $ ( ".flex-center .bar" ) . width ( "0%" )
97+ $ ( ".flex-center" ) . hide ( )
98+ $ ( "#upload .input_file" ) . val ( '' )
99+ $ ( "#upload .choose-file .input-group-field" ) . val ( '' )
100+ $ ( "#setting" ) . find ( "form" ) . submit ( ) ;
101+ $ ( ".reveal-overlay" ) . trigger ( 'click' ) ;
102+ clearInterval ( timer ) ;
103+ }
104+ } , 100 )
105+ }
106+
0 commit comments