48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
//go:build script
|
|
// +build script
|
|
|
|
package js
|
|
|
|
import (
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
)
|
|
|
|
var sharedCommonScripts []*serverconfigs.CommonScript
|
|
|
|
func SetCommonScripts(commonScripts []*serverconfigs.CommonScript) {
|
|
sharedCommonScripts = commonScripts
|
|
}
|
|
|
|
func GetCommonScripts() []*serverconfigs.CommonScript {
|
|
return sharedCommonScripts
|
|
}
|
|
|
|
func IsSameCommonScripts(commonScripts []*serverconfigs.CommonScript) bool {
|
|
var oldScripts = sharedCommonScripts // 为了操作安全需要拷贝
|
|
var newScripts = commonScripts
|
|
if len(oldScripts) != len(newScripts) {
|
|
return false
|
|
}
|
|
var oldMap = map[string]*serverconfigs.CommonScript{} // filename => CommonScript
|
|
for _, script := range oldScripts {
|
|
oldMap[script.Filename] = script
|
|
}
|
|
|
|
var newMap = map[string]*serverconfigs.CommonScript{} // filename => CommonScript
|
|
for _, script := range newScripts {
|
|
newMap[script.Filename] = script
|
|
}
|
|
|
|
for filename, oldScript := range oldMap {
|
|
newScript, ok := newMap[filename]
|
|
if !ok {
|
|
return false
|
|
}
|
|
if oldScript.Code != newScript.Code {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|