Przeglądaj źródła

그냥 일관되게 다시 변경, 필요하면 Go로 짜는 게 맞는 듯

잉여개발기 (SPDV) 2 lat temu
rodzic
commit
be2a3375a3

+ 6 - 8
route/api_bbs_w_comment.py

@@ -1,20 +1,18 @@
 from .tool.func import *
 
-def api_bbs_w_comment(sub_code : str = '') -> typing.Union[str, flask.Response, werkzeug.wrappers.response.Response]:
-    conn : typing.Union[sqlite3.Connection, pymysql.connections.Connection]
+def api_bbs_w_comment(sub_code = ''):
     with get_db_connect() as conn:
-        curs : typing.Union[sqlite3.Cursor, pymysql.cursors.Cursor] = conn.cursor()
+        curs = conn.cursor()
 
         curs.execute(db_change('select set_name, set_data, set_code, set_id from bbs_data where (set_name = "comment" or set_name = "comment_date" or set_name = "comment_user_id") and set_id = ? order by set_code + 0 asc'), [sub_code])
-        db_data : typing.Optional[typing.List[typing.Tuple[str, str, str]]] = curs.fetchall()
+        db_data = curs.fetchall()
         if not db_data:
             return flask.jsonify({})
         else:
-            temp_id : str = ''
-            temp_dict : dict[str, str] = {}
-            temp_list : typing.List[dict[str, str]] = []
+            temp_id = ''
+            temp_dict = {}
+            temp_list = []
 
-            for_a : typing.Tuple[str, str, str]
             for for_a in db_data:
                 if temp_id != for_a[2]:
                     if temp_dict != {}:

+ 6 - 8
route/api_bbs_w_post.py

@@ -1,23 +1,21 @@
 from .tool.func import *
 
-def api_bbs_w_post(sub_code : str = '') -> typing.Union[str, flask.Response, werkzeug.wrappers.response.Response]:
-    sub_code_split : typing.List[str] = sub_code.split('-')
+def api_bbs_w_post(sub_code = ''):
+    sub_code_split = sub_code.split('-')
     if len(sub_code_split) < 2:
         sub_code_split = ['', '']
 
-    conn : typing.Union[sqlite3.Connection, pymysql.connections.Connection]
     with get_db_connect() as conn:
-        curs : typing.Union[sqlite3.Cursor, pymysql.cursors.Cursor] = conn.cursor()
+        curs = conn.cursor()
 
         curs.execute(db_change('select set_name, set_data, set_code from bbs_data where set_id = ? and set_code = ?'), [sub_code_split[0], sub_code_split[1]])
-        db_data : typing.Optional[typing.List[typing.Tuple[str, str, str]]] = curs.fetchall()
+        db_data = curs.fetchall()
         if not db_data:
             return flask.jsonify({})
         else:
-            temp_id : str = ''
-            temp_dict : dict[str, str] = {}
+            temp_id = ''
+            temp_dict = {}
 
-            for_a : typing.Tuple[str, str, str]
             for for_a in db_data:
                 if temp_id != for_a[2]:
                     temp_id = for_a[2]

+ 38 - 51
route/bbs_w_post.py

@@ -4,7 +4,7 @@ from .api_bbs_w_post import api_bbs_w_post
 from .api_bbs_w_comment import api_bbs_w_comment
 from .edit import edit_editor
 
-def bbs_w_post_make_thread(user_id : str, date : str, data : str, code : str, color : str = '', blind : str = '', add_style : str = '') -> str:
+def bbs_w_post_make_thread(user_id, date, data, code, color = '', blind = '', add_style = ''):
     if blind != '':
         if data == '':
             color_b = 'opennamu_comment_blind'
