Bladeren bron

임시 업로드 2

잉여개발기 1 jaar geleden
bovenliggende
commit
4cb4b2105a
7 gewijzigde bestanden met toevoegingen van 25 en 63 verwijderingen
  1. 2 2
      route/bbs_w_delete.py
  2. 2 2
      route/bbs_w_edit.py
  3. 2 2
      route/bbs_w_pinned.py
  4. 1 1
      route/bbs_w_post.py
  5. 5 2
      route/go_api_bbs_w.py
  6. 11 52
      route/tool/func.py
  7. 2 2
      route/view_raw.py

+ 2 - 2
route/bbs_w_delete.py

@@ -2,7 +2,7 @@ from .tool.func import *
 
 from .go_api_bbs_w import api_bbs_w
 
-def bbs_w_delete(bbs_num = '', post_num = '', comment_num = ''):
+async def bbs_w_delete(bbs_num = '', post_num = '', comment_num = ''):
     with get_db_connect() as conn:
         curs = conn.cursor()
 
@@ -19,7 +19,7 @@ def bbs_w_delete(bbs_num = '', post_num = '', comment_num = ''):
         if acl_check('', 'owner_auth', '') == 1:
             return redirect(conn, '/bbs/in/' + bbs_num_str)
         
-        temp_dict = orjson.loads(api_bbs_w(bbs_num_str + '-' + post_num_str).data)
+        temp_dict = await api_bbs_w(bbs_num_str + '-' + post_num_str)
         if not 'user_id' in temp_dict:
             return redirect(conn, '/bbs/main')
         

+ 2 - 2
route/bbs_w_edit.py

@@ -26,7 +26,7 @@ async def bbs_w_edit(bbs_num = '', post_num = '', comment_num = ''):
             else:
                 return redirect(conn, '/bbs/main')
         elif post_num != '':
-            temp_dict = orjson.loads(api_bbs_w(bbs_num_str + '-' + post_num_str).data)
+            temp_dict = await api_bbs_w(bbs_num_str + '-' + post_num_str)
             if 'user_id' in temp_dict:
                 if not temp_dict['user_id'] == ip and acl_check('', 'owner_auth', '', '') == 1:
                     return re_error(conn, 0)
@@ -101,7 +101,7 @@ async def bbs_w_edit(bbs_num = '', post_num = '', comment_num = ''):
                 title = ''
                 data = ''
             else:
-                temp_dict = orjson.loads(api_bbs_w(bbs_num_str + '-' + post_num_str).data)
+                temp_dict = await api_bbs_w(bbs_num_str + '-' + post_num_str)
 
                 title = temp_dict['title']
                 data = temp_dict['data']

+ 2 - 2
route/bbs_w_pinned.py

@@ -2,7 +2,7 @@ from .tool.func import *
 
 from .go_api_bbs_w import api_bbs_w
 
-def bbs_w_pinned(bbs_num = '', post_num = ''):
+async def bbs_w_pinned(bbs_num = '', post_num = ''):
     with get_db_connect() as conn:
         curs = conn.cursor()
 
@@ -19,7 +19,7 @@ def bbs_w_pinned(bbs_num = '', post_num = ''):
         if acl_check('', 'bbs_auth', '', '') == 1:
             return redirect(conn, '/bbs/in/' + bbs_num_str)
         
-        temp_dict = orjson.loads(api_bbs_w(bbs_num_str + '-' + post_num_str).data)
+        temp_dict = await api_bbs_w(bbs_num_str + '-' + post_num_str)
         if not 'user_id' in temp_dict:
             return redirect(conn, '/bbs/main')
         

+ 1 - 1
route/bbs_w_post.py

@@ -69,7 +69,7 @@ async def bbs_w_post(bbs_num = '', post_num = ''):
         bbs_comment_acl = acl_check(bbs_num_str, 'bbs_comment')
         ip = ip_check()
 
-        temp_dict = orjson.loads(api_bbs_w(bbs_num_str + '-' + post_num_str).data)
+        temp_dict = await api_bbs_w(bbs_num_str + '-' + post_num_str)
         if temp_dict == {}:
             return redirect(conn, '/bbs/main')
         

+ 5 - 2
route/go_api_bbs_w.py

@@ -1,9 +1,12 @@
 from .tool.func import *
 
-def api_bbs_w(sub_code = '', legacy = 'on'):
+async def api_bbs_w(sub_code = '', legacy = 'on'):
     other_set = {}
     other_set['ip'] = ip_check()
     other_set["legacy"] = legacy
     other_set['sub_code'] = sub_code
 
-    return flask.Response(response = python_to_golang_sync(sys._getframe().f_code.co_name, other_set), status = 200, mimetype = 'application/json')
+    return await python_to_golang(sys._getframe().f_code.co_name, other_set)
+
+async def api_bbs_w_exter(sub_code = '', legacy = 'on'):
+    return flask.Response(response = await api_bbs_w(sub_code, legacy), status = 200, mimetype = 'application/json')

+ 11 - 52
route/tool/func.py

@@ -132,42 +132,6 @@ class flask_data_or_variable:
             else:
                 return replace_data
 
