Explorar o código

역링크 API 제작 완료

https://github.com/openNAMU/openNAMU/issues/2051
잉여개발기 %!s(int64=2) %!d(string=hai) anos
pai
achega
a167fc6ce8

+ 5 - 0
app.py

@@ -681,6 +681,11 @@ app.route('/api/raw_exist/<everything:name>', defaults = { 'exist_check' : 'on',
 app.route('/api/raw_rev/<int(signed = True):rev>/<everything:name>', defaults = { 'db_set' : db_set_str })(api_w_raw)
 app.route('/api/raw/<everything:name>', defaults = { 'db_set' : db_set_str })(api_w_raw)
 
+app.route('/api/xref/<everything:name>', defaults = { 'db_set' : db_set_str })(api_w_xref)
+app.route('/api/xref_page/<int:num>/<everything:name>', defaults = { 'db_set' : db_set_str })(api_w_xref)
+app.route('/api/xref_this/<everything:name>', defaults = { 'xref_type' : '2', 'db_set' : db_set_str })(api_w_xref)
+app.route('/api/xref_this_page/<int:num>/<everything:name>', defaults = { 'xref_type' : '2', 'db_set' : db_set_str })(api_w_xref)
+
 app.route('/api/random', defaults = { 'db_set' : db_set_str })(api_w_random)
 
 app.route('/api/bbs/main', defaults = { 'db_set' : db_set_str })(api_bbs)

+ 1 - 0
route/__init__.py

@@ -182,5 +182,6 @@ from route.go_api_topic import api_topic
 
 from route.go_api_w_raw import api_w_raw
 from route.go_api_w_random import api_w_random
+from route.go_api_w_xref import api_w_xref
 
 from route.go_main_func_easter_egg import main_func_easter_egg

+ 1 - 1
route/go_api_bbs.py

@@ -3,7 +3,7 @@ from .tool.func import *
 def api_bbs(db_set, bbs_num = "", page = 1):
     with get_db_connect() as conn:
         other_set = {}
-        other_set["bbs_num"] = bbs_num
+        other_set["bbs_num"] = str(bbs_num)
         other_set["page"] = str(page)
         other_set["ip"] = ip_check()
         other_set = json.dumps(other_set)

+ 24 - 0
route/go_api_w_xref.py

@@ -0,0 +1,24 @@
+from .tool.func import *
+
+def api_w_xref(db_set, name = 'Test', page = 1, xref_type = '1'):
+    with get_db_connect() as conn:
+        other_set = {}
+        other_set["name"] = name
+        other_set["page"] = str(page)
+        other_set["do_type"] = xref_type
+        other_set = json.dumps(other_set)
+
+        if platform.system() == 'Linux':
+            if platform.machine() in ["AMD64", "x86_64"]:
+                data = subprocess.Popen([os.path.join(".", "route_go", "bin", "main.amd64.bin"), sys._getframe().f_code.co_name, db_set, other_set], stdout = subprocess.PIPE).communicate()[0]
+            else:
+                data = subprocess.Popen([os.path.join(".", "route_go", "bin", "main.arm64.bin"), sys._getframe().f_code.co_name, db_set, other_set], stdout = subprocess.PIPE).communicate()[0]
+        else:
+            if platform.machine() in ["AMD64", "x86_64"]:
+                data = subprocess.Popen([os.path.join(".", "route_go", "bin", "main.amd64.exe"), sys._getframe().f_code.co_name, db_set, other_set], stdout = subprocess.PIPE).communicate()[0]
+            else:
+                data = subprocess.Popen([os.path.join(".", "route_go", "bin", "main.arm64.exe"), sys._getframe().f_code.co_name, db_set, other_set], stdout = subprocess.PIPE).communicate()[0]
+
+        data = data.decode('utf8')
+
+        return flask.Response(response = data, status = 200, mimetype = 'application/json')

BIN=BIN
route_go/bin/main.amd64.bin


BIN=BIN
route_go/bin/main.amd64.exe


BIN=BIN
route_go/bin/main.arm64.bin


BIN=BIN
route_go/bin/main.arm64.exe


+ 2 - 0
route_go/main.go

@@ -28,5 +28,7 @@ func main() {
 		route.Api_recent_edit_request(call_arg[1:])
 	} else if call_arg[0] == "api_bbs" {
 		route.Api_bbs(call_arg[1:])
+	} else if call_arg[0] == "api_w_xref" {
+		route.Api_w_xref(call_arg[1:])
 	}
 }

+ 6 - 2
route_go/route/api_bbs.go

@@ -92,6 +92,10 @@ func Api_bbs(call_arg []string) {
 		data_list = append(data_list, temp_data)
 	}
 
-	json_data, _ := json.Marshal(data_list)
-	fmt.Print(string(json_data))
+	if len(data_list) == 0 {
+		fmt.Print("{}")
+	} else {
+		json_data, _ := json.Marshal(data_list)
+		fmt.Print(string(json_data))
+	}
 }

+ 83 - 0
route_go/route/api_w_xref.go

@@ -0,0 +1,83 @@
+package route
+
+import (
+	"database/sql"
+	"encoding/json"
+	"fmt"
+	"opennamu/route/tool"
+	"strconv"
+)
+
+func Api_w_xref(call_arg []string) {
+	db_set := map[string]string{}
+	json.Unmarshal([]byte(call_arg[0]), &db_set)
+
+	other_set := map[string]string{}
+	json.Unmarshal([]byte(call_arg[1]), &other_set)
+
+	db := tool.DB_connect(db_set)
+	if db == nil {
+		return
+	}
+	defer db.Close()
+
+	page, _ := strconv.Atoi(other_set["page"])
+	num := 0
+	if page*50 > 0 {
+		num = page*50 - 50
+	}
+
+	var link_case_insensitive string
+
+	err := db.QueryRow(tool.DB_change(db_set, "select data from other where name = 'link_case_insensitive'")).Scan(&link_case_insensitive)
+	if err != nil {
+		if err == sql.ErrNoRows {
+			link_case_insensitive = ""
+		} else {
+			return
+		}
+	}
+
+	if link_case_insensitive != "" {
+		link_case_insensitive = " collate nocase"
+	}
+
+	var stmt *sql.Stmt
+	if other_set["do_type"] == "1" {
+		stmt, err = db.Prepare(tool.DB_change(db_set, "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"))
+	} else {
+		stmt, err = db.Prepare(tool.DB_change(db_set, "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"))
+	}
+
+	if err != nil {
+		return
+	}
+	defer stmt.Close()
+
+	rows, err := stmt.Query(other_set["name"], num)
+	if err != nil {
+		return
+	}
+	defer rows.Close()
+
+	var name string
+	var type_data string
+
+	var data_list [][]string
+
+	for rows.Next() {
+		err := rows.Scan(&name, &type_data)
+		if err != nil {
+			return
+		}
+
+		data_list = append(data_list, []string{name, type_data})
+	}
+
+	if len(data_list) == 0 {
+		fmt.Print("{}")
+	} else {
+		json_data, _ := json.Marshal(data_list)
+		fmt.Print(string(json_data))
+	}
+}

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "beta" : {
-        "r_ver" : "v3.5.0-dev35",
+        "r_ver" : "v3.5.0-dev36",
         "c_ver" : "3500376",
         "s_ver" : "3500113"
     }