Init Repo

This commit is contained in:
root
2019-09-06 23:53:10 +08:00
commit f0ef89dfbb
7905 changed files with 914138 additions and 0 deletions

132
mobile/reg/js/upload.js Executable file
View File

@ -0,0 +1,132 @@
accessid = ''
accesskey = ''
host = ''
policyBase64 = ''
signature = ''
callbackbody = ''
filename = ''
key = ''
expire = 0
g_object_name = ''
g_object_name_type = 'random_name'
now = timestamp = Date.parse(new Date()) / 1000;
dir = 'images'
function send_request() {
var xmlhttp = null;
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else if(window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if(xmlhttp != null) {
// console.log(dir)
serverUrl = '/oss/get.php?dir='+dir;
xmlhttp.open("GET", serverUrl, false);
xmlhttp.send(null);
return xmlhttp.responseText
} else {
mui.alert("Your browser does not support XMLHTTP.");
}
};
function check_object_radio() {
var tt = document.getElementsByName('myradio');
for(var i = 0; i < tt.length; i++) {
if(tt[i].checked) {
g_object_name_type = tt[i].value;
break;
}
}
}
function get_signature() {
//可以判断当前expire是否超过了当前时间,如果超过了当前时间,就重新取一下.3s 做为缓冲
now = timestamp = Date.parse(new Date()) / 1000;
if(expire < now + 3) {
body = send_request()
var obj = eval("(" + body + ")");
host = obj['host']
policyBase64 = obj['policy']
accessid = obj['accessid']
signature = obj['signature']
expire = parseInt(obj['expire'])
callbackbody = obj['callback']
key = obj['dir']
return true;
}
return false;
};
function random_string(len) {  
len = len || 32;  
var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';  
var maxPos = chars.length;  
var pwd = '';  
for(i = 0; i < len; i++) {  
pwd += chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
function get_suffix(filename) {
pos = filename.lastIndexOf('.')
suffix = ''
if(pos != -1) {
suffix = filename.substring(pos)
}
return suffix;
}
function calculate_object_name(filename) {
if(g_object_name_type == 'local_name') {
g_object_name += "${filename}"
} else if(g_object_name_type == 'random_name') {
suffix = get_suffix(filename)
g_object_name = key + random_string(10) + suffix
}
return ''
}
function get_uploaded_object_name(filename) {
if(g_object_name_type == 'local_name') {
tmp_name = g_object_name
tmp_name = tmp_name.replace("${filename}", filename);
return tmp_name
} else if(g_object_name_type == 'random_name') {
return g_object_name
}
}
function set_upload_param(up, filename, ret,savedir) {
dir = savedir;
if(ret == false) {
ret = get_signature()
}
//g_object_name = key;
//console.log(filename);
if(filename != '') {
suffix = get_suffix(filename)
calculate_object_name(filename)
}
// alert(g_object_name)
console.log(g_object_name);
new_multipart_params = {
'key': g_object_name,
'policy': policyBase64,
'OSSAccessKeyId': accessid,
'success_action_status': '200', //让服务端返回200,不然默认会返回204
'callback': callbackbody,
'signature': signature,
};
// console.log(callbackbody);
up.setOption({
'url': host,
'multipart_params': new_multipart_params
});
up.start();
}