api_w_xref.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package route
  2. import (
  3. "opennamu/route/tool"
  4. )
  5. func Api_w_xref(config tool.Config, num_str string, doc_name string, do_type string) map[string]any {
  6. db := tool.DB_connect()
  7. defer tool.DB_close(db)
  8. page := tool.Str_to_int(num_str)
  9. num := 0
  10. if page * 50 > 0 {
  11. num = page * 50 - 50
  12. }
  13. link_case_insensitive := ""
  14. tool.QueryRow_DB(
  15. db,
  16. "select data from other where name = 'link_case_insensitive'",
  17. []any{ &link_case_insensitive },
  18. doc_name,
  19. )
  20. if link_case_insensitive != "" {
  21. link_case_insensitive = " collate nocase"
  22. }
  23. query := ""
  24. if do_type == "1" {
  25. query = "select distinct link, type from back where title" + link_case_insensitive + " = ? and not type = 'no' and not type = 'nothing' order by type asc, link asc limit ?, 50"
  26. } else {
  27. query = "select distinct title, type from back where link" + link_case_insensitive + " = ? and not type = 'no' and not type = 'nothing' order by type asc, title asc limit ?, 50"
  28. }
  29. rows := tool.Query_DB(
  30. db,
  31. query,
  32. doc_name,
  33. num,
  34. )
  35. defer rows.Close()
  36. data_list := [][]string{}
  37. for rows.Next() {
  38. var name string
  39. var type_data string
  40. err := rows.Scan(&name, &type_data)
  41. if err != nil {
  42. panic(err)
  43. }
  44. data_list = append(data_list, []string{name, type_data})
  45. }
  46. return_data := make(map[string]any)
  47. return_data["response"] = "ok"
  48. return_data["data"] = data_list
  49. return return_data
  50. }