]>
git.p6c8.net - jirafeau_mojo42.git/blob - lib/functions.js
15ae08c59b396bfc1fc9720ee5456eaf84abdaa1
2 * Jirafeau, your web file repository
3 * Copyright (C) 2012 Jerome Jutteau <j.jutteau@gmail.com>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 function show_link (url
, reference
, delete_code
, date
)
21 var download_link
= url
+ 'file.php?h=' + reference
;
22 var delete_link
= download_link
+ '&d=' + delete_code
;
23 var delete_link_href
= download_link
+ '&d=' + delete_code
;
24 document
.getElementById('upload_link').innerHTML
= download_link
;
25 document
.getElementById('upload_link').href
= download_link
;
26 document
.getElementById('delete_link').innerHTML
= delete_link
;
27 document
.getElementById('delete_link').href
= delete_link_href
;
30 document
.getElementById('date').innerHTML
= date
;
31 document
.getElementById('validity').style
.display
= '';
34 document
.getElementById('validity').style
.display
= 'none';
37 document
.getElementById('uploading').style
.display
= 'none';
38 document
.getElementById('upload').style
.display
= 'none';
39 document
.getElementById('upload_finished').style
.display
= '';
42 function upload_progress (e
)
44 if (!e
.lengthComputable
)
46 /* Show the user the operation do not reach 100%, the server need time
47 * to give a response before providing the link.
49 var p
= Math
.round (e
.loaded
* 99 / e
.total
);
50 document
.getElementById('uploaded_percentage').innerHTML
= p
.toString() + '%';
53 function upload_failed (e
)
55 /* Todo: Considere showing a error div. */
56 alert ('Sorry, upload failed');
59 function upload (url
, file
, time
, password
, one_time
)
61 var req
= new XMLHttpRequest ();
62 req
.upload
.addEventListener("progress", upload_progress
, false);
63 req
.addEventListener("error", upload_failed
, false);
64 req
.addEventListener("abort", upload_failed
, false);
65 req
.onreadystatechange = function ()
67 if (req
.readyState
== 4 && req
.status
== 200)
69 var res
= req
.responseText
;
72 res
= res
.split ("\n");
77 d
.setSeconds (d
.getSeconds() + 60);
78 else if (time
== 'hour')
79 d
.setSeconds (d
.getSeconds() + 3600);
80 else if (time
== 'day')
81 d
.setSeconds (d
.getSeconds() + 86400);
82 else if (time
== 'week')
83 d
.setSeconds (d
.getSeconds() + 604800);
84 else if (time
== 'month')
85 d
.setSeconds (d
.getSeconds() + 2419200);
86 show_link (url
, res
[0], res
[1], d
.toString());
89 show_link (url
, res
[0], res
[1]);
92 req
.open ("POST", url
+ 'script.php' , true);
94 var form
= new FormData();
95 form
.append ("file", file
);
97 form
.append ("time", time
);
99 form
.append ("key", password
);
101 form
.append ("one_time_download", '1');
105 function start_upload (url
)
108 document
.getElementById('file_select').files
[0],
109 document
.getElementById('select_time').value
,
110 document
.getElementById('input_key').value
,
111 document
.getElementById('one_time_download').checked
patrick-canterino.de