@@ -30,28 +30,27 @@ def bbs_w_post_make_thread(user_id : str, date : str, data : str, code : str, co
         </table>
     '''
 
-def bbs_w_post_comment(user_id : str, sub_code : str, comment_num : str, bbs_num_str : str, post_num_str : str) -> typing.Tuple[str, str, int, int]:
-    comment_data : str = ''
-    comment_select : str = ''
+def bbs_w_post_comment(user_id, sub_code, comment_num, bbs_num_str, post_num_str):
+    comment_data = ''
+    comment_select = ''
 
-    comment_count : int = 0
-    comment_add_count : int = 0
+    comment_count = 0
+    comment_add_count = 0
 
-    thread_data : typing.List[dict[str, str]] = json.loads(api_bbs_w_comment(sub_code).data)
+    thread_data = json.loads(api_bbs_w_comment(sub_code).data)
     
     comment_count += len(thread_data)
     comment_add_count += comment_count
 
-    temp_dict : dict[str, str]
     for temp_dict in thread_data:
-        color : str = 'default'
+        color = 'default'
         if user_id == temp_dict['comment_user_id']:
             color = 'green'
 
-        sub_code_check : str = re.sub(r'^[0-9]+-[0-9]+-', '', sub_code + '-' + temp_dict['code'])
-        margin_count : int = sub_code_check.count('-')
+        sub_code_check = re.sub(r'^[0-9]+-[0-9]+-', '', sub_code + '-' + temp_dict['code'])
+        margin_count = sub_code_check.count('-')
 
-        date : str = ''
+        date = ''
         date += '<a href="javascript:opennamu_change_comment(\'' + sub_code_check + '\');">(' + load_lang('comment') + ')</a> '
         date += '<a href="/bbs/w/' + bbs_num_str + '/' + post_num_str + '/comment/' + sub_code_check + '/tool">(' + load_lang('tool') + ')</a> '
         date += temp_dict['comment_date']
@@ -69,14 +68,14 @@ def bbs_w_post_comment(user_id : str, sub_code : str, comment_num : str, bbs_num
             add_style = 'width: calc(100% - ' + str(margin_count * 20) + 'px);'
         )
 
-        comment_default : str = ''
+        comment_default = ''
         if comment_num == sub_code_check:
             comment_default = 'selected'
 
         comment_select += '<option value="' + sub_code_check + '" ' + comment_default + '>' + sub_code_check + '</option>'
         comment_data += '<hr class="main_hr">'
 
-        temp_data : typing.Tuple[str, str, int, int] = bbs_w_post_comment(user_id, sub_code + '-' + temp_dict['code'], comment_num, bbs_num_str, post_num_str)
+        temp_data = bbs_w_post_comment(user_id, sub_code + '-' + temp_dict['code'], comment_num, bbs_num_str, post_num_str)
 
         comment_data += temp_data[0]
         comment_select += temp_data[1]
@@ -84,40 +83,28 @@ def bbs_w_post_comment(user_id : str, sub_code : str, comment_num : str, bbs_num
 
     return (comment_data, comment_select, comment_count, comment_add_count)
 
-def bbs_w_post(bbs_num : typing.Union[int, str] = '', post_num : typing.Union[int, str] = '', do_type : str = '') -> typing.Union[str, flask.Response, werkzeug.wrappers.response.Response]:
-    conn : typing.Union[sqlite3.Connection, pymysql.connections.Connection]
+def bbs_w_post(bbs_num = '', post_num = '', do_type = ''):
     with get_db_connect() as conn:
-        curs : typing.Union[sqlite3.Cursor, pymysql.cursors.Cursor] = conn.cursor()
+        curs = conn.cursor()
 
         curs.execute(db_change('select set_data from bbs_set where set_id = ? and set_name = "bbs_name"'), [bbs_num])
-        db_data_3 : typing.Optional[typing.List[typing.Tuple[str]]] = curs.fetchall()
+        db_data_3 = curs.fetchall()
         if not db_data_3:
             return redirect('/bbs/main')
         
-        bbs_name : str = db_data_3[0][0]
-
-        bbs_num_str : str = str(bbs_num)
-        post_num_str : str = str(post_num)
-        bbs_comment_acl : int = acl_check(bbs_num_str, 'bbs_comment')
-        ip : str = ip_check()
-
-        set_id : str
-        text : str
-        data_preview : str
-        user_id : str
-        bbs_comment_form : str
-        id_data : str
-        data : str
-        date : str
-        temp_dict : dict[str, str]
-        new_id_data : str
+        bbs_name = db_data_3[0][0]
+
+        bbs_num_str = str(bbs_num)
+        post_num_str = str(post_num)
+        bbs_comment_acl = acl_check(bbs_num_str, 'bbs_comment')
+        ip = ip_check()
 
         temp_dict = json.loads(api_bbs_w_post(bbs_num_str + '-' + post_num_str).data)
         if temp_dict == {}:
             return redirect('/bbs/main')
         
         curs.execute(db_change('select set_data from bbs_set where set_id = ? and set_name = "bbs_type"'), [bbs_num])
-        db_data_2 : typing.Optional[typing.List[typing.Tuple[str]]] = curs.fetchall()
+        db_data_2 = curs.fetchall()
         if not db_data_2:
             return redirect('/bbs/main')
         elif db_data_2[0][0] == 'thread':
@@ -133,7 +120,7 @@ def bbs_w_post(bbs_num : typing.Union[int, str] = '', post_num : typing.Union[in
                 set_id = bbs_num_str + '-' + post_num_str
 
                 curs.execute(db_change('select set_code from bbs_data where set_name = "comment" and set_id = ? order by set_code + 0 desc'), [set_id])
-                db_data_4 : typing.Optional[typing.List[typing.Tuple[str]]] = curs.fetchall()
+                db_data_4 = curs.fetchall()
                 id_data = str(int(db_data_4[0][0]) + 1) if db_data_4 else '1'
 
                 data = flask.request.form.get('content', '')
@@ -191,9 +178,9 @@ def bbs_w_post(bbs_num : typing.Union[int, str] = '', post_num : typing.Union[in
                 data += '<hr class="main_hr">'
 
                 user_id = temp_dict['user_id']
-                count : int = 1
+                count = 1
 
-                thread_data : typing.List[dict[str, str]] = json.loads(api_bbs_w_comment(bbs_num_str + '-' + post_num_str).data)
+                thread_data = json.loads(api_bbs_w_comment(bbs_num_str + '-' + post_num_str).data)
                 for temp_dict in thread_data:
                     count += 1
                     if user_id == temp_dict['comment_user_id']:
@@ -254,16 +241,16 @@ def bbs_w_post(bbs_num : typing.Union[int, str] = '', post_num : typing.Union[in
                 else:
                     captcha_post('', 0)
                 
-                select : str = flask.request.form.get('comment_select', '0')
+                select = flask.request.form.get('comment_select', '0')
                 select = '' if select == '0' else select
 
-                comment_user_name : str = ''
+                comment_user_name = ''
 
                 if select != '':
-                    select_split : typing.List[str] = select.split('-')
+                    select_split = select.split('-')
                     if len(select_split) < 2:
                         curs.execute(db_change('select set_data from bbs_data where set_name = "comment_user_id" and set_id = ? and set_code = ? limit 1'), [bbs_num_str + '-' + post_num_str, select_split[0]])    
-                        db_data_6 : typing.Optional[typing.List[typing.Tuple[str]]] = curs.fetchall()
+                        db_data_6 = curs.fetchall()
                         if not db_data_6:
                             # re_error로 변경 예정
                             return redirect('/bbs/w/' + bbs_num_str + '/' + post_num_str)
@@ -272,7 +259,7 @@ def bbs_w_post(bbs_num : typing.Union[int, str] = '', post_num : typing.Union[in
                             comment_user_name = db_data_6[0][0]
                     else:
                         curs.execute(db_change('select set_data from bbs_data where set_name = "comment_user_id" and set_id = ? and set_code = ? limit 1'), [bbs_num_str + '-' + post_num_str + '-' + '-'.join(select_split[0:len(select_split) - 1]), select_split[len(select_split) - 1]])
-                        db_data_7 : typing.Optional[typing.List[typing.Tuple[str]]] = curs.fetchall()
+                        db_data_7 = curs.fetchall()
                         if not db_data_7:
                             return redirect('/bbs/w/' + bbs_num_str + '/' + post_num_str)
                         else:
@@ -282,7 +269,7 @@ def bbs_w_post(bbs_num : typing.Union[int, str] = '', post_num : typing.Union[in
                     set_id = bbs_num_str + '-' + post_num_str
 
                 curs.execute(db_change('select set_code from bbs_data where set_name = "comment" and set_id = ? order by set_code + 0 desc limit 1'), [set_id])
-                db_data_5 : typing.Optional[typing.List[typing.Tuple[str]]] = curs.fetchall()
+                db_data_5 = curs.fetchall()
                 id_data = str(int(db_data_5[0][0]) + 1) if db_data_5 else '1'
 
                 data = flask.request.form.get('content', '')
@@ -315,7 +302,7 @@ def bbs_w_post(bbs_num : typing.Union[int, str] = '', post_num : typing.Union[in
                     return re_error('/ban')
                     
                 text = ''
-                comment_num : str = ''
+                comment_num = ''
                 data_preview = ''
                 if do_type == 'preview':
                     text = flask.request.form.get('content', '')
@@ -347,15 +334,15 @@ def bbs_w_post(bbs_num : typing.Union[int, str] = '', post_num : typing.Union[in
                 )
 
                 user_id = temp_dict['user_id']
-                comment_data : str = ''
+                comment_data = ''
 
-                comment_select : str = '<select id="opennamu_comment_select" name="comment_select">'
+                comment_select = '<select id="opennamu_comment_select" name="comment_select">'
                 comment_select += '<option value="0">' + load_lang('normal') + '</option>'
 
-                comment_count : int = 0
-                comment_add_count : int = 0
+                comment_count = 0
+                comment_add_count = 0
 
-                temp_data : typing.Tuple[str, str, int, int] = bbs_w_post_comment(user_id, bbs_num_str + '-' + post_num_str, comment_num, bbs_num_str, post_num_str)
+                temp_data = bbs_w_post_comment(user_id, bbs_num_str + '-' + post_num_str, comment_num, bbs_num_str, post_num_str)
 
                 comment_data += temp_data[0]
                 comment_select += temp_data[1]

+ 8 - 11
route/edit_delete_file.py

@@ -2,27 +2,24 @@ from .tool.func import *
 
 from .edit_delete import edit_delete
 
-# 처음으로 차세대 코드 방법론 적용
-# 앞으로 다 이렇게 작성할 예정
-def edit_delete_file(name : str = 'test.jpg') -> typing.Union[str, flask.Response, werkzeug.wrappers.response.Response]:
-    conn : typing.Union[sqlite3.Connection, pymysql.connections.Connection]
+def edit_delete_file(name = 'test.jpg'):
     with get_db_connect() as conn:
-        curs : typing.Union[sqlite3.Cursor, pymysql.cursors.Cursor] = conn.cursor()
+        curs = conn.cursor()
 
-        ip : str = ip_check()
+        ip = ip_check()
         if admin_check() == 0:
             return re_error('/ban')
 
-        mime_type : typing.Optional[re.Match] = re.search(r'([^.]+)$', name)
-        mime_type_str : str = 'jpg'
+        mime_type = re.search(r'([^.]+)$', name)
+        mime_type_str = 'jpg'
         if mime_type:
             mime_type_str = mime_type.group(1).lower()
 
-        file_name : str = re.sub(r'\.([^.]+)$', '', name)
+        file_name = re.sub(r'\.([^.]+)$', '', name)
         file_name = re.sub(r'^file:', '', file_name)
 
-        file_all_name : str = sha224_replace(file_name) + '.' + mime_type_str
-        file_directory : str = os.path.join(load_image_url(), file_all_name)
+        file_all_name = sha224_replace(file_name) + '.' + mime_type_str
+        file_directory = os.path.join(load_image_url(), file_all_name)
 
         if not os.path.exists(file_directory):
             return redirect('/w/' + url_pas(name))

+ 3 - 0
views/main_css/js/func/check_new_thread.ts

@@ -0,0 +1,3 @@
+function opennamu_check_new_thread(do_type : string = '') {
+    
+}

+ 0 - 0
views/main_css/js/route/thread.ts