system.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. // SiYuan - Refactor your thinking
  2. // Copyright (c) 2020-present, b3log.org
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. package api
  17. import (
  18. "io"
  19. "net/http"
  20. "os"
  21. "path/filepath"
  22. "strings"
  23. "sync"
  24. "time"
  25. "github.com/88250/gulu"
  26. "github.com/88250/lute"
  27. "github.com/gin-gonic/gin"
  28. "github.com/jinzhu/copier"
  29. "github.com/siyuan-note/logging"
  30. "github.com/siyuan-note/siyuan/kernel/conf"
  31. "github.com/siyuan-note/siyuan/kernel/model"
  32. "github.com/siyuan-note/siyuan/kernel/util"
  33. )
  34. func getWorkspaceInfo(c *gin.Context) {
  35. ret := gulu.Ret.NewResult()
  36. defer c.JSON(http.StatusOK, ret)
  37. ret.Data = map[string]any{
  38. "workspaceDir": util.WorkspaceDir,
  39. }
  40. }
  41. func getNetwork(c *gin.Context) {
  42. ret := gulu.Ret.NewResult()
  43. defer c.JSON(http.StatusOK, ret)
  44. maskedConf, err := model.GetMaskedConf()
  45. if err != nil {
  46. ret.Code = -1
  47. ret.Msg = "get conf failed: " + err.Error()
  48. return
  49. }
  50. ret.Data = map[string]interface{}{
  51. "proxy": maskedConf.System.NetworkProxy,
  52. }
  53. }
  54. func getChangelog(c *gin.Context) {
  55. ret := gulu.Ret.NewResult()
  56. defer c.JSON(http.StatusOK, ret)
  57. data := map[string]interface{}{"show": false, "html": ""}
  58. ret.Data = data
  59. changelogsDir := filepath.Join(util.WorkingDir, "changelogs")
  60. if !gulu.File.IsDir(changelogsDir) {
  61. return
  62. }
  63. if !model.Conf.ShowChangelog {
  64. return
  65. }
  66. changelogPath := filepath.Join(changelogsDir, "v"+util.Ver, "v"+util.Ver+"_"+model.Conf.Lang+".md")
  67. if !gulu.File.IsExist(changelogPath) {
  68. changelogPath = filepath.Join(changelogsDir, "v"+util.Ver, "v"+util.Ver+".md")
  69. if !gulu.File.IsExist(changelogPath) {
  70. logging.LogErrorf("changelog not found: %s", changelogPath)
  71. return
  72. }
  73. }
  74. contentData, err := os.ReadFile(changelogPath)
  75. if err != nil {
  76. logging.LogErrorf("read changelog failed: %s", err)
  77. return
  78. }
  79. model.Conf.ShowChangelog = false
  80. luteEngine := lute.New()
  81. htmlContent := luteEngine.MarkdownStr("", string(contentData))
  82. htmlContent = util.LinkTarget(htmlContent, "")
  83. data["show"] = true
  84. data["html"] = htmlContent
  85. ret.Data = data
  86. }
  87. func getEmojiConf(c *gin.Context) {
  88. ret := gulu.Ret.NewResult()
  89. defer c.JSON(http.StatusOK, ret)
  90. builtConfPath := filepath.Join(util.AppearancePath, "emojis", "conf.json")
  91. data, err := os.ReadFile(builtConfPath)
  92. if err != nil {
  93. logging.LogErrorf("read emojis conf.json failed: %s", err)
  94. ret.Code = -1
  95. ret.Msg = err.Error()
  96. return
  97. }
  98. var conf []map[string]interface{}
  99. if err = gulu.JSON.UnmarshalJSON(data, &conf); err != nil {
  100. logging.LogErrorf("unmarshal emojis conf.json failed: %s", err)
  101. ret.Code = -1
  102. ret.Msg = err.Error()
  103. return
  104. }
  105. customConfDir := filepath.Join(util.DataDir, "emojis")
  106. custom := map[string]interface{}{
  107. "id": "custom",
  108. "title": "Custom",
  109. "title_zh_cn": "自定义",
  110. "title_ja_jp": "カスタム",
  111. }
  112. items := []map[string]interface{}{}
  113. custom["items"] = items
  114. if gulu.File.IsDir(customConfDir) {
  115. model.CustomEmojis = sync.Map{}
  116. customEmojis, err := os.ReadDir(customConfDir)
  117. if err != nil {
  118. logging.LogErrorf("read custom emojis failed: %s", err)
  119. } else {
  120. for _, customEmoji := range customEmojis {
  121. name := customEmoji.Name()
  122. if strings.HasPrefix(name, ".") {
  123. continue
  124. }
  125. if customEmoji.IsDir() {
  126. // 子级
  127. subCustomEmojis, err := os.ReadDir(filepath.Join(customConfDir, name))
  128. if err != nil {
  129. logging.LogErrorf("read custom emojis failed: %s", err)
  130. continue
  131. }
  132. for _, subCustomEmoji := range subCustomEmojis {
  133. if subCustomEmoji.IsDir() {
  134. continue
  135. }
  136. name = subCustomEmoji.Name()
  137. if strings.HasPrefix(name, ".") {
  138. continue
  139. }
  140. addCustomEmoji(customEmoji.Name()+"/"+name, &items)
  141. }
  142. continue
  143. }
  144. addCustomEmoji(name, &items)
  145. }
  146. }
  147. }
  148. custom["items"] = items
  149. conf = append([]map[string]interface{}{custom}, conf...)
  150. ret.Data = conf
  151. return
  152. }
  153. func addCustomEmoji(name string, items *[]map[string]interface{}) {
  154. ext := filepath.Ext(name)
  155. nameWithoutExt := strings.TrimSuffix(name, ext)
  156. emoji := map[string]interface{}{
  157. "unicode": name,
  158. "description": nameWithoutExt,
  159. "description_zh_cn": nameWithoutExt,
  160. "description_ja_jp": nameWithoutExt,
  161. "keywords": nameWithoutExt,
  162. }
  163. *items = append(*items, emoji)
  164. imgSrc := "/emojis/" + name
  165. model.CustomEmojis.Store(nameWithoutExt, imgSrc)
  166. }
  167. func checkUpdate(c *gin.Context) {
  168. ret := gulu.Ret.NewResult()
  169. defer c.JSON(http.StatusOK, ret)
  170. arg, ok := util.JsonArg(c, ret)
  171. if !ok {
  172. return
  173. }
  174. showMsg := arg["showMsg"].(bool)
  175. model.CheckUpdate(showMsg)
  176. }
  177. func exportLog(c *gin.Context) {
  178. ret := gulu.Ret.NewResult()
  179. defer c.JSON(http.StatusOK, ret)
  180. zipPath := model.ExportSystemLog()
  181. ret.Data = map[string]interface{}{
  182. "zip": zipPath,
  183. }
  184. }
  185. func exportConf(c *gin.Context) {
  186. ret := gulu.Ret.NewResult()
  187. defer c.JSON(http.StatusOK, ret)
  188. logging.LogInfof("exporting conf...")
  189. name := "siyuan-conf-" + time.Now().Format("20060102150405") + ".json"
  190. tmpDir := filepath.Join(util.TempDir, "export")
  191. if err := os.MkdirAll(tmpDir, 0755); err != nil {
  192. logging.LogErrorf("export conf failed: %s", err)
  193. ret.Code = -1
  194. ret.Msg = err.Error()
  195. return
  196. }
  197. clonedConf := &model.AppConf{}
  198. if err := copier.CopyWithOption(clonedConf, model.Conf, copier.Option{IgnoreEmpty: false, DeepCopy: true}); err != nil {
  199. logging.LogErrorf("export conf failed: %s", err)
  200. ret.Code = -1
  201. ret.Msg = err.Error()
  202. return
  203. }
  204. if nil != clonedConf.Appearance {
  205. clonedConf.Appearance.DarkThemes = nil
  206. clonedConf.Appearance.LightThemes = nil
  207. clonedConf.Appearance.Icons = nil
  208. }
  209. if nil != clonedConf.Editor {
  210. clonedConf.Editor.Emoji = []string{}
  211. }
  212. if nil != clonedConf.Export {
  213. clonedConf.Export.PandocBin = ""
  214. }
  215. clonedConf.UserData = ""
  216. clonedConf.Account = nil
  217. clonedConf.AccessAuthCode = ""
  218. if nil != clonedConf.System {
  219. clonedConf.System.ID = ""
  220. clonedConf.System.Name = ""
  221. clonedConf.System.OSPlatform = ""
  222. clonedConf.System.Container = ""
  223. clonedConf.System.IsMicrosoftStore = false
  224. clonedConf.System.IsInsider = false
  225. }
  226. clonedConf.Sync = nil
  227. clonedConf.Stat = nil
  228. clonedConf.Api = nil
  229. clonedConf.Repo = nil
  230. clonedConf.Publish = nil
  231. clonedConf.CloudRegion = 0
  232. clonedConf.DataIndexState = 0
  233. data, err := gulu.JSON.MarshalIndentJSON(clonedConf, "", " ")
  234. if err != nil {
  235. logging.LogErrorf("export conf failed: %s", err)
  236. ret.Code = -1
  237. ret.Msg = err.Error()
  238. return
  239. }
  240. tmp := filepath.Join(tmpDir, name)
  241. if err = os.WriteFile(tmp, data, 0644); err != nil {
  242. logging.LogErrorf("export conf failed: %s", err)
  243. ret.Code = -1
  244. ret.Msg = err.Error()
  245. return
  246. }
  247. zipFile, err := gulu.Zip.Create(tmp + ".zip")
  248. if err != nil {
  249. logging.LogErrorf("export conf failed: %s", err)
  250. ret.Code = -1
  251. ret.Msg = err.Error()
  252. return
  253. }
  254. if err = zipFile.AddEntry(name, tmp); err != nil {
  255. logging.LogErrorf("export conf failed: %s", err)
  256. ret.Code = -1
  257. ret.Msg = err.Error()
  258. return
  259. }
  260. if err = zipFile.Close(); err != nil {
  261. logging.LogErrorf("export conf failed: %s", err)
  262. ret.Code = -1
  263. ret.Msg = err.Error()
  264. return
  265. }
  266. logging.LogInfof("exported conf")
  267. zipPath := "/export/" + name + ".zip"
  268. ret.Data = map[string]interface{}{
  269. "name": name,
  270. "zip": zipPath,
  271. }
  272. }
  273. func importConf(c *gin.Context) {
  274. ret := gulu.Ret.NewResult()
  275. defer c.JSON(200, ret)
  276. logging.LogInfof("importing conf...")
  277. form, err := c.MultipartForm()
  278. if err != nil {
  279. logging.LogErrorf("read upload file failed: %s", err)
  280. ret.Code = -1
  281. ret.Msg = err.Error()
  282. return
  283. }
  284. files := form.File["file"]
  285. if 1 != len(files) {
  286. ret.Code = -1
  287. ret.Msg = "invalid upload file"
  288. return
  289. }
  290. f := files[0]
  291. fh, err := f.Open()
  292. if err != nil {
  293. logging.LogErrorf("read upload file failed: %s", err)
  294. ret.Code = -1
  295. ret.Msg = err.Error()
  296. return
  297. }
  298. data, err := io.ReadAll(fh)
  299. fh.Close()
  300. if err != nil {
  301. logging.LogErrorf("read upload file failed: %s", err)
  302. ret.Code = -1
  303. ret.Msg = err.Error()
  304. return
  305. }
  306. importDir := filepath.Join(util.TempDir, "import")
  307. if err = os.MkdirAll(importDir, 0755); err != nil {
  308. logging.LogErrorf("import conf failed: %s", err)
  309. ret.Code = -1
  310. ret.Msg = err.Error()
  311. return
  312. }
  313. tmp := filepath.Join(importDir, f.Filename)
  314. if err = os.WriteFile(tmp, data, 0644); err != nil {
  315. logging.LogErrorf("import conf failed: %s", err)
  316. ret.Code = -1
  317. ret.Msg = err.Error()
  318. return
  319. }
  320. tmpDir := filepath.Join(importDir, "conf")
  321. if err = gulu.Zip.Unzip(tmp, tmpDir); err != nil {
  322. logging.LogErrorf("import conf failed: %s", err)
  323. ret.Code = -1
  324. ret.Msg = err.Error()
  325. return
  326. }
  327. entries, err := os.ReadDir(tmpDir)
  328. if err != nil {
  329. logging.LogErrorf("import conf failed: %s", err)
  330. ret.Code = -1
  331. ret.Msg = err.Error()
  332. return
  333. }
  334. if 1 != len(entries) {
  335. logging.LogErrorf("invalid conf package")
  336. ret.Code = -1
  337. ret.Msg = "invalid conf package"
  338. return
  339. }
  340. tmp = filepath.Join(tmpDir, entries[0].Name())
  341. data, err = os.ReadFile(tmp)
  342. if err != nil {
  343. logging.LogErrorf("import conf failed: %s", err)
  344. ret.Code = -1
  345. ret.Msg = err.Error()
  346. return
  347. }
  348. importedConf := model.NewAppConf()
  349. if err = gulu.JSON.UnmarshalJSON(data, importedConf); err != nil {
  350. logging.LogErrorf("import conf failed: %s", err)
  351. ret.Code = -1
  352. ret.Msg = err.Error()
  353. return
  354. }
  355. if err = copier.CopyWithOption(model.Conf, importedConf, copier.Option{IgnoreEmpty: true, DeepCopy: true}); err != nil {
  356. logging.LogErrorf("import conf failed: %s", err)
  357. ret.Code = -1
  358. ret.Msg = err.Error()
  359. return
  360. }
  361. logging.LogInfof("imported conf")
  362. }
  363. func getConf(c *gin.Context) {
  364. ret := gulu.Ret.NewResult()
  365. defer c.JSON(http.StatusOK, ret)
  366. maskedConf, err := model.GetMaskedConf()
  367. if err != nil {
  368. ret.Code = -1
  369. ret.Msg = "get conf failed: " + err.Error()
  370. return
  371. }
  372. if !maskedConf.Sync.Enabled || (0 == maskedConf.Sync.Provider && !model.IsSubscriber()) {
  373. maskedConf.Sync.Stat = model.Conf.Language(53)
  374. }
  375. // REF: https://github.com/siyuan-note/siyuan/issues/11364
  376. role := model.GetGinContextRole(c)
  377. isPublish := model.IsReadOnlyRole(role)
  378. if isPublish {
  379. maskedConf.ReadOnly = true
  380. }
  381. if !model.IsValidRole(role, []model.Role{
  382. model.RoleAdministrator,
  383. }) {
  384. model.HideConfSecret(maskedConf)
  385. }
  386. ret.Data = map[string]interface{}{
  387. "conf": maskedConf,
  388. "start": !util.IsUILoaded,
  389. "isPublish": isPublish,
  390. }
  391. }
  392. func setUILayout(c *gin.Context) {
  393. ret := gulu.Ret.NewResult()
  394. defer c.JSON(http.StatusOK, ret)
  395. if util.ReadOnly {
  396. return
  397. }
  398. arg, ok := util.JsonArg(c, ret)
  399. if !ok {
  400. return
  401. }
  402. param, err := gulu.JSON.MarshalJSON(arg["layout"])
  403. if err != nil {
  404. ret.Code = -1
  405. ret.Msg = err.Error()
  406. return
  407. }
  408. uiLayout := &conf.UILayout{}
  409. if err = gulu.JSON.UnmarshalJSON(param, uiLayout); err != nil {
  410. ret.Code = -1
  411. ret.Msg = err.Error()
  412. return
  413. }
  414. model.Conf.SetUILayout(uiLayout)
  415. model.Conf.Save()
  416. }
  417. func setAPIToken(c *gin.Context) {
  418. ret := gulu.Ret.NewResult()
  419. defer c.JSON(http.StatusOK, ret)
  420. arg, ok := util.JsonArg(c, ret)
  421. if !ok {
  422. return
  423. }
  424. token := arg["token"].(string)
  425. model.Conf.Api.Token = token
  426. model.Conf.Save()
  427. }
  428. func setAccessAuthCode(c *gin.Context) {
  429. ret := gulu.Ret.NewResult()
  430. defer c.JSON(http.StatusOK, ret)
  431. arg, ok := util.JsonArg(c, ret)
  432. if !ok {
  433. return
  434. }
  435. aac := arg["accessAuthCode"].(string)
  436. if model.MaskedAccessAuthCode == aac {
  437. aac = model.Conf.AccessAuthCode
  438. }
  439. model.Conf.AccessAuthCode = aac
  440. model.Conf.Save()
  441. session := util.GetSession(c)
  442. workspaceSession := util.GetWorkspaceSession(session)
  443. workspaceSession.AccessAuthCode = aac
  444. session.Save(c)
  445. go func() {
  446. time.Sleep(200 * time.Millisecond)
  447. util.ReloadUI()
  448. }()
  449. return
  450. }
  451. func setFollowSystemLockScreen(c *gin.Context) {
  452. ret := gulu.Ret.NewResult()
  453. defer c.JSON(http.StatusOK, ret)
  454. arg, ok := util.JsonArg(c, ret)
  455. if !ok {
  456. return
  457. }
  458. lockScreenMode := int(arg["lockScreenMode"].(float64))
  459. model.Conf.System.LockScreenMode = lockScreenMode
  460. model.Conf.Save()
  461. return
  462. }
  463. func getSysFonts(c *gin.Context) {
  464. ret := gulu.Ret.NewResult()
  465. defer c.JSON(http.StatusOK, ret)
  466. ret.Data = util.GetSysFonts(model.Conf.Lang)
  467. }
  468. func version(c *gin.Context) {
  469. ret := gulu.Ret.NewResult()
  470. defer c.JSON(http.StatusOK, ret)
  471. ret.Data = util.Ver
  472. }
  473. func currentTime(c *gin.Context) {
  474. ret := gulu.Ret.NewResult()
  475. defer c.JSON(http.StatusOK, ret)
  476. ret.Data = util.CurrentTimeMillis()
  477. }
  478. func bootProgress(c *gin.Context) {
  479. ret := gulu.Ret.NewResult()
  480. defer c.JSON(http.StatusOK, ret)
  481. progress, details := util.GetBootProgressDetails()
  482. ret.Data = map[string]interface{}{"progress": progress, "details": details}
  483. }
  484. func setAppearanceMode(c *gin.Context) {
  485. ret := gulu.Ret.NewResult()
  486. defer c.JSON(http.StatusOK, ret)
  487. arg, ok := util.JsonArg(c, ret)
  488. if !ok {
  489. return
  490. }
  491. mode := int(arg["mode"].(float64))
  492. model.Conf.Appearance.Mode = mode
  493. if 0 == mode {
  494. model.Conf.Appearance.ThemeJS = gulu.File.IsExist(filepath.Join(util.ThemesPath, model.Conf.Appearance.ThemeLight, "theme.js"))
  495. } else {
  496. model.Conf.Appearance.ThemeJS = gulu.File.IsExist(filepath.Join(util.ThemesPath, model.Conf.Appearance.ThemeDark, "theme.js"))
  497. }
  498. model.Conf.Save()
  499. ret.Data = map[string]interface{}{
  500. "appearance": model.Conf.Appearance,
  501. }
  502. }
  503. func setNetworkServe(c *gin.Context) {
  504. ret := gulu.Ret.NewResult()
  505. defer c.JSON(http.StatusOK, ret)
  506. arg, ok := util.JsonArg(c, ret)
  507. if !ok {
  508. return
  509. }
  510. networkServe := arg["networkServe"].(bool)
  511. model.Conf.System.NetworkServe = networkServe
  512. model.Conf.Save()
  513. util.PushMsg(model.Conf.Language(42), 1000*15)
  514. time.Sleep(time.Second * 3)
  515. }
  516. func setGoogleAnalytics(c *gin.Context) {
  517. ret := gulu.Ret.NewResult()
  518. defer c.JSON(http.StatusOK, ret)
  519. arg, ok := util.JsonArg(c, ret)
  520. if !ok {
  521. return
  522. }
  523. googleAnalytics := arg["googleAnalytics"].(bool)
  524. model.Conf.System.DisableGoogleAnalytics = !googleAnalytics
  525. model.Conf.Save()
  526. }
  527. func setUploadErrLog(c *gin.Context) {
  528. ret := gulu.Ret.NewResult()
  529. defer c.JSON(http.StatusOK, ret)
  530. arg, ok := util.JsonArg(c, ret)
  531. if !ok {
  532. return
  533. }
  534. uploadErrLog := arg["uploadErrLog"].(bool)
  535. model.Conf.System.UploadErrLog = uploadErrLog
  536. model.Conf.Save()
  537. util.PushMsg(model.Conf.Language(42), 1000*15)
  538. time.Sleep(time.Second * 3)
  539. }
  540. func setAutoLaunch(c *gin.Context) {
  541. ret := gulu.Ret.NewResult()
  542. defer c.JSON(http.StatusOK, ret)
  543. arg, ok := util.JsonArg(c, ret)
  544. if !ok {
  545. return
  546. }
  547. autoLaunch := int(arg["autoLaunch"].(float64))
  548. model.Conf.System.AutoLaunch2 = autoLaunch
  549. model.Conf.Save()
  550. }
  551. func setDownloadInstallPkg(c *gin.Context) {
  552. ret := gulu.Ret.NewResult()
  553. defer c.JSON(http.StatusOK, ret)
  554. arg, ok := util.JsonArg(c, ret)
  555. if !ok {
  556. return
  557. }
  558. downloadInstallPkg := arg["downloadInstallPkg"].(bool)
  559. model.Conf.System.DownloadInstallPkg = downloadInstallPkg
  560. model.Conf.Save()
  561. }
  562. func setNetworkProxy(c *gin.Context) {
  563. ret := gulu.Ret.NewResult()
  564. defer c.JSON(http.StatusOK, ret)
  565. arg, ok := util.JsonArg(c, ret)
  566. if !ok {
  567. return
  568. }
  569. scheme := arg["scheme"].(string)
  570. host := arg["host"].(string)
  571. port := arg["port"].(string)
  572. model.Conf.System.NetworkProxy = &conf.NetworkProxy{
  573. Scheme: scheme,
  574. Host: host,
  575. Port: port,
  576. }
  577. model.Conf.Save()
  578. proxyURL := model.Conf.System.NetworkProxy.String()
  579. util.SetNetworkProxy(proxyURL)
  580. util.PushMsg(model.Conf.Language(102), 3000)
  581. }
  582. func addUIProcess(c *gin.Context) {
  583. pid := c.Query("pid")
  584. util.UIProcessIDs.Store(pid, true)
  585. }
  586. func exit(c *gin.Context) {
  587. ret := gulu.Ret.NewResult()
  588. defer c.JSON(http.StatusOK, ret)
  589. arg, ok := util.JsonArg(c, ret)
  590. if !ok {
  591. return
  592. }
  593. forceArg := arg["force"]
  594. var force bool
  595. if nil != forceArg {
  596. force = forceArg.(bool)
  597. }
  598. execInstallPkgArg := arg["execInstallPkg"] // 0:默认检查新版本,1:不执行新版本安装,2:执行新版本安装
  599. execInstallPkg := 0
  600. if nil != execInstallPkgArg {
  601. execInstallPkg = int(execInstallPkgArg.(float64))
  602. }
  603. exitCode := model.Close(force, true, execInstallPkg)
  604. ret.Code = exitCode
  605. switch exitCode {
  606. case 0:
  607. case 1: // 同步执行失败
  608. ret.Msg = model.Conf.Language(96) + "<div class=\"fn__space\"></div><button class=\"b3-button b3-button--white\">" + model.Conf.Language(97) + "</button>"
  609. ret.Data = map[string]interface{}{"closeTimeout": 0}
  610. case 2: // 提示新安装包
  611. ret.Msg = model.Conf.Language(61)
  612. ret.Data = map[string]interface{}{"closeTimeout": 0}
  613. }
  614. }