mirror of https://github.com/cloudreve/Cloudreve
				
				
				
			
							parent
							
								
									99033d61c6
								
							
						
					
					
						commit
						9910f8d732
					
				| 
						 | 
				
			
			@ -45,6 +45,41 @@ func InitStatic() {
 | 
			
		|||
	if util.Exists(util.RelativePath("statics")) {
 | 
			
		||||
		util.Log().Info("检测到 statics 目录存在,将使用此目录下的静态资源文件")
 | 
			
		||||
		StaticFS = static.LocalFile(util.RelativePath("statics"), false)
 | 
			
		||||
 | 
			
		||||
		// 检查静态资源的版本
 | 
			
		||||
		f, err := StaticFS.Open("version.json")
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			util.Log().Warning("静态资源版本标识文件不存在,请重新构建或删除 statics 目录")
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		b, err := ioutil.ReadAll(f)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			util.Log().Warning("无法读取静态资源文件版本,请重新构建或删除 statics 目录")
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var v staticVersion
 | 
			
		||||
		if err := json.Unmarshal(b, &v); err != nil {
 | 
			
		||||
			util.Log().Warning("无法解析静态资源文件版本, %s", err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		staticName := "cloudreve-frontend"
 | 
			
		||||
		if conf.IsPro == "true" {
 | 
			
		||||
			staticName += "-pro"
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if v.Name != staticName {
 | 
			
		||||
			util.Log().Warning("静态资源版本不匹配,请重新构建或删除 statics 目录")
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if v.Version != conf.RequiredStaticVersion {
 | 
			
		||||
			util.Log().Warning("静态资源版本不匹配 [当前 %s, 需要: %s],请重新构建或删除 statics 目录", v.Version, conf.RequiredStaticVersion)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	} else {
 | 
			
		||||
		StaticFS = &GinFS{}
 | 
			
		||||
		StaticFS.(*GinFS).FS, err = fs.New()
 | 
			
		||||
| 
						 | 
				
			
			@ -53,38 +88,4 @@ func InitStatic() {
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 检查静态资源的版本
 | 
			
		||||
	f, err := StaticFS.Open("version.json")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		util.Log().Warning("静态资源版本标识文件不存在,请重新构建或删除 statics 目录")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	b, err := ioutil.ReadAll(f)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		util.Log().Warning("无法读取静态资源文件版本,请重新构建或删除 statics 目录")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var v staticVersion
 | 
			
		||||
	if err := json.Unmarshal(b, &v); err != nil {
 | 
			
		||||
		util.Log().Warning("无法解析静态资源文件版本, %s", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	staticName := "cloudreve-frontend"
 | 
			
		||||
	if conf.IsPro == "true" {
 | 
			
		||||
		staticName += "-pro"
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if v.Name != staticName {
 | 
			
		||||
		util.Log().Warning("静态资源版本不匹配,请重新构建或删除 statics 目录")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if v.Version != conf.RequiredStaticVersion {
 | 
			
		||||
		util.Log().Warning("静态资源版本不匹配 [当前 %s, 需要: %s],请重新构建或删除 statics 目录", v.Version, conf.RequiredStaticVersion)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue