file.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. package v1
  2. import (
  3. "bufio"
  4. "encoding/csv"
  5. "fmt"
  6. "io"
  7. "io/ioutil"
  8. "net/http"
  9. url2 "net/url"
  10. "os"
  11. "path"
  12. "strconv"
  13. "strings"
  14. "github.com/IceWhaleTech/CasaOS/model"
  15. "github.com/IceWhaleTech/CasaOS/pkg/config"
  16. "github.com/IceWhaleTech/CasaOS/pkg/utils/file"
  17. oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
  18. "github.com/IceWhaleTech/CasaOS/service"
  19. "github.com/gin-gonic/gin"
  20. "github.com/spf13/afero"
  21. )
  22. func downloadReadFile(c *gin.Context) {
  23. //http下载地址 csv
  24. csvFileUrl := c.PostForm("file_name")
  25. res, err := http.Get(csvFileUrl)
  26. if err != nil {
  27. c.String(400, err.Error())
  28. return
  29. }
  30. defer res.Body.Close()
  31. //读取csv
  32. reader := csv.NewReader(bufio.NewReader(res.Body))
  33. for {
  34. line, err := reader.Read()
  35. if err == io.EOF {
  36. break
  37. } else if err != nil {
  38. c.String(400, err.Error())
  39. return
  40. }
  41. //line 就是每一行的内容
  42. fmt.Println(line)
  43. //line[0] 就是第几列
  44. fmt.Println(line[0])
  45. }
  46. }
  47. func downloadWriteFile(c *gin.Context) {
  48. //写文件
  49. var filename = "./output1.csv"
  50. file, err := os.Create(filename) //创建文件
  51. if err != nil {
  52. c.String(400, err.Error())
  53. return
  54. }
  55. buf := bufio.NewWriter(file) //创建新的 Writer 对象
  56. buf.WriteString("test")
  57. buf.Flush()
  58. defer file.Close()
  59. //返回文件流
  60. c.File(filename)
  61. }
  62. // @Summary 读取文件
  63. // @Produce application/json
  64. // @Accept application/json
  65. // @Tags file
  66. // @Security ApiKeyAuth
  67. // @Param path query string true "路径"
  68. // @Success 200 {string} string "ok"
  69. // @Router /file/read [get]
  70. func GetFilerContent(c *gin.Context) {
  71. filePath := c.Query("path")
  72. if len(filePath) == 0 {
  73. c.JSON(http.StatusOK, model.Result{
  74. Success: oasis_err2.INVALID_PARAMS,
  75. Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS),
  76. })
  77. return
  78. }
  79. if !file.Exists(filePath) {
  80. c.JSON(http.StatusOK, model.Result{
  81. Success: oasis_err2.FILE_DOES_NOT_EXIST,
  82. Message: oasis_err2.GetMsg(oasis_err2.FILE_DOES_NOT_EXIST),
  83. })
  84. return
  85. }
  86. //文件读取任务是将文件内容读取到内存中。
  87. info, err := ioutil.ReadFile(filePath)
  88. if err != nil {
  89. c.JSON(http.StatusOK, model.Result{
  90. Success: oasis_err2.FILE_READ_ERROR,
  91. Message: oasis_err2.GetMsg(oasis_err2.FILE_READ_ERROR),
  92. Data: err.Error(),
  93. })
  94. return
  95. }
  96. result := string(info)
  97. //返回结果
  98. c.JSON(http.StatusOK, model.Result{
  99. Success: oasis_err2.SUCCESS,
  100. Message: oasis_err2.GetMsg(oasis_err2.SUCCESS),
  101. Data: result,
  102. })
  103. }
  104. func GetLocalFile(c *gin.Context) {
  105. path := c.Query("path")
  106. if len(path) == 0 {
  107. c.JSON(http.StatusOK, model.Result{
  108. Success: oasis_err2.INVALID_PARAMS,
  109. Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS),
  110. })
  111. return
  112. }
  113. if !file.Exists(path) {
  114. c.JSON(http.StatusOK, model.Result{
  115. Success: oasis_err2.FILE_DOES_NOT_EXIST,
  116. Message: oasis_err2.GetMsg(oasis_err2.FILE_DOES_NOT_EXIST),
  117. })
  118. return
  119. }
  120. c.File(path)
  121. return
  122. }
  123. // @Summary download
  124. // @Produce application/json
  125. // @Accept application/json
  126. // @Tags file
  127. // @Security ApiKeyAuth
  128. // @Param path query string true "path of file"
  129. // @Success 200 {string} string "ok"
  130. // @Router /file/download [get]
  131. func GetDownloadFile(c *gin.Context) {
  132. filePath := c.Query("path")
  133. if len(filePath) == 0 {
  134. c.JSON(http.StatusOK, model.Result{
  135. Success: oasis_err2.INVALID_PARAMS,
  136. Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS),
  137. })
  138. return
  139. }
  140. if !file.Exists(filePath) {
  141. c.JSON(http.StatusOK, model.Result{
  142. Success: oasis_err2.FILE_DOES_NOT_EXIST,
  143. Message: oasis_err2.GetMsg(oasis_err2.FILE_DOES_NOT_EXIST),
  144. })
  145. return
  146. }
  147. //打开文件
  148. fileTmp, _ := os.Open(filePath)
  149. defer fileTmp.Close()
  150. //获取文件的名称
  151. fileName := path.Base(filePath)
  152. c.Header("Content-Type", "application/octet-stream")
  153. c.Header("Content-Disposition", "attachment; filename*=utf-8''"+url2.PathEscape(fileName))
  154. c.Header("Content-Transfer-Encoding", "binary")
  155. c.Header("Cache-Control", "no-cache")
  156. c.File(filePath)
  157. }
  158. // @Summary download
  159. // @Produce application/json
  160. // @Accept application/json
  161. // @Tags file
  162. // @Security ApiKeyAuth
  163. // @Param path query string true "path of file"
  164. // @Success 200 {string} string "ok"
  165. // @Router /file/new/download [get]
  166. func GetFileDownloadNew(c *gin.Context) {
  167. filePath := c.Query("path")
  168. if len(filePath) == 0 {
  169. c.JSON(http.StatusOK, model.Result{
  170. Success: oasis_err2.INVALID_PARAMS,
  171. Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS),
  172. })
  173. return
  174. }
  175. if !file.Exists(filePath) {
  176. c.JSON(http.StatusOK, model.Result{
  177. Success: oasis_err2.FILE_DOES_NOT_EXIST,
  178. Message: oasis_err2.GetMsg(oasis_err2.FILE_DOES_NOT_EXIST),
  179. })
  180. return
  181. }
  182. //打开文件
  183. fileStat, _ := os.Stat(filePath)
  184. var AppFs = afero.NewOsFs()
  185. fileT, _ := AppFs.Open(filePath)
  186. //fileTmp, _ := os.Open(filePath)
  187. //defer fileTmp.Close()
  188. //获取文件的名称
  189. //fileName := path.Base(filePath)
  190. //c.Header("Content-Disposition", "attachment; filename*=utf-8''"+url2.PathEscape(fileName))
  191. //在线
  192. //c.Header("Content-Disposition", "inline")
  193. // extraHeaders := map[string]string{
  194. // "Content-Disposition": `attachment; filename="` + url2.PathEscape(fileName) + `"`,
  195. // }
  196. //c.Header("Cache-Control", "private")
  197. //c.Header("Content-Type", "application/octet-stream")
  198. http.ServeContent(c.Writer, c.Request, fileStat.Name(), fileStat.ModTime(), fileT)
  199. }
  200. // @Summary 获取目录列表
  201. // @Produce application/json
  202. // @Accept application/json
  203. // @Tags file
  204. // @Security ApiKeyAuth
  205. // @Param path query string false "路径"
  206. // @Success 200 {string} string "ok"
  207. // @Router /file/dirpath [get]
  208. func DirPath(c *gin.Context) {
  209. path := c.DefaultQuery("path", "")
  210. info := service.MyService.ZiMa().GetDirPath(path)
  211. if path == "/DATA/AppData" {
  212. list := service.MyService.Docker().DockerContainerList()
  213. apps := make(map[string]string, len(list))
  214. for _, v := range list {
  215. apps[strings.ReplaceAll(v.Names[0], "/", "")] = strings.ReplaceAll(v.Names[0], "/", "")
  216. }
  217. for i := 0; i < len(info); i++ {
  218. if v, ok := apps[info[i].Name]; ok {
  219. info[i].Label = v
  220. info[i].Type = "application"
  221. }
  222. }
  223. } else if path == "/DATA" {
  224. disk := make(map[string]string)
  225. lsblk := service.MyService.Disk().LSBLK(true)
  226. for _, v := range lsblk {
  227. if len(v.Children) > 0 {
  228. t := v.Tran
  229. for _, c := range v.Children {
  230. if len(c.Children) > 0 {
  231. for _, gc := range c.Children {
  232. if len(gc.MountPoint) > 0 {
  233. disk[gc.MountPoint] = t
  234. }
  235. }
  236. }
  237. if len(c.MountPoint) > 0 {
  238. disk[c.MountPoint] = t
  239. }
  240. }
  241. }
  242. }
  243. for i := 0; i < len(info); i++ {
  244. if v, ok := disk[info[i].Path]; ok {
  245. info[i].Type = v
  246. }
  247. }
  248. }
  249. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: info})
  250. }
  251. // @Summary rename file or dir
  252. // @Produce application/json
  253. // @Accept application/json
  254. // @Tags file
  255. // @Security ApiKeyAuth
  256. // @Param oldpath formData string true "path of old"
  257. // @Param newpath formData string true "path of new"
  258. // @Success 200 {string} string "ok"
  259. // @Router /file/rename [put]
  260. func RenamePath(c *gin.Context) {
  261. op := c.PostForm("oldpath")
  262. np := c.PostForm("newpath")
  263. if len(op) == 0 || len(np) == 0 {
  264. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
  265. return
  266. }
  267. success, err := service.MyService.ZiMa().RenameFile(op, np)
  268. c.JSON(http.StatusOK, model.Result{Success: success, Message: oasis_err2.GetMsg(success), Data: err})
  269. }
  270. // @Summary create folder
  271. // @Produce application/json
  272. // @Accept multipart/form-data
  273. // @Tags file
  274. // @Security ApiKeyAuth
  275. // @Param path formData string true "path of folder"
  276. // @Success 200 {string} string "ok"
  277. // @Router /file/mkdir [post]
  278. func MkdirAll(c *gin.Context) {
  279. path := c.PostForm("path")
  280. var code int
  281. if len(path) == 0 {
  282. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
  283. return
  284. }
  285. code, _ = service.MyService.ZiMa().MkdirAll(path)
  286. c.JSON(http.StatusOK, model.Result{Success: code, Message: oasis_err2.GetMsg(code)})
  287. }
  288. // @Summary create file
  289. // @Produce application/json
  290. // @Accept multipart/form-data
  291. // @Tags file
  292. // @Security ApiKeyAuth
  293. // @Param path formData string false "路径"
  294. // @Success 200 {string} string "ok"
  295. // @Router /file/create [post]
  296. func PostCreateFile(c *gin.Context) {
  297. path := c.PostForm("path")
  298. var code int
  299. if len(path) == 0 {
  300. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
  301. return
  302. }
  303. code, _ = service.MyService.ZiMa().CreateFile(path)
  304. c.JSON(http.StatusOK, model.Result{Success: code, Message: oasis_err2.GetMsg(code)})
  305. }
  306. // @Summary upload file
  307. // @Produce application/json
  308. // @Accept multipart/form-data
  309. // @Tags file
  310. // @Security ApiKeyAuth
  311. // @Param path formData string false "file path"
  312. // @Param file formData file true "file"
  313. // @Success 200 {string} string "ok"
  314. // @Router /file/upload [get]
  315. func GetFileUpload(c *gin.Context) {
  316. relative := c.Query("relativePath")
  317. fileName := c.Query("filename")
  318. chunkNumber := c.Query("chunkNumber")
  319. totalChunks, _ := strconv.Atoi(c.DefaultQuery("totalChunks", "0"))
  320. path := c.Query("path")
  321. dirPath := ""
  322. hash := file.GetHashByContent([]byte(fileName))
  323. tempDir := config.AppInfo.RootPath + "/temp/" + hash + strconv.Itoa(totalChunks) + "/"
  324. if fileName != relative {
  325. dirPath = strings.TrimSuffix(relative, fileName)
  326. tempDir += dirPath
  327. file.MkDir(path + "/" + dirPath)
  328. }
  329. tempDir += chunkNumber
  330. if !file.CheckNotExist(tempDir) {
  331. c.JSON(200, model.Result{Success: 200, Message: oasis_err2.GetMsg(oasis_err2.FILE_ALREADY_EXISTS)})
  332. return
  333. }
  334. c.JSON(204, model.Result{Success: 204, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
  335. }
  336. // @Summary upload file
  337. // @Produce application/json
  338. // @Accept multipart/form-data
  339. // @Tags file
  340. // @Security ApiKeyAuth
  341. // @Param path formData string false "file path"
  342. // @Param file formData file true "file"
  343. // @Success 200 {string} string "ok"
  344. // @Router /file/upload [post]
  345. func PostFileUpload(c *gin.Context) {
  346. f, _, _ := c.Request.FormFile("file")
  347. relative := c.PostForm("relativePath")
  348. fileName := c.PostForm("filename")
  349. totalChunks, _ := strconv.Atoi(c.DefaultPostForm("totalChunks", "0"))
  350. chunkNumber := c.PostForm("chunkNumber")
  351. dirPath := ""
  352. path := c.PostForm("path")
  353. hash := file.GetHashByContent([]byte(fileName))
  354. if len(path) == 0 {
  355. c.JSON(oasis_err2.INVALID_PARAMS, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
  356. return
  357. }
  358. tempDir := config.AppInfo.RootPath + "/temp/" + hash + strconv.Itoa(totalChunks) + "/"
  359. if fileName != relative {
  360. dirPath = strings.TrimSuffix(relative, fileName)
  361. tempDir += dirPath
  362. file.MkDir(path + "/" + dirPath)
  363. }
  364. path += "/" + relative
  365. if !file.CheckNotExist(tempDir + chunkNumber) {
  366. file.RMDir(tempDir + chunkNumber)
  367. }
  368. if totalChunks > 1 {
  369. file.IsNotExistMkDir(tempDir)
  370. out, _ := os.OpenFile(tempDir+chunkNumber, os.O_WRONLY|os.O_CREATE, 0644)
  371. defer out.Close()
  372. _, err := io.Copy(out, f)
  373. if err != nil {
  374. c.JSON(oasis_err2.ERROR, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR), Data: err.Error()})
  375. return
  376. }
  377. } else {
  378. out, _ := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0644)
  379. defer out.Close()
  380. _, err := io.Copy(out, f)
  381. if err != nil {
  382. c.JSON(oasis_err2.ERROR, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR), Data: err.Error()})
  383. return
  384. }
  385. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
  386. return
  387. }
  388. fileNum, err := ioutil.ReadDir(tempDir)
  389. if err != nil {
  390. c.JSON(oasis_err2.ERROR, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR), Data: err.Error()})
  391. return
  392. }
  393. if totalChunks == len(fileNum) {
  394. file.SpliceFiles(tempDir, path, totalChunks, 1)
  395. file.RMDir(tempDir)
  396. }
  397. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
  398. }
  399. // @Summary copy or move file
  400. // @Produce application/json
  401. // @Accept multipart/form-data
  402. // @Tags file
  403. // @Security ApiKeyAuth
  404. // @Param from formData string true "from path"
  405. // @Param to formData string true "to path"
  406. // @Param type formData string true "action" Enums(move,copy)
  407. // @Success 200 {string} string "ok"
  408. // @Router /file/operate [post]
  409. func PostOperateFileOrDir(c *gin.Context) {
  410. from := c.PostForm("from")
  411. to := c.PostForm("to")
  412. t := c.PostForm("type")
  413. if len(from) == 0 || len(t) == 0 || len(to) == 0 {
  414. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
  415. return
  416. }
  417. if t == "move" {
  418. lastPath := from[strings.LastIndex(from, "/")+1:]
  419. if !file.CheckNotExist(to + "/" + lastPath) {
  420. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.FILE_OR_DIR_EXISTS, Message: oasis_err2.GetMsg(oasis_err2.FILE_ALREADY_EXISTS)})
  421. return
  422. }
  423. err := os.Rename(from, to+"/"+lastPath)
  424. if err != nil {
  425. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR), Data: err.Error()})
  426. return
  427. }
  428. } else if t == "copy" {
  429. err := file.CopyDir(from, to)
  430. if err != nil {
  431. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR), Data: err.Error()})
  432. return
  433. }
  434. } else {
  435. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
  436. return
  437. }
  438. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
  439. }
  440. // @Summary delete file
  441. // @Produce application/json
  442. // @Accept multipart/form-data
  443. // @Tags file
  444. // @Security ApiKeyAuth
  445. // @Param path query string true "path"
  446. // @Success 200 {string} string "ok"
  447. // @Router /file/delete [delete]
  448. func DeleteFile(c *gin.Context) {
  449. path := c.Query("path")
  450. //err := os.Remove(path)
  451. err := os.RemoveAll(path)
  452. if err != nil {
  453. fmt.Println(err)
  454. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.FILE_DELETE_ERROR, Message: oasis_err2.GetMsg(oasis_err2.FILE_DELETE_ERROR), Data: err})
  455. return
  456. }
  457. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
  458. }
  459. // @Summary update file
  460. // @Produce application/json
  461. // @Accept multipart/form-data
  462. // @Tags file
  463. // @Security ApiKeyAuth
  464. // @Param path formData string true "path"
  465. // @Param content formData string true "content"
  466. // @Success 200 {string} string "ok"
  467. // @Router /file/update [put]
  468. func PutFileContent(c *gin.Context) {
  469. path := c.PostForm("path")
  470. content := c.PostForm("content")
  471. if !file.Exists(path) {
  472. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.FILE_ALREADY_EXISTS, Message: oasis_err2.GetMsg(oasis_err2.FILE_ALREADY_EXISTS)})
  473. return
  474. }
  475. //err := os.Remove(path)
  476. err := os.RemoveAll(path)
  477. if err != nil {
  478. fmt.Println(err)
  479. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.FILE_DELETE_ERROR, Message: oasis_err2.GetMsg(oasis_err2.FILE_DELETE_ERROR), Data: err})
  480. return
  481. }
  482. err = file.CreateFileAndWriteContent(path, content)
  483. if err != nil {
  484. fmt.Println(err)
  485. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR), Data: err})
  486. return
  487. }
  488. c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
  489. }
  490. // @Summary image thumbnail/original image
  491. // @Produce application/json
  492. // @Accept application/json
  493. // @Tags file
  494. // @Security ApiKeyAuth
  495. // @Param path query string true "path"
  496. // @Param type query string false "original,thumbnail" Enums(original,thumbnail)
  497. // @Success 200 {string} string "ok"
  498. // @Router /file/image [get]
  499. func GetFileImage(c *gin.Context) {
  500. t := c.Query("type")
  501. path := c.Query("path")
  502. if !file.Exists(path) {
  503. c.JSON(http.StatusInternalServerError, model.Result{Success: oasis_err2.FILE_ALREADY_EXISTS, Message: oasis_err2.GetMsg(oasis_err2.FILE_ALREADY_EXISTS)})
  504. return
  505. }
  506. if t == "thumbnail" {
  507. f, err := file.GetImage(path, 100, 0)
  508. if err != nil {
  509. c.JSON(http.StatusInternalServerError, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR), Data: err.Error()})
  510. return
  511. }
  512. c.Writer.WriteString(string(f))
  513. return
  514. }
  515. f, err := os.Open(path)
  516. if err != nil {
  517. c.JSON(http.StatusInternalServerError, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR), Data: err.Error()})
  518. return
  519. }
  520. defer f.Close()
  521. data, err := ioutil.ReadAll(f)
  522. if err != nil {
  523. c.JSON(http.StatusInternalServerError, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR), Data: err.Error()})
  524. return
  525. }
  526. c.Writer.WriteString(string(data))
  527. }