var UpdateView = ClassBase.extend({
versionDev:{version:"1.49",build:'10'}, // 开发环境
versionRelease:{version:"1.49",build:'10'}, // 推送版本
versionReleaseAll:{version:"1.49",build:'10'}, // 稳定大版本;针对企业授权客户;
// releaseBefore:1.48.03 1.49.10
statusLink:'https://api.kodcloud.com/?state/index',
readmoreLink:'https://doc.kodcloud.com/v2/#/help/changeLog',
versionPackage:'http://static.kodcloud.com/update/update/',
updateLog:{
'zh-CN':"\
#### 更新内容:
\
- 详见更新说明",
'en':"\
- correlation, bug repair, security optimization
\
"
},
init:function(){
this.BASIC_PATH = _.get(window,'G.kod.BASIC_PATH');
this.DATA_PATH = this.BASIC_PATH+'config/';
this.versionLocal = parseFloat(_.get(window,'G.kod.version',''));
this.versionIsRoot = parseFloat(_.get(window,'G.user.isRoot',''));
this.versionBuildLocal = _.get(window,'G.kod.build');
this.pathModel = _.get(window,'kodApp.pathAction.pathModel');
if(!this.versionLocal) return;
this.userState();
requireAsync('https://static.kodcloud.com/update/log.js?v='+window._ktime);
var release = this.versionRelease;
// 授权版本; 推送相对稳定的版本;
if(this.disableVipUpdate()){release = this.versionReleaseAll;}
if( this.versionLocal == '1' || this.isDevSite() ){
release = this.versionDev;
}
// console.log(101,release,this.disableVipUpdate());
this.versionServer = release.version;
this.versionBuild = release.build;
this.versionServerMust = 1.49; // 安全修复,最低版本要求,小于该版本会预警提醒;
this.versionPackage = this.versionPackage+'update-'+this.versionServer+'.zip?v='+time();
this.initLanguage();
// 加入到全局对象;
G.kod.update = {
version:this.versionServer,
build:this.versionBuild,
check:_.bind(this.updateShow,this),
view:this
};
Events.trigger('uploadView.initAfter',self);
if(!this.pathModel){
this.pathModel = _.get(window,'kodApp.pathAction.pathModel');
if(!this.pathModel && window.kodApi && kodApi.componment && kodApi.componment.pathModel){
this.pathModel = new kodApi.componment.pathModel();
}
return;
}
this.checkIE();
this.checkStart();
},
/**
* 更新检测:
*
* 需要更新: 管理员登陆,文件管理页面;
* 版本不相等;build不相等都进行更新;
*/
needUpdate:function(){
if(!this.versionIsRoot) return false;
if($(".share-page-topbar").length) return false;
if(this.versionServer > this.versionLocal) return true;
// 预发布时, 不判断build;
if(this.versionServer == this.versionLocal){
// if(this.versionBuild != this.versionBuildLocal) return true;
if(this.versionBuild > this.versionBuildLocal) return true;
}
return false;
},
checkStart:function(){
if(!this.needUpdate()) return;
if(parseFloat(this.versionLocal) <= this.versionServerMust ){
return this.updateShow();
} // 小于安全版本, 则提示升级;
this.keyTimeout = 'kod_updateIgnore_timeout'+this.versionServer;
var notCheck = ['hikvision.com','35.com','Macrosan','npave.com','Npave'];
var channel = _.get(window,'G.kod.channel');
if(_.includes(notCheck,channel)) return;
if(this.disableVipUpdate()) return;
this.updateShow();
},
isDevSite:function(){
var href = window.location.href;
var host = $.parseUrl().host;
if(_.includes(['localhost','127.0.0.1'],host)) return true;
if( href.search("/works/0.kod/") != -1 ||
href.search("kodin.io") != -1 ||
href.search("kodcloud.com") != -1 ){
return true;
}
var devSiteID = [
'7e3368eccbd1a90079907583a74b5f4e', // group
'1b1a1e0117bd74eee79a18019616df83', // 81;
'6943b51c47536f3da1c0f42eab818481', // 190
];
if(_.includes(devSiteID,G.kod.kodID)) return true;
return false;
},
// 授权版默认不自动提示升级, 可在后台点击检测版本后手动手动升级(确保版本稳定)
disableVipUpdate:function(){
if(this.isDevSite()) return false;
if(_.get(G,'kod.versionType') == 'A') return false;
if(parseFloat(_.get(G,'kod.version','1')) < '1.14') return false;
return true;
},
userState:function(){
var param = {
version:this.versionLocal,
type:this.versionIsRoot,
sid:time(),
hash:_.get(window,'G.kod.versionHash',''),
hashUser:_.get(window,'G.kod.versionHashUser',''),
channel:_.get(window,'G.kod.channel',''),
id:_.get(window,'G.kod.kodID',''),
uid:_.get(window,'G.kod.userID',''),
env:_.get(window,'G.kod.versionEnv',''),
link:urlEncode(window.location.href)
};
var link = this.statusLink;
_.each(param,function(val,key){
if(!val) return;
link += '&'+key+'='+val;
});
this.loadScript(link,function(){
Events.trigger('updateCheck.finished',"");
});
this.profillFixTemp();
},
loadScript:function(src,callback) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
script.onload = script.onreadystatechange = function() {
if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete" ) {
callback && callback();
script.onload = script.onreadystatechange = null;
}
};
head.appendChild(script);
},
updateShow:function(showDialog){
var self = this;
var LNG = this.LNG;
var dialogID = 'check-version-dialog';
var lastTime = parseInt(LocalData.get(this.keyTimeout)) || 0;
var hasNew = this.needUpdate();
// 安全漏洞修复,提醒升级;
if(parseFloat(this.versionLocal) < this.versionServerMust ){
showDialog = true;
var text = '紧急安全问题修复,强烈推荐升级到最新版!';
if(this.LNG.type == 'en'){text = 'Emergency vulnerability repair!';}
this.LNG['updateInfo'] = ""+text+"";
}
// 强制显示版本信息;
if(!showDialog){
if ( lastTime > time() || !hasNew) return;
if($('.'+dialogID).exists()) return;
}
var render = template.compile(this.tplDialogHtml());
var html = render({
LNG:LNG,
hasNew:hasNew,
versionPackage:this.versionPackage,
readmoreLink:this.readmoreLink,
versionNew:this.versionServer,
versionLocal:this.versionLocal,
versionBuildLocal:this.versionBuildLocal || '',
versionBuild:this.versionBuild
});
this.dialog = $.dialog({
id:dialogID,
simple:true,
top:'50%',
resize:false,
width:330,
title:LNG.updateTitle,
padding:'0',
fixed:true,
content:html
});
var $main = this.dialog.$main;
$main.find('.update-start').bind('click',function(){
LocalData.del(self.keyTimeout);
if(parseFloat(this.versionLocal) >= 1.41){
// 1.41以后版本通过接口更新(适应关闭访问物理路径的情况)
return self.updateStartNew();
}
self.updateStart();
});
$main.find('.update-self-dialog').bind('click',function(){
self.updateUserSelf();
});
$main.find('.ignore').bind('click',function(){
LocalData.set(self.keyTimeout,time()+3600*24*3); //3天不提示该版本;
self.dialog.close();
});
},
// 开始更新; 检测权限-->下载-->[检测下载直到完成,速度计算]--> 解压覆盖,删除压缩包;
updateStart:function(){
var self = this, LNG = this.LNG, $main = this.dialog.$main,pathModel = this.pathModel;
var DATA_PATH = this.DATA_PATH, BASIC_PATH = this.BASIC_PATH || '';
var zipFile = DATA_PATH+'update-'+this.versionServer+'.zip';
var $uploadBtn = $main.find('.update-start');
var $progress = $main.find('.progress');
var $tips = $main.find('.ignore');
var updateCheckAuth = function(callback){
var checkPath = [
BASIC_PATH+'app',
BASIC_PATH+'config',
BASIC_PATH+'plugins',
BASIC_PATH+'config/version.php',
BASIC_PATH+'app/controller/explorer/index.class.php',
];
fileInfo(checkPath,function(data){
var allWriteable = true;
if(!data || !data.code){
allWriteable = false;
}
_.each(data.data,function(item){
if(!item || !item.isWriteable){
allWriteable = false;
}
});
callback.apply(self,[allWriteable]);
});
};
var fileInfo=function(file,callback){
var param = {dataArr:[]};
var fileList = _.isArray(file)?file:[file];
_.each(fileList,function(item){
param.dataArr.push({path:item});
});
self.pathModel.pathInfo(param,function(data){
callback.apply(self,[data]);
});
};
var downloadRequest = _.bind(pathModel.serverDownload,pathModel);
var downloadStart = function(){
var param = {url:self.versionPackage,uuid:UUID(),path:DATA_PATH};
downloadRequest(param,function(data){
clearInterval(self.speedTimer);
if (data && data.code) {
var filePath = _.get(data,'info.path') || data.info || zipFile;//下载地址;
return unzipUpdate(filePath);
}else{
$progress.addClass('hidden');
$uploadBtn.removeClass('hidden').html(LNG.updateAutoUpdate);
$tips.html(LNG.updateDownloadFail);
Tips.tips(LNG.updateDownloadFail,"error");
}
});
self.downloadSpeedWatch(param.uuid,downloadRequest);
};
var unzipUpdate = function(theFile){
//if(window.API_HOST && API_HOST.indexOf('/works/0.kod/')){console.log('test');return;}
var message = "
";
MaskView.tips("
chmod -Rf 777 "+basicPath+"\ windows:
"+LNG.updateErrorWindows+"\ "+LNG.updateErrorDownloadTips+"\
{{@LNG.updateInfo}}
\ {{LNG.updateReadmore}}\ \为了得到站点最好的体验效果,我们建议您升级到Edge。
或使用更现代的浏览器,如Edge、Chrome、360浏览器、UC浏览器、QQ浏览器、猎豹、firefox等。
如果已经是现代浏览器,请将地址栏浏览模式切换为急速模式!