system.go 17 KB

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