Explorar o código

최근 변경 API Golang으로 이전

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

+ 5 - 6
app.py

@@ -486,9 +486,8 @@ app.route('/block_log/ongoing/<int:num>', defaults = { 'tool' : 'ongoing' })(rec
 
 # Func-history
 app.route('/recent_change', defaults = { 'tool' : 'recent' })(recent_change)
-app.route('/recent_change/<int:num>/<set_type>', defaults = { 'tool' : 'recent' })(recent_change)
 app.route('/recent_changes', defaults = { 'tool' : 'recent' })(recent_change)
-app.route('/recent_changes/<int:num>/<set_type>', defaults = { 'tool' : 'recent' })(recent_change)
+app.route('/recent_change/<int:num>/<set_type>', defaults = { 'tool' : 'recent' })(recent_change)
 
 app.route('/record/<name>', defaults = { 'tool' : 'record' })(recent_change)
 app.route('/record/<int:num>/<set_type>/<name>', defaults = { 'tool' : 'record' })(recent_change)
@@ -702,10 +701,10 @@ app.route('/api/search_data/<everything:name>', defaults = { 'search_type' : 'da
 app.route('/api/search_data_page/<int:num>/<everything:name>', defaults = { 'search_type' : 'data', 'db_set' : db_set_str })(api_search)
 
 # 곧 개편 당할 곳
-app.route('/api/recent_change/<int:num>')(api_recent_change)
-app.route('/api/recent_change')(api_recent_change)
-# recent_changes -> recent_change
-app.route('/api/recent_changes')(api_recent_change)
+app.route('/api/recent_change', defaults = { 'db_set' : db_set_str })(api_recent_change)
+app.route('/api/recent_changes', defaults = { 'db_set' : db_set_str })(api_recent_change)
+app.route('/api/recent_change/<int:limit>', defaults = { 'db_set' : db_set_str })(api_recent_change)
+app.route('/api/recent_change/<int:limit>/<set_type>/<int:num>', defaults = { 'db_set' : db_set_str })(api_recent_change)
 
 app.route('/api/recent_discuss/<get_type>/<int:num>')(api_recent_discuss)
 app.route('/api/recent_discuss/<int:num>')(api_recent_discuss)

+ 2 - 1
route/__init__.py

@@ -1,6 +1,5 @@
 from route.api_func_lang import api_func_lang
 from route.api_image_view import api_image_view
-from route.api_recent_change import api_recent_change
 from route.api_recent_discuss import api_recent_discuss
 from route.api_setting import api_setting
 from route.api_skin_info import api_skin_info
@@ -173,6 +172,8 @@ from route.go_api_func_ip import api_func_ip
 
 from route.go_api_search import api_search
 
+from route.go_api_recent_change import api_recent_change
+
 from route.go_api_topic import api_topic
 
 from route.go_api_w_raw import api_w_raw

+ 0 - 29
route/api_recent_change.py

@@ -1,29 +0,0 @@
-from .tool.func import *
-
-def api_recent_change(num = 10):
-    with get_db_connect() as conn:
-        curs = conn.cursor()
-
-        num = 50 if (1 if not num > 0 else num) > 50 else num
-        admin = admin_check(6)
-
-        data_list = []
-
-        curs.execute(db_change('select id, title from rc where type = "normal" order by date desc limit ?'), [num])
-        for for_a in curs.fetchall():
-            curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where id = ? and title = ?'), for_a)
-            db_data = curs.fetchall()
-            if db_data:
-                db_data = list(db_data[0])
-                if db_data[6] == '' or admin == 1:
-                    if admin == 1:
-                        data_list += [db_data]
-                    else:
-                        db_data[3] = ip_pas(db_data[3], 1)
-                        data_list += [db_data]
-                else:
-                    data_list += [['', '', '', '', '', '', db_data[6]]]
-            else:
-                data_list += [['', '', '', '', '', '', '']]
-
-        return flask.jsonify(data_list if data_list else {}) 

+ 4 - 4
route/go_api_func_ip.py

@@ -9,14 +9,14 @@ def api_func_ip(db_set, data = 'Test'):
 
         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, data], stdout = subprocess.PIPE).communicate()[0]
+                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, data], stdout = subprocess.PIPE).communicate()[0]
+                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, data], stdout = subprocess.PIPE).communicate()[0]
+                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, data], stdout = subprocess.PIPE).communicate()[0]
+                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')
 

