@@ -510,6 +510,31 @@ func GetGroupP(group string) string {
510510 return fmt .Sprintf ("%d/%d" , gouliangLines , totalLines )
511511}
512512
513+ // 读取manifest.json的version号
514+ func ReadVersion (filePath string ) string {
515+ // 打开文件
516+ Path := filepath .Join (filePath , "manifest.json" )
517+ file , err := os .Open (Path )
518+ if err != nil {
519+ fmt .Println ("打开文件失败:" , err )
520+ }
521+ defer file .Close ()
522+ // 文件内容转map
523+ var data map [string ]interface {}
524+ decoder := json .NewDecoder (file )
525+ err = decoder .Decode (& data )
526+ if err != nil {
527+ return "未知版本"
528+ }
529+ // 获取version
530+ version , ok := data ["version" ].(string )
531+ if ! ok {
532+ return "未知版本"
533+ }
534+ return version
535+
536+ }
537+
513538func GetAutoArtifactsPro () ([]DogFood , error ) {
514539 // 获取当前目录下所有 .txt 文件
515540 files , err := filepath .Glob (fmt .Sprintf ("%s\\ User\\ JsScript\\ AutoArtifactsPro\\ records\\ *.txt" , Config .BetterGIAddress ))
@@ -1146,3 +1171,56 @@ func GetGroupPInfo() string {
11461171
11471172 return string (s1 )
11481173}
1174+
1175+ func AutoJs () string {
1176+
1177+ url := "https://github.com/babalae/bettergi-scripts-list/archive/refs/heads/main.zip"
1178+ zipFile := "main.zip"
1179+ err := downloadFile (zipFile , url )
1180+ if err != nil {
1181+ return "下载失败"
1182+ }
1183+ err2 := unzipRepo (zipFile , "repo" , "repo/" )
1184+ if err2 != nil {
1185+ return "解压失败"
1186+ }
1187+
1188+ jsNames := Config .JsName
1189+ repoDir := "repo/js"
1190+
1191+ for _ , jsName := range jsNames {
1192+ subFolderPath , err := findSubFolder (repoDir , jsName )
1193+ if err != nil {
1194+ autoLog .Sugar .Errorf ("查找子文件夹失败: %v" , err )
1195+ return fmt .Sprintf ("未找到子文件夹: %s" , jsName )
1196+ }
1197+
1198+ // 找到子文件夹后,执行复制操作
1199+ targetPath := filepath .Join (Config .BetterGIAddress , "User" , "JsScript" , jsName )
1200+ err2 := copy .Copy (subFolderPath , targetPath )
1201+ if err2 != nil {
1202+ fmt .Println (err2 )
1203+ }
1204+ autoLog .Sugar .Infof ("Js脚本: %s 已更新" , subFolderPath )
1205+ }
1206+ os .RemoveAll ("repo" )
1207+ os .RemoveAll ("main.zip" )
1208+
1209+ return "备份成功"
1210+ }
1211+
1212+ // 查找 repo 目录下是否存在名为 targetFolder 的子文件夹
1213+ func findSubFolder (root string , targetFolder string ) (string , error ) {
1214+ entries , err := os .ReadDir (root )
1215+ if err != nil {
1216+ return "" , err
1217+ }
1218+
1219+ for _ , entry := range entries {
1220+ if entry .IsDir () && entry .Name () == targetFolder {
1221+ return filepath .Join (root , entry .Name ()), nil
1222+ }
1223+ }
1224+
1225+ return "" , fmt .Errorf ("未找到子文件夹: %s" , targetFolder )
1226+ }
0 commit comments