-def python_to_golang_sync(func_name, other_set = {}):
-    with class_temp_db() as m_conn:
-        m_curs = m_conn.cursor()
-        
-        other_set = {
-            "url" : func_name,
-            "data" : json.dumps(other_set)
-        }
-
-        if flask.has_request_context():
-            other_set["session"] = json.dumps(dict(flask.session))
-    
-            if "Cookie" in flask.request.headers:
-                other_set["cookie"] = flask.request.headers["Cookie"]
-            else:
-                other_set["cookie"] = ""
-
-            other_set["ip"] = ip_check()
-        else:
-            other_set["session"] = "{}"
-            other_set["cookie"] = ""
-            other_set["ip"] = "127.0.0.1"
-    
-        m_curs.execute('select data from temp where name = "setup_golang_port"')
-        db_data = m_curs.fetchall()
-        db_data = db_data[0][0] if db_data else "3001"
-
-        while 1:
-            res = requests.post('http://localhost:' + db_data + '/', data = json.dumps(other_set))
-            data = res.json()
-
-            if "error" == data:
-                raise
-            else:
-                return data
-
 async def python_to_golang(func_name, other_set = {}):
     with class_temp_db() as m_conn:
         m_curs = m_conn.cursor()
@@ -969,15 +933,14 @@ def redirect(conn, data = '/'):
     return flask.redirect(load_domain(conn, 'full') + data)
     
 # Golang 의존
-def get_acl_list(type_data = 'normal'):
+async def get_acl_list(type_data = 'normal'):
     if type_data == 'user':
         type_data = 'user_document'
 
     other_set = {}
     other_set['type'] = type_data
 
-    data_str = python_to_golang_sync('api_list_acl', other_set)
-    data = orjson.loads(data_str)
+    data = await python_to_golang('api_list_acl', other_set)
 
     return data["data"]
 
@@ -1953,7 +1916,7 @@ def level_check(conn, ip = ''):
 
     return [level, exp, max_exp]
 
-def acl_check(name = '', tool = '', topic_num = '', ip = '', memo = ''):
+async def acl_check(name = '', tool = '', topic_num = '', ip = '', memo = ''):
     ip = ip_check() if ip == '' else ip
 
     other_set = {}
@@ -1962,8 +1925,7 @@ def acl_check(name = '', tool = '', topic_num = '', ip = '', memo = ''):
     other_set['topic_number'] = topic_num
     other_set['tool'] = tool
 
-    data_str = python_to_golang_sync('api_func_acl', other_set)
-    data = orjson.loads(data_str)
+    data = await python_to_golang('api_func_acl', other_set)
 
     result = 0 if data["data"] else 1
 
@@ -1972,11 +1934,11 @@ def acl_check(name = '', tool = '', topic_num = '', ip = '', memo = ''):
         other_set['ip'] = ip
         other_set['what'] = memo
 
-        python_to_golang_sync('api_func_auth_post', other_set)
+        await python_to_golang('api_func_auth_post', other_set)
 
     return result
 
-def ban_check(ip = None, tool = ''):
+async def ban_check(ip = None, tool = ''):
     ip = ip_check() if not ip else ip
     tool = '' if not tool else tool
 
@@ -1984,13 +1946,12 @@ def ban_check(ip = None, tool = ''):
     other_set['ip'] = ip
     other_set['type'] = tool
 
-    data_str = python_to_golang_sync('api_func_ban', other_set)
-    data = orjson.loads(data_str)
+    data = await python_to_golang('api_func_ban', other_set)
     data["ban"] = 1 if data["ban"] == "true" else 0
 
     return [data["ban"], data["ban_type"]]
 
-def ip_pas(raw_ip):
+async def ip_pas(raw_ip):
     other_set = {}
     other_set["ip"] = ip_check()
     
@@ -2004,9 +1965,7 @@ def ip_pas(raw_ip):
     for for_a in range(1, len(get_ip) + 1):
         other_set["data_" + str(for_a)] = get_ip[for_a - 1]
 
-    data_str = python_to_golang_sync('api_func_ip_post', other_set)
-    data = orjson.loads(data_str)
-
+    data = await python_to_golang('api_func_ip_post', other_set)
     return data["data"][raw_ip] if return_data == 1 else data["data"]
         
 # Func-edit
@@ -2205,13 +2164,13 @@ def do_reload_recent_thread(conn, topic_num, date, name = None, sub = None):
     else:
         curs.execute(db_change("insert into rd (title, sub, code, date, band, stop, agree, acl) values (?, ?, ?, ?, '', '', '', '')"), [name, sub, topic_num, date])
 
-def add_alarm(to_user, from_user, context):
+async def add_alarm(to_user, from_user, context):
     other_set = {}
     other_set['to'] = to_user
     other_set['from'] = from_user
     other_set['data'] = context
 
-    python_to_golang_sync('api_func_alarm_post', other_set)
+    await python_to_golang('api_func_alarm_post', other_set)
 
 def add_user(conn, user_name, user_pw, user_email = '', user_encode = ''):
     curs = conn.cursor()

+ 2 - 2
route/view_raw.py

@@ -68,9 +68,9 @@ async def view_raw(name = '', topic_num = '', num = '', doc_acl = 0, bbs_num = '
         if bbs_num != '' and post_num != '':
             if comment_num != '':
                 data = await api_bbs_w_comment_one(bbs_num_str + '-' + post_num_str + '-' + comment_num)
-                sub_data = orjson.loads(api_bbs_w(bbs_num_str + '-' + post_num_str).data)
+                sub_data = await api_bbs_w(bbs_num_str + '-' + post_num_str)
             else:
-                data = orjson.loads(api_bbs_w(bbs_num_str + '-' + post_num_str).data)
+                data = await api_bbs_w(bbs_num_str + '-' + post_num_str)
                 
             if 'comment' in data:
                 v_name = sub_data["title"]