+ 25 - 0
route/go_api_recent_change.py

@@ -0,0 +1,25 @@
+from .tool.func import *
+
+def api_recent_change(db_set, num = 1, set_type = 'normal', limit = 10):
+    with get_db_connect() as conn:
+        other_set = {}
+        other_set["num"] = str(num)
+        other_set["limit"] = str(limit)
+        other_set["set_type"] = set_type
+        other_set["ip"] = ip_check()
+        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

@@ -22,5 +22,7 @@ func main() {
 		route.Api_thread(call_arg[1:])
 	} else if call_arg[0] == "api_func_ip" {
 		route.Api_func_ip(call_arg[1:])
+	} else if call_arg[0] == "api_recent_change" {
+		route.Api_recent_change(call_arg[1:])
 	}
 }

+ 96 - 0
route_go/route/api_recent_change.go

@@ -0,0 +1,96 @@
+package route
+
+import (
+	"database/sql"
+	"encoding/json"
+	"fmt"
+	"opennamu/route/tool"
+	"strconv"
+)
+
+func Api_recent_change(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()
+
+	set_type := other_set["set_type"]
+	if set_type == "edit" {
+		set_type = ""
+	}
+
+	limit_int, err := strconv.Atoi(other_set["limit"])
+	if err != nil {
+		return
+	}
+
+	if limit_int > 50 || limit_int < 0 {
+		limit_int = 50
+	}
+
+	stmt, err := db.Prepare(tool.DB_change(db_set, "select id, title from rc where type = ? order by date desc limit ?"))
+	if err != nil {
+		return
+	}
+	defer stmt.Close()
+
+	rows, err := stmt.Query(set_type, limit_int)
+	if err != nil {
+		return
+	}
+	defer rows.Close()
+
+	var id string
+	var title string
+
+	var data_list [][]string
+	admin_auth := tool.Get_admin_auth(db_set, other_set["ip"])
+
+	for rows.Next() {
+		err := rows.Scan(&id, &title)
+		if err != nil {
+			return
+		}
+
+		var date string
+		var ip string
+		var send string
+		var leng string
+		var hide string
+
+		stmt, err := db.Prepare(tool.DB_change(db_set, "select date, ip, send, leng, hide from history where id = ? and title = ?"))
+		if err != nil {
+			return
+		}
+		defer stmt.Close()
+
+		err = stmt.QueryRow(id, title).Scan(&date, &ip, &send, &leng, &hide)
+		if err != nil {
+			if err == sql.ErrNoRows {
+				date = ""
+				ip = ""
+				send = ""
+				leng = ""
+				hide = ""
+			} else {
+				return
+			}
+		}
+
+		if hide == "" || admin_auth != "" {
+			data_list = append(data_list, []string{id, title, date, tool.IP_preprocess(db_set, ip, other_set["ip"])[0], send, leng, hide, tool.IP_parser(db_set, ip, other_set["ip"])})
+		} else {
+			data_list = append(data_list, []string{"", "", "", "", "", "", hide, ""})
+		}
+	}
+
+	json_data, _ := json.Marshal(data_list)
+	fmt.Print(string(json_data))
+}

+ 1 - 1
route_go/route/tool/ip_parser.go

@@ -132,7 +132,7 @@ func IP_preprocess(db_set map[string]string, ip string, my_ip string) []string {
 
 	ip_change := ""
 	if IP_or_user(ip) {
-		if ip_view != "" {
+		if ip_view != "" && ip != my_ip {
 			hash_ip := Sha224(ip)
 			ip = hash_ip[:10]
 			ip_change = "true"

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "beta" : {
-        "r_ver" : "v3.5.0-dev11",
+        "r_ver" : "v3.5.0-dev12",
         "c_ver" : "3500374",
         "s_ver" : "3500113"
     }