main.go 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  1. package main
  2. import (
  3. "crypto/md5"
  4. "encoding/base64"
  5. "encoding/hex"
  6. "fmt"
  7. "io"
  8. "log"
  9. "os"
  10. "path/filepath"
  11. "runtime/debug"
  12. "strings"
  13. "opennamu/route"
  14. "opennamu/route/tool"
  15. "net/http"
  16. "github.com/flosch/pongo2/v6"
  17. "github.com/gin-gonic/gin"
  18. jsoniter "github.com/json-iterator/go"
  19. )
  20. var json = jsoniter.ConfigCompatibleWithStandardLibrary
  21. func error_handler() gin.HandlerFunc {
  22. return func(c *gin.Context) {
  23. defer func() {
  24. if r := recover(); r != nil {
  25. err, ok := r.(error)
  26. if !ok {
  27. err = fmt.Errorf("%v", r)
  28. }
  29. stackTrace := debug.Stack()
  30. c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
  31. "response" : "error",
  32. "error" : err.Error(),
  33. "stack" : string(stackTrace),
  34. })
  35. }
  36. }()
  37. c.Next()
  38. }
  39. }
  40. func pongo_init() {
  41. pongo2.RegisterFilter("md5_replace", func(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
  42. h := md5.Sum([]byte(in.String()))
  43. return pongo2.AsValue(hex.EncodeToString(h[:])), nil
  44. })
  45. pongo2.RegisterFilter("load_lang", func(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
  46. db := tool.DB_connect()
  47. defer tool.DB_close(db)
  48. return pongo2.AsValue(tool.Get_language(db, in.String(), false)), nil
  49. })
  50. pongo2.RegisterFilter("cut_100", func(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
  51. s := in.String()
  52. if len(s) > 100 {
  53. s = s[:100]
  54. }
  55. return pongo2.AsValue(s), nil
  56. })
  57. }
  58. func main() {
  59. log.SetFlags(log.LstdFlags | log.Lshortfile)
  60. port := "3001"
  61. if len(os.Args) > 1 {
  62. port = os.Args[1]
  63. }
  64. var r *gin.Engine
  65. if len(os.Args) > 2 && os.Args[2] == "dev" {
  66. r = gin.Default()
  67. } else {
  68. gin.SetMode(gin.ReleaseMode)
  69. r = gin.New()
  70. }
  71. if len(os.Args) <= 3 || os.Args[3] != "api" {
  72. tool.IN_mod_OUT_mod(true)
  73. }
  74. r.Use(error_handler())
  75. pongo_init()
  76. tool.Main_init()
  77. r.GET("/api/user_info/:user_name", func(c *gin.Context) {
  78. route_data := route.Api_user_info(tool.Config{
  79. Other_set: "",
  80. IP: tool.Get_IP(c),
  81. Cookies: tool.Get_Cookies(c),
  82. Session: "",
  83. }, c.Param("user_name"))
  84. c.JSON(http.StatusOK, route_data)
  85. })
  86. r.GET("/api/recent_change", func(c *gin.Context) {
  87. route_data := route.Api_list_recent_change(tool.Config{
  88. Other_set: "",
  89. IP: tool.Get_IP(c),
  90. Cookies: tool.Get_Cookies(c),
  91. Session: "",
  92. }, "normal", "10", "1")
  93. in_data := route_data["data"].([][]string)
  94. c.JSON(http.StatusOK, in_data)
  95. })
  96. r.GET("/api/recent_change/:limit", func(c *gin.Context) {
  97. route_data := route.Api_list_recent_change(tool.Config{
  98. Other_set: "",
  99. IP: tool.Get_IP(c),
  100. Cookies: tool.Get_Cookies(c),
  101. Session: "",
  102. }, "normal", c.Param("limit"), "1")
  103. in_data := route_data["data"].([][]string)
  104. c.JSON(http.StatusOK, in_data)
  105. })
  106. r.GET("/api/recent_discuss", func(c *gin.Context) {
  107. route_data := route.Api_list_recent_discuss(tool.Config{
  108. Other_set: "",
  109. IP: tool.Get_IP(c),
  110. Cookies: tool.Get_Cookies(c),
  111. Session: "",
  112. }, "10", "1", "")
  113. in_data := route_data["data"].([][]string)
  114. c.JSON(http.StatusOK, in_data)
  115. })
  116. r.GET("/api/recent_discuss/:limit", func(c *gin.Context) {
  117. route_data := route.Api_list_recent_discuss(tool.Config{
  118. Other_set: "",
  119. IP: tool.Get_IP(c),
  120. Cookies: tool.Get_Cookies(c),
  121. Session: "",
  122. }, c.Param("limit"), "1", "")
  123. in_data := route_data["data"].([][]string)
  124. c.JSON(http.StatusOK, in_data)
  125. })
  126. r.POST("/api/v2/lang", func(c *gin.Context) {
  127. data := c.PostForm("data")
  128. safe := c.PostForm("safe")
  129. legacy := c.PostForm("legacy")
  130. route_data := route.Api_func_language(tool.Config{
  131. Other_set: "",
  132. IP: tool.Get_IP(c),
  133. Cookies: tool.Get_Cookies(c),
  134. Session: "",
  135. }, data, safe, legacy)
  136. c.JSON(http.StatusOK, route_data)
  137. })
  138. r.GET("/api/v2/ip/:ip", func(c *gin.Context) {
  139. route_data := route.Api_func_ip(tool.Config{
  140. Other_set: "",
  141. IP: tool.Get_IP(c),
  142. Cookies: tool.Get_Cookies(c),
  143. Session: "",
  144. }, c.Param("ip"))
  145. c.JSON(http.StatusOK, route_data)
  146. })
  147. r.GET("/api/v2/ip_menu/:ip", func(c *gin.Context) {
  148. route_data := route.Api_func_ip_menu(tool.Config{
  149. Other_set: "",
  150. IP: tool.Get_IP(c),
  151. Cookies: tool.Get_Cookies(c),
  152. Session: "",
  153. }, c.Param("ip"), "")
  154. c.JSON(http.StatusOK, route_data)
  155. })
  156. r.GET("/api/v2/user/setting/editor", func(c *gin.Context) {
  157. route_data := route.Api_user_setting_editor(tool.Config{
  158. Other_set: "",
  159. IP: tool.Get_IP(c),
  160. Cookies: tool.Get_Cookies(c),
  161. Session: "",
  162. })
  163. c.JSON(http.StatusOK, route_data)
  164. })
  165. r.GET("/api/v2/page_view/*doc_name", func(c *gin.Context) {
  166. route_data := route.Api_w_page_view(tool.Config{
  167. Other_set: "",
  168. IP: tool.Get_IP(c),
  169. Cookies: tool.Get_Cookies(c),
  170. Session: "",
  171. }, strings.TrimPrefix(c.Param("doc_name"), "/"))
  172. c.JSON(http.StatusOK, route_data)
  173. })
  174. r.POST("/api/v2/user/setting/editor", func(c *gin.Context) {
  175. route_data := route.Api_user_setting_editor_post(tool.Config{
  176. Other_set: "",
  177. IP: tool.Get_IP(c),
  178. Cookies: tool.Get_Cookies(c),
  179. Session: "",
  180. }, c.Request.FormValue("data"))
  181. c.JSON(http.StatusOK, route_data)
  182. })
  183. r.DELETE("/api/v2/user/setting/editor", func(c *gin.Context) {
  184. route_data := route.Api_user_setting_editor_delete(tool.Config{
  185. Other_set: "",
  186. IP: tool.Get_IP(c),
  187. Cookies: tool.Get_Cookies(c),
  188. Session: "",
  189. }, c.Request.FormValue("data"))
  190. c.JSON(http.StatusOK, route_data)
  191. })
  192. r.GET("/api/v2/page_view_post/*doc_name", func(c *gin.Context) {
  193. route_data := route.Api_w_page_view_post(tool.Config{
  194. Other_set: "",
  195. IP: tool.Get_IP(c),
  196. Cookies: tool.Get_Cookies(c),
  197. Session: "",
  198. }, strings.TrimPrefix(c.Param("doc_name"), "/"))
  199. c.JSON(http.StatusOK, route_data)
  200. })
  201. r.GET("/api/v2/bbs/w/page_view_post/:set_id/:set_code", func(c *gin.Context) {
  202. route_data := route.Api_bbs_w_page_view_post(tool.Config{
  203. Other_set: "",
  204. IP: tool.Get_IP(c),
  205. Cookies: tool.Get_Cookies(c),
  206. Session: "",
  207. }, strings.TrimPrefix(c.Param("set_id"), "/"), strings.TrimPrefix(c.Param("set_code"), "/"))
  208. c.JSON(http.StatusOK, route_data)
  209. })
  210. r.GET("/api/v2/bbs/w/page_view/:set_id/:set_code", func(c *gin.Context) {
  211. route_data := route.Api_bbs_w_page_view(tool.Config{
  212. Other_set: "",
  213. IP: tool.Get_IP(c),
  214. Cookies: tool.Get_Cookies(c),
  215. Session: "",
  216. }, strings.TrimPrefix(c.Param("set_id"), "/"), strings.TrimPrefix(c.Param("set_code"), "/"))
  217. c.JSON(http.StatusOK, route_data)
  218. })
  219. r.GET("/api/v2/bbs/main", func(c *gin.Context) {
  220. route_data := route.Api_bbs(tool.Config{
  221. Other_set: "",
  222. IP: tool.Get_IP(c),
  223. Cookies: tool.Get_Cookies(c),
  224. Session: "",
  225. }, "", "1")
  226. c.JSON(http.StatusOK, route_data)
  227. })
  228. r.GET("/api/v2/raw/*doc_name", func(c *gin.Context) {
  229. route_data := route.Api_w_raw(tool.Config{
  230. Other_set: "",
  231. IP: tool.Get_IP(c),
  232. Cookies: tool.Get_Cookies(c),
  233. Session: "",
  234. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "", "")
  235. c.JSON(http.StatusOK, route_data)
  236. })
  237. r.GET("/api/v2/raw_exist/*doc_name", func(c *gin.Context) {
  238. route_data := route.Api_w_raw(tool.Config{
  239. Other_set: "",
  240. IP: tool.Get_IP(c),
  241. Cookies: tool.Get_Cookies(c),
  242. Session: "",
  243. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "true", "")
  244. c.JSON(http.StatusOK, route_data)
  245. })
  246. r.GET("/api/v2/raw_rev/:rev/*doc_name", func(c *gin.Context) {
  247. route_data := route.Api_w_raw(tool.Config{
  248. Other_set: "",
  249. IP: tool.Get_IP(c),
  250. Cookies: tool.Get_Cookies(c),
  251. Session: "",
  252. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "", c.Param("rev"))
  253. c.JSON(http.StatusOK, route_data)
  254. })
  255. r.GET("/watch_list", func(c *gin.Context) {
  256. route_data := route.View_user_watch_list(tool.Config{
  257. Other_set: "",
  258. IP: tool.Get_IP(c),
  259. Cookies: tool.Get_Cookies(c),
  260. Session: "",
  261. }, "1", "watchlist")
  262. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  263. })
  264. r.GET("/star_doc", func(c *gin.Context) {
  265. route_data := route.View_user_watch_list(tool.Config{
  266. Other_set: "",
  267. IP: tool.Get_IP(c),
  268. Cookies: tool.Get_Cookies(c),
  269. Session: "",
  270. }, "1", "star_doc")
  271. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  272. })
  273. r.GET("/doc_watch_list/:count/*doc_name", func(c *gin.Context) {
  274. route_data := route.View_w_watch_list(tool.Config{
  275. Other_set: "",
  276. IP: tool.Get_IP(c),
  277. Cookies: tool.Get_Cookies(c),
  278. Session: "",
  279. }, strings.TrimPrefix(c.Param("doc_name"), "/"), strings.TrimPrefix(c.Param("count"), "/"), "watchlist")
  280. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  281. })
  282. r.GET("/doc_star_doc/:count/*doc_name", func(c *gin.Context) {
  283. route_data := route.View_w_watch_list(tool.Config{
  284. Other_set: "",
  285. IP: tool.Get_IP(c),
  286. Cookies: tool.Get_Cookies(c),
  287. Session: "",
  288. }, strings.TrimPrefix(c.Param("doc_name"), "/"), strings.TrimPrefix(c.Param("count"), "/"), "star_doc")
  289. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  290. })
  291. r.POST("/star_doc_from/*doc_name", func(c *gin.Context) {
  292. route_data := route.View_w_watch_list_add_post(tool.Config{
  293. Other_set: "",
  294. IP: tool.Get_IP(c),
  295. Cookies: tool.Get_Cookies(c),
  296. Session: "",
  297. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "star_doc_from")
  298. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  299. })
  300. r.GET("/star_doc_from/*doc_name", func(c *gin.Context) {
  301. route_data := route.View_w_watch_list_add(tool.Config{
  302. Other_set: "",
  303. IP: tool.Get_IP(c),
  304. Cookies: tool.Get_Cookies(c),
  305. Session: "",
  306. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "star_doc_from")
  307. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  308. })
  309. r.POST("/star_doc/*doc_name", func(c *gin.Context) {
  310. route_data := route.View_w_watch_list_add_post(tool.Config{
  311. Other_set: "",
  312. IP: tool.Get_IP(c),
  313. Cookies: tool.Get_Cookies(c),
  314. Session: "",
  315. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "star_doc")
  316. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  317. })
  318. r.GET("/star_doc/*doc_name", func(c *gin.Context) {
  319. route_data := route.View_w_watch_list_add(tool.Config{
  320. Other_set: "",
  321. IP: tool.Get_IP(c),
  322. Cookies: tool.Get_Cookies(c),
  323. Session: "",
  324. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "star_doc")
  325. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  326. })
  327. r.POST("/watch_list_from/*doc_name", func(c *gin.Context) {
  328. route_data := route.View_w_watch_list_add_post(tool.Config{
  329. Other_set: "",
  330. IP: tool.Get_IP(c),
  331. Cookies: tool.Get_Cookies(c),
  332. Session: "",
  333. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "watchlist_from")
  334. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  335. })
  336. r.GET("/watch_list_from/*doc_name", func(c *gin.Context) {
  337. route_data := route.View_w_watch_list_add(tool.Config{
  338. Other_set: "",
  339. IP: tool.Get_IP(c),
  340. Cookies: tool.Get_Cookies(c),
  341. Session: "",
  342. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "watchlist_from")
  343. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  344. })
  345. r.POST("/watch_list/*doc_name", func(c *gin.Context) {
  346. route_data := route.View_w_watch_list_add_post(tool.Config{
  347. Other_set: "",
  348. IP: tool.Get_IP(c),
  349. Cookies: tool.Get_Cookies(c),
  350. Session: "",
  351. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "watchlist")
  352. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  353. })
  354. r.GET("/watch_list/*doc_name", func(c *gin.Context) {
  355. route_data := route.View_w_watch_list_add(tool.Config{
  356. Other_set: "",
  357. IP: tool.Get_IP(c),
  358. Cookies: tool.Get_Cookies(c),
  359. Session: "",
  360. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "watchlist")
  361. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  362. })
  363. r.GET("/record_bbs/:user_name", func(c *gin.Context) {
  364. route_data := route.View_record_bbs(tool.Config{
  365. Other_set: "",
  366. IP: tool.Get_IP(c),
  367. Cookies: tool.Get_Cookies(c),
  368. Session: "",
  369. }, c.Param("user_name"), "1")
  370. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  371. })
  372. r.GET("/record_bbs/:user_name/:page", func(c *gin.Context) {
  373. route_data := route.View_record_bbs(tool.Config{
  374. Other_set: "",
  375. IP: tool.Get_IP(c),
  376. Cookies: tool.Get_Cookies(c),
  377. Session: "",
  378. }, c.Param("user_name"), c.Param("page"))
  379. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  380. })
  381. r.GET("/record_bbs_in/:set_id/:user_name", func(c *gin.Context) {
  382. route_data := route.View_record_bbs_in(tool.Config{
  383. Other_set: "",
  384. IP: tool.Get_IP(c),
  385. Cookies: tool.Get_Cookies(c),
  386. Session: "",
  387. }, c.Param("user_name"), c.Param("set_id"), "1")
  388. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  389. })
  390. r.GET("/record_bbs_in/:set_id/:user_name/:page", func(c *gin.Context) {
  391. route_data := route.View_record_bbs_in(tool.Config{
  392. Other_set: "",
  393. IP: tool.Get_IP(c),
  394. Cookies: tool.Get_Cookies(c),
  395. Session: "",
  396. }, c.Param("user_name"), c.Param("set_id"), c.Param("page"))
  397. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  398. })
  399. r.GET("/record_bbs_comment/:user_name", func(c *gin.Context) {
  400. route_data := route.View_record_bbs_comment(tool.Config{
  401. Other_set: "",
  402. IP: tool.Get_IP(c),
  403. Cookies: tool.Get_Cookies(c),
  404. Session: "",
  405. }, c.Param("user_name"), "1")
  406. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  407. })
  408. r.GET("/record_bbs_comment/:user_name/:page", func(c *gin.Context) {
  409. route_data := route.View_record_bbs_comment(tool.Config{
  410. Other_set: "",
  411. IP: tool.Get_IP(c),
  412. Cookies: tool.Get_Cookies(c),
  413. Session: "",
  414. }, c.Param("user_name"), c.Param("page"))
  415. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  416. })
  417. r.GET("/record_bbs_comment_in/:set_id/:user_name", func(c *gin.Context) {
  418. route_data := route.View_record_bbs_comment_in(tool.Config{
  419. Other_set: "",
  420. IP: tool.Get_IP(c),
  421. Cookies: tool.Get_Cookies(c),
  422. Session: "",
  423. }, c.Param("user_name"), c.Param("set_id"), "1")
  424. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  425. })
  426. r.GET("/record_bbs_comment_in/:set_id/:user_name/:page", func(c *gin.Context) {
  427. route_data := route.View_record_bbs_comment_in(tool.Config{
  428. Other_set: "",
  429. IP: tool.Get_IP(c),
  430. Cookies: tool.Get_Cookies(c),
  431. Session: "",
  432. }, c.Param("user_name"), c.Param("set_id"), c.Param("page"))
  433. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  434. })
  435. r.GET("/list/random", func(c *gin.Context) {
  436. route_data := route.View_list_random(tool.Config{
  437. Other_set: "",
  438. IP: tool.Get_IP(c),
  439. Cookies: tool.Get_Cookies(c),
  440. Session: "",
  441. })
  442. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  443. })
  444. r.GET("/list/document/old", func(c *gin.Context) {
  445. route_data := route.View_list_old_page(tool.Config{
  446. Other_set: "",
  447. IP: tool.Get_IP(c),
  448. Cookies: tool.Get_Cookies(c),
  449. Session: "",
  450. }, "1", "old")
  451. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  452. })
  453. r.GET("/list/document/old/:num", func(c *gin.Context) {
  454. route_data := route.View_list_old_page(tool.Config{
  455. Other_set: "",
  456. IP: tool.Get_IP(c),
  457. Cookies: tool.Get_Cookies(c),
  458. Session: "",
  459. }, c.Param("num"), "old")
  460. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  461. })
  462. r.GET("/list/document/new", func(c *gin.Context) {
  463. route_data := route.View_list_old_page(tool.Config{
  464. Other_set: "",
  465. IP: tool.Get_IP(c),
  466. Cookies: tool.Get_Cookies(c),
  467. Session: "",
  468. }, "1", "new")
  469. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  470. })
  471. r.GET("/list/document/new/:num", func(c *gin.Context) {
  472. route_data := route.View_list_old_page(tool.Config{
  473. Other_set: "",
  474. IP: tool.Get_IP(c),
  475. Cookies: tool.Get_Cookies(c),
  476. Session: "",
  477. }, c.Param("num"), "new")
  478. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  479. })
  480. r.GET("/list/document/long", func(c *gin.Context) {
  481. route_data := route.View_list_long_page(tool.Config{
  482. Other_set: "",
  483. IP: tool.Get_IP(c),
  484. Cookies: tool.Get_Cookies(c),
  485. Session: "",
  486. }, "1", "long")
  487. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  488. })
  489. r.GET("/list/document/long/:num", func(c *gin.Context) {
  490. route_data := route.View_list_long_page(tool.Config{
  491. Other_set: "",
  492. IP: tool.Get_IP(c),
  493. Cookies: tool.Get_Cookies(c),
  494. Session: "",
  495. }, c.Param("num"), "long")
  496. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  497. })
  498. r.GET("/list/document/short", func(c *gin.Context) {
  499. route_data := route.View_list_long_page(tool.Config{
  500. Other_set: "",
  501. IP: tool.Get_IP(c),
  502. Cookies: tool.Get_Cookies(c),
  503. Session: "",
  504. }, "1", "short")
  505. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  506. })
  507. r.GET("/list/document/short/:num", func(c *gin.Context) {
  508. route_data := route.View_list_long_page(tool.Config{
  509. Other_set: "",
  510. IP: tool.Get_IP(c),
  511. Cookies: tool.Get_Cookies(c),
  512. Session: "",
  513. }, c.Param("num"), "short")
  514. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  515. })
  516. r.GET("/random", func(c *gin.Context) {
  517. route_data := route.View_w_random(tool.Config{
  518. Other_set: "",
  519. IP: tool.Get_IP(c),
  520. Cookies: tool.Get_Cookies(c),
  521. Session: "",
  522. })
  523. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  524. })
  525. r.GET("/other", func(c *gin.Context) {
  526. route_data := route.View_main_other(tool.Config{
  527. Other_set: "",
  528. IP: tool.Get_IP(c),
  529. Cookies: tool.Get_Cookies(c),
  530. Session: "",
  531. })
  532. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  533. })
  534. r.GET("/user", func(c *gin.Context) {
  535. route_data := route.View_user(tool.Config{
  536. Other_set: "",
  537. IP: tool.Get_IP(c),
  538. Cookies: tool.Get_Cookies(c),
  539. Session: "",
  540. }, tool.Get_IP(c))
  541. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  542. })
  543. r.GET("/user/*user_name", func(c *gin.Context) {
  544. route_data := route.View_user(tool.Config{
  545. Other_set: "",
  546. IP: tool.Get_IP(c),
  547. Cookies: tool.Get_Cookies(c),
  548. Session: "",
  549. }, strings.TrimPrefix(c.Param("user_name"), "/"))
  550. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  551. })
  552. r.GET("/upload", func(c *gin.Context) {
  553. route_data := route.View_edit_file_upload(tool.Config{
  554. Other_set: "",
  555. IP: tool.Get_IP(c),
  556. Cookies: tool.Get_Cookies(c),
  557. Session: "",
  558. })
  559. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  560. })
  561. r.GET("/w/*doc_name", func(c *gin.Context) {
  562. route_data, status_code := route.View_w(c, tool.Config{
  563. Other_set: "",
  564. IP: tool.Get_IP(c),
  565. Cookies: tool.Get_Cookies(c),
  566. Session: "",
  567. }, strings.TrimPrefix(c.Param("doc_name"), "/"))
  568. c.Data(status_code, "text/html; charset=utf-8", []byte(route_data))
  569. })
  570. r.GET("/down/*doc_name", func(c *gin.Context) {
  571. route_data := route.View_w_down(tool.Config{
  572. Other_set: "",
  573. IP: tool.Get_IP(c),
  574. Cookies: tool.Get_Cookies(c),
  575. Session: "",
  576. }, strings.TrimPrefix(c.Param("doc_name"), "/"))
  577. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  578. })
  579. r.GET("/raw/*doc_name", func(c *gin.Context) {
  580. route_data := route.View_w_raw(tool.Config{
  581. Other_set: "",
  582. IP: tool.Get_IP(c),
  583. Cookies: tool.Get_Cookies(c),
  584. Session: "",
  585. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "", "")
  586. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  587. })
  588. r.GET("/raw_rev/:rev/*doc_name", func(c *gin.Context) {
  589. route_data := route.View_w_raw(tool.Config{
  590. Other_set: "",
  591. IP: tool.Get_IP(c),
  592. Cookies: tool.Get_Cookies(c),
  593. Session: "",
  594. }, strings.TrimPrefix(c.Param("doc_name"), "/"), c.Param("rev"), "")
  595. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  596. })
  597. r.GET("/raw_acl/*doc_name", func(c *gin.Context) {
  598. route_data := route.View_w_raw(tool.Config{
  599. Other_set: "",
  600. IP: tool.Get_IP(c),
  601. Cookies: tool.Get_Cookies(c),
  602. Session: "",
  603. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "", "document_acl")
  604. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  605. })
  606. r.GET("/topic/*doc_name", func(c *gin.Context) {
  607. route_data := route.View_topic_list(tool.Config{
  608. Other_set: "",
  609. IP: tool.Get_IP(c),
  610. Cookies: tool.Get_Cookies(c),
  611. Session: "",
  612. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "", "1")
  613. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  614. })
  615. r.GET("/topic_page/:num/*doc_name", func(c *gin.Context) {
  616. route_data := route.View_topic_list(tool.Config{
  617. Other_set: "",
  618. IP: tool.Get_IP(c),
  619. Cookies: tool.Get_Cookies(c),
  620. Session: "",
  621. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "", c.Param("num"))
  622. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  623. })
  624. r.GET("/topic_close/:num/*doc_name", func(c *gin.Context) {
  625. route_data := route.View_topic_list(tool.Config{
  626. Other_set: "",
  627. IP: tool.Get_IP(c),
  628. Cookies: tool.Get_Cookies(c),
  629. Session: "",
  630. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "close", c.Param("num"))
  631. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  632. })
  633. r.GET("/topic_agree/:num/*doc_name", func(c *gin.Context) {
  634. route_data := route.View_topic_list(tool.Config{
  635. Other_set: "",
  636. IP: tool.Get_IP(c),
  637. Cookies: tool.Get_Cookies(c),
  638. Session: "",
  639. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "agree", c.Param("num"))
  640. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  641. })
  642. r.GET("/recent_block", func(c *gin.Context) {
  643. route_data := route.View_list_recent_block(tool.Config{
  644. Other_set: "",
  645. IP: tool.Get_IP(c),
  646. Cookies: tool.Get_Cookies(c),
  647. Session: "",
  648. }, "1", "", "", "")
  649. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  650. })
  651. r.GET("/recent_block/all", func(c *gin.Context) {
  652. route_data := route.View_list_recent_block(tool.Config{
  653. Other_set: "",
  654. IP: tool.Get_IP(c),
  655. Cookies: tool.Get_Cookies(c),
  656. Session: "",
  657. }, "1", "", "", "")
  658. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  659. })
  660. r.GET("/recent_block/all/:num", func(c *gin.Context) {
  661. route_data := route.View_list_recent_block(tool.Config{
  662. Other_set: "",
  663. IP: tool.Get_IP(c),
  664. Cookies: tool.Get_Cookies(c),
  665. Session: "",
  666. }, c.Param("num"), "", "", "")
  667. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  668. })
  669. r.GET("/recent_block/all/:num/*why", func(c *gin.Context) {
  670. route_data := route.View_list_recent_block(tool.Config{
  671. Other_set: "",
  672. IP: tool.Get_IP(c),
  673. Cookies: tool.Get_Cookies(c),
  674. Session: "",
  675. }, c.Param("num"), "", strings.TrimPrefix(c.Param("why"), "/"), "")
  676. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  677. })
  678. r.GET("/recent_block/user/:user_name", func(c *gin.Context) {
  679. route_data := route.View_list_recent_block(tool.Config{
  680. Other_set: "",
  681. IP: tool.Get_IP(c),
  682. Cookies: tool.Get_Cookies(c),
  683. Session: "",
  684. }, "1", "user", "", c.Param("user_name"))
  685. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  686. })
  687. r.GET("/recent_block/user/:user_name/:num", func(c *gin.Context) {
  688. route_data := route.View_list_recent_block(tool.Config{
  689. Other_set: "",
  690. IP: tool.Get_IP(c),
  691. Cookies: tool.Get_Cookies(c),
  692. Session: "",
  693. }, c.Param("num"), "user", "", c.Param("user_name"))
  694. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  695. })
  696. r.GET("/recent_block/admin/:user_name", func(c *gin.Context) {
  697. route_data := route.View_list_recent_block(tool.Config{
  698. Other_set: "",
  699. IP: tool.Get_IP(c),
  700. Cookies: tool.Get_Cookies(c),
  701. Session: "",
  702. }, "1", "admin", "", c.Param("user_name"))
  703. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  704. })
  705. r.GET("/recent_block/admin/:user_name/:num", func(c *gin.Context) {
  706. route_data := route.View_list_recent_block(tool.Config{
  707. Other_set: "",
  708. IP: tool.Get_IP(c),
  709. Cookies: tool.Get_Cookies(c),
  710. Session: "",
  711. }, c.Param("num"), "admin", "", c.Param("user_name"))
  712. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  713. })
  714. r.GET("/recent_block/regex", func(c *gin.Context) {
  715. route_data := route.View_list_recent_block(tool.Config{
  716. Other_set: "",
  717. IP: tool.Get_IP(c),
  718. Cookies: tool.Get_Cookies(c),
  719. Session: "",
  720. }, "1", "regex", "", "")
  721. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  722. })
  723. r.GET("/recent_block/regex/:num", func(c *gin.Context) {
  724. route_data := route.View_list_recent_block(tool.Config{
  725. Other_set: "",
  726. IP: tool.Get_IP(c),
  727. Cookies: tool.Get_Cookies(c),
  728. Session: "",
  729. }, c.Param("num"), "regex", "", "")
  730. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  731. })
  732. r.GET("/recent_block/cidr", func(c *gin.Context) {
  733. route_data := route.View_list_recent_block(tool.Config{
  734. Other_set: "",
  735. IP: tool.Get_IP(c),
  736. Cookies: tool.Get_Cookies(c),
  737. Session: "",
  738. }, "1", "cidr", "", "")
  739. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  740. })
  741. r.GET("/recent_block/cidr/:num", func(c *gin.Context) {
  742. route_data := route.View_list_recent_block(tool.Config{
  743. Other_set: "",
  744. IP: tool.Get_IP(c),
  745. Cookies: tool.Get_Cookies(c),
  746. Session: "",
  747. }, c.Param("num"), "cidr", "", "")
  748. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  749. })
  750. r.GET("/recent_block/private", func(c *gin.Context) {
  751. route_data := route.View_list_recent_block(tool.Config{
  752. Other_set: "",
  753. IP: tool.Get_IP(c),
  754. Cookies: tool.Get_Cookies(c),
  755. Session: "",
  756. }, "1", "private", "", "")
  757. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  758. })
  759. r.GET("/recent_block/private/:num", func(c *gin.Context) {
  760. route_data := route.View_list_recent_block(tool.Config{
  761. Other_set: "",
  762. IP: tool.Get_IP(c),
  763. Cookies: tool.Get_Cookies(c),
  764. Session: "",
  765. }, c.Param("num"), "private", "", "")
  766. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  767. })
  768. r.GET("/recent_block/ongoing", func(c *gin.Context) {
  769. route_data := route.View_list_recent_block(tool.Config{
  770. Other_set: "",
  771. IP: tool.Get_IP(c),
  772. Cookies: tool.Get_Cookies(c),
  773. Session: "",
  774. }, "1", "ongoing", "", "")
  775. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  776. })
  777. r.GET("/recent_block/ongoing/:num", func(c *gin.Context) {
  778. route_data := route.View_list_recent_block(tool.Config{
  779. Other_set: "",
  780. IP: tool.Get_IP(c),
  781. Cookies: tool.Get_Cookies(c),
  782. Session: "",
  783. }, c.Param("num"), "ongoing", "", "")
  784. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  785. })
  786. r.GET("/recent_change", func(c *gin.Context) {
  787. route_data := route.View_list_recent_change(tool.Config{
  788. Other_set: "",
  789. IP: tool.Get_IP(c),
  790. Cookies: tool.Get_Cookies(c),
  791. Session: "",
  792. }, "", "50", "1")
  793. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  794. })
  795. r.GET("/recent_changes", func(c *gin.Context) {
  796. route_data := route.View_list_recent_change(tool.Config{
  797. Other_set: "",
  798. IP: tool.Get_IP(c),
  799. Cookies: tool.Get_Cookies(c),
  800. Session: "",
  801. }, "", "50", "1")
  802. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  803. })
  804. r.GET("/recent_change/:num/:set_type", func(c *gin.Context) {
  805. route_data := route.View_list_recent_change(tool.Config{
  806. Other_set: "",
  807. IP: tool.Get_IP(c),
  808. Cookies: tool.Get_Cookies(c),
  809. Session: "",
  810. }, c.Param("set_type"), "50", c.Param("num"))
  811. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  812. })
  813. r.GET("/recent_discuss", func(c *gin.Context) {
  814. route_data := route.View_list_recent_discuss(tool.Config{
  815. Other_set: "",
  816. IP: tool.Get_IP(c),
  817. Cookies: tool.Get_Cookies(c),
  818. Session: "",
  819. }, "50", "1", "")
  820. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  821. })
  822. r.GET("/recent_discuss/:num/:set_type", func(c *gin.Context) {
  823. route_data := route.View_list_recent_discuss(tool.Config{
  824. Other_set: "",
  825. IP: tool.Get_IP(c),
  826. Cookies: tool.Get_Cookies(c),
  827. Session: "",
  828. }, "50", c.Param("num"), c.Param("set_type"))
  829. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  830. })
  831. r.GET("/bbs/main", func(c *gin.Context) {
  832. route_data := route.View_bbs_main(tool.Config{
  833. Other_set: "",
  834. IP: tool.Get_IP(c),
  835. Cookies: tool.Get_Cookies(c),
  836. Session: "",
  837. }, "1")
  838. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  839. })
  840. r.GET("/bbs/make", func(c *gin.Context) {
  841. route_data := route.View_bbs_make(tool.Config{
  842. Other_set: "",
  843. IP: tool.Get_IP(c),
  844. Cookies: tool.Get_Cookies(c),
  845. Session: "",
  846. })
  847. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  848. })
  849. r.POST("/bbs/make", func(c *gin.Context) {
  850. bbs_name := c.PostForm("bbs_name")
  851. bbs_type := c.PostForm("bbs_type")
  852. route_data := route.View_bbs_make_post(tool.Config{
  853. Other_set: "",
  854. IP: tool.Get_IP(c),
  855. Cookies: tool.Get_Cookies(c),
  856. Session: "",
  857. }, bbs_name, bbs_type)
  858. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  859. })
  860. r.GET("/bbs/in/:set_id", func(c *gin.Context) {
  861. route_data := route.View_bbs_in(tool.Config{
  862. Other_set: "",
  863. IP: tool.Get_IP(c),
  864. Cookies: tool.Get_Cookies(c),
  865. Session: "",
  866. }, c.Param("set_id"), "1")
  867. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  868. })
  869. r.GET("/bbs/in/:set_id/:page_num", func(c *gin.Context) {
  870. route_data := route.View_bbs_in(tool.Config{
  871. Other_set: "",
  872. IP: tool.Get_IP(c),
  873. Cookies: tool.Get_Cookies(c),
  874. Session: "",
  875. }, c.Param("set_id"), c.Param("page_num"))
  876. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  877. })
  878. r.GET("/bbs/w/:set_id/:set_code", func(c *gin.Context) {
  879. route_data := route.View_bbs_in_w(c, tool.Config{
  880. Other_set: "",
  881. IP: tool.Get_IP(c),
  882. Cookies: tool.Get_Cookies(c),
  883. Session: "",
  884. }, c.Param("set_id"), c.Param("set_code"))
  885. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  886. })
  887. r.GET("/history/*doc_name", func(c *gin.Context) {
  888. route_data := route.View_list_history(tool.Config{
  889. Other_set: "",
  890. IP: tool.Get_IP(c),
  891. Cookies: tool.Get_Cookies(c),
  892. Session: "",
  893. }, strings.TrimPrefix(c.Param("doc_name"), "/"), "", "1")
  894. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  895. })
  896. r.POST("/history/*doc_name", func(c *gin.Context) {
  897. doc_name := strings.TrimPrefix(c.Param("doc_name"), "/")
  898. a := c.PostForm("a")
  899. b := c.PostForm("b")
  900. route_data := route.View_list_history_post(tool.Config{
  901. Other_set: "",
  902. IP: tool.Get_IP(c),
  903. Cookies: tool.Get_Cookies(c),
  904. Session: "",
  905. }, doc_name, a, b)
  906. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  907. })
  908. r.GET("/history_page/:num/:set_type/*doc_name", func(c *gin.Context) {
  909. route_data := route.View_list_history(tool.Config{
  910. Other_set: "",
  911. IP: tool.Get_IP(c),
  912. Cookies: tool.Get_Cookies(c),
  913. Session: "",
  914. }, strings.TrimPrefix(c.Param("doc_name"), "/"), strings.TrimPrefix(c.Param("set_type"), "/"), strings.TrimPrefix(c.Param("num"), "/"))
  915. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  916. })
  917. r.POST("/history_page/:num/:set_type/*doc_name", func(c *gin.Context) {
  918. doc_name := strings.TrimPrefix(c.Param("doc_name"), "/")
  919. a := c.PostForm("a")
  920. b := c.PostForm("b")
  921. route_data := route.View_list_history_post(tool.Config{
  922. Other_set: "",
  923. IP: tool.Get_IP(c),
  924. Cookies: tool.Get_Cookies(c),
  925. Session: "",
  926. }, doc_name, a, b)
  927. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  928. })
  929. r.GET("/edit/*doc_name", func(c *gin.Context) {
  930. route_data := route.View_edit(tool.Config{
  931. Other_set: "",
  932. IP: tool.Get_IP(c),
  933. Cookies: tool.Get_Cookies(c),
  934. Session: "",
  935. }, strings.TrimPrefix(c.Param("doc_name"), "/"), c.Query("load"))
  936. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  937. })
  938. r.POST("/edit/*doc_name", func(c *gin.Context) {
  939. doc_name := strings.TrimPrefix(c.Param("doc_name"), "/")
  940. data := c.PostForm("content")
  941. send := c.PostForm("send")
  942. agree := c.PostForm("copyright_agreement")
  943. route_data := route.View_edit_post(tool.Config{
  944. Other_set: "",
  945. IP: tool.Get_IP(c),
  946. Cookies: tool.Get_Cookies(c),
  947. Session: "",
  948. }, doc_name, data, send, agree)
  949. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  950. })
  951. r.POST("/upload", func(c *gin.Context) {
  952. form, err := c.MultipartForm()
  953. if err != nil || form == nil {
  954. c.String(http.StatusBadRequest, "invalid multipart form")
  955. return
  956. }
  957. files := form.File["f_data[]"]
  958. if len(files) == 0 {
  959. c.String(http.StatusBadRequest, "no file")
  960. return
  961. }
  962. posted_name := strings.TrimSpace(c.PostForm("f_name"))
  963. other_set_arr := []map[string]string{}
  964. count := 1
  965. for _, fh := range files {
  966. f, err := fh.Open()
  967. if err != nil {
  968. continue
  969. }
  970. b, err := io.ReadAll(f)
  971. _ = f.Close()
  972. if err != nil {
  973. continue
  974. }
  975. name := posted_name
  976. name = strings.TrimSpace(name)
  977. ext := strings.TrimPrefix(strings.ToLower(filepath.Ext(name)), ".")
  978. ext = strings.TrimSpace(ext)
  979. b64 := base64.StdEncoding.EncodeToString(b)
  980. other_set := map[string]string{
  981. "file_name": name,
  982. "file_ext": ext,
  983. "file_data": b64,
  984. }
  985. other_set_arr = append(other_set_arr, other_set)
  986. count += 1
  987. }
  988. other_set_arr_str, _ := json.MarshalToString(other_set_arr)
  989. route_data := route.View_edit_file_upload_post(tool.Config{
  990. IP: tool.Get_IP(c),
  991. Cookies: tool.Get_Cookies(c),
  992. Session: "",
  993. Other_set: other_set_arr_str,
  994. })
  995. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  996. })
  997. r.GET("/view/*name", route.View_view_file)
  998. r.GET("/views/*name", route.View_view_file)
  999. r.GET("/image/*name", route.View_view_image_file)
  1000. r.POST("/goto", func(c *gin.Context) {
  1001. route_data := route.View_main_search_post(tool.Config{
  1002. Other_set: "",
  1003. IP: tool.Get_IP(c),
  1004. Cookies: tool.Get_Cookies(c),
  1005. Session: "",
  1006. }, "", true, c.PostForm("search"))
  1007. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  1008. })
  1009. r.POST("/goto/*keyword", func(c *gin.Context) {
  1010. route_data := route.View_main_search_post(tool.Config{
  1011. Other_set: "",
  1012. IP: tool.Get_IP(c),
  1013. Cookies: tool.Get_Cookies(c),
  1014. Session: "",
  1015. }, "", true, c.PostForm("search"))
  1016. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  1017. })
  1018. r.POST("/search", func(c *gin.Context) {
  1019. route_data := route.View_main_search_post(tool.Config{
  1020. Other_set: "",
  1021. IP: tool.Get_IP(c),
  1022. Cookies: tool.Get_Cookies(c),
  1023. Session: "",
  1024. }, "", false, c.PostForm("search"))
  1025. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  1026. })
  1027. r.GET("/search/*keyword", func(c *gin.Context) {
  1028. route_data := route.View_main_search(tool.Config{
  1029. Other_set: "",
  1030. IP: tool.Get_IP(c),
  1031. Cookies: tool.Get_Cookies(c),
  1032. Session: "",
  1033. }, strings.TrimPrefix(c.Param("keyword"), "/"), "1", "title")
  1034. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  1035. })
  1036. r.POST("/search/*keyword", func(c *gin.Context) {
  1037. route_data := route.View_main_search_post(tool.Config{
  1038. Other_set: "",
  1039. IP: tool.Get_IP(c),
  1040. Cookies: tool.Get_Cookies(c),
  1041. Session: "",
  1042. }, "", false, c.PostForm("search"))
  1043. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  1044. })
  1045. r.POST("/search_page/:num/*keyword", func(c *gin.Context) {
  1046. route_data := route.View_main_search_post(tool.Config{
  1047. Other_set: "",
  1048. IP: tool.Get_IP(c),
  1049. Cookies: tool.Get_Cookies(c),
  1050. Session: "",
  1051. }, "", false, c.PostForm("search"))
  1052. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  1053. })
  1054. r.GET("/search_page/:num/*keyword", func(c *gin.Context) {
  1055. route_data := route.View_main_search(tool.Config{
  1056. Other_set: "",
  1057. IP: tool.Get_IP(c),
  1058. Cookies: tool.Get_Cookies(c),
  1059. Session: "",
  1060. }, strings.TrimPrefix(c.Param("keyword"), "/"), c.Param("num"), "title")
  1061. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  1062. })
  1063. r.POST("/search_data/*keyword", func(c *gin.Context) {
  1064. route_data := route.View_main_search_post(tool.Config{
  1065. Other_set: "",
  1066. IP: tool.Get_IP(c),
  1067. Cookies: tool.Get_Cookies(c),
  1068. Session: "",
  1069. }, "", false, c.PostForm("search"))
  1070. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  1071. })
  1072. r.POST("/search_data_page/:num/*keyword", func(c *gin.Context) {
  1073. route_data := route.View_main_search_post(tool.Config{
  1074. Other_set: "",
  1075. IP: tool.Get_IP(c),
  1076. Cookies: tool.Get_Cookies(c),
  1077. Session: "",
  1078. }, "", false, c.PostForm("search"))
  1079. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  1080. })
  1081. r.GET("/search_data_page/:num/*keyword", func(c *gin.Context) {
  1082. route_data := route.View_main_search(tool.Config{
  1083. Other_set: "",
  1084. IP: tool.Get_IP(c),
  1085. Cookies: tool.Get_Cookies(c),
  1086. Session: "",
  1087. }, strings.TrimPrefix(c.Param("keyword"), "/"), c.Param("num"), "data")
  1088. c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(route_data))
  1089. })
  1090. r.NoRoute(func(c *gin.Context) {
  1091. route_data := route.View_main_404_page(tool.Config{
  1092. Other_set: "",
  1093. IP: tool.Get_IP(c),
  1094. Cookies: tool.Get_Cookies(c),
  1095. Session: "",
  1096. }, c.Request.URL.Path)
  1097. c.Data(http.StatusNotFound, "text/html; charset=utf-8", []byte(route_data))
  1098. })
  1099. log.Default().Println("Run in http://127.0.0.1:" + port)
  1100. if err := r.Run("0.0.0.0:" + port); err != nil {
  1101. log.Fatalf("server failed: %v", err)
  1102. }
  1103. }