Jelajahi Sumber

게시판 조회수 추가

잉여개발기 5 bulan lalu
induk
melakukan
96fd375759
6 mengubah file dengan 44 tambahan dan 28 penghapusan
  1. 7 1
      app.py
  2. 0 1
      route/__init__.py
  3. 7 1
      route/bbs_w_post.py
  4. 0 7
      route/go_api_w_page_view.py
  5. 26 7
      route/tool/func.py
  6. 4 11
      route/view_w.py

+ 7 - 1
app.py

@@ -933,15 +933,21 @@ app.route('/api/v2/bbs')(api_bbs_list)
 app.route('/api/v2/bbs/main')(api_bbs_exter)
 app.route('/api/v2/bbs/set/<int:bbs_num>/<name>', methods = ['GET', 'PUT'])(api_bbs_w_set)
 app.route('/api/v2/bbs/in/<int:bbs_num>/<int:page>')(api_bbs_exter)
+
 app.route('/api/v2/bbs/w/<sub_code>', defaults = { 'legacy' : '' })(api_bbs_w)
 app.route('/api/v2/bbs/w/tabom/<sub_code>', methods = ['GET', 'POST'])(api_bbs_w_tabom)
 app.route('/api/v2/bbs/w/comment/<sub_code>/<tool>', defaults = { 'legacy' : '' })(api_bbs_w_comment_exter)
 app.route('/api/v2/bbs/w/comment_one/<sub_code>/<tool>', defaults = { 'legacy' : '' })(api_bbs_w_comment_one_exter)
 
+app.route('/api/v2/bbs/w/page_view/<set_id>/<set_code>')(golang_view())
+app.route('/api/v2/bbs/w/page_view_post/<set_id>/<set_code>')(golang_view())
+
 app.route('/api/v2/doc_star_doc/<int:num>/<everything:name>', defaults = { 'do_type' : 'star_doc' })(api_w_watch_list)
 app.route('/api/v2/doc_watch_list/<int:num>/<everything:name>')(api_w_watch_list)
 app.route('/api/v2/set_reset/<everything:name>')(api_w_set_reset)
-app.route('/api/v2/page_view/<everything:name>')(api_w_page_view)
+
+app.route('/api/v2/page_view/<everything:name>')(golang_view())
+app.route('/api/v2/page_view_post/<everything:name>')(golang_view())
 
 app.route('/api/v2/setting/<name>', methods = ['GET', 'PUT'])(api_setting_exter)
 

+ 0 - 1
route/__init__.py

@@ -213,6 +213,5 @@ from route.go_api_w_xref import api_w_xref
 from route.go_api_w_watch_list import api_w_watch_list
 from route.go_api_w_render import api_w_render, api_w_render_exter
 from route.go_api_w_set_reset import api_w_set_reset
-from route.go_api_w_page_view import api_w_page_view
 
 from route.go_main_func_easter_egg import main_func_easter_egg

+ 7 - 1
route/bbs_w_post.py

@@ -208,10 +208,16 @@ async def bbs_w_post(bbs_num = '', post_num = ''):
                         ''' + bbs_comment_form + '''
                     </form>
                 '''
+                
+                await python_to_golang("get_json", path = "v2/bbs/w/page_view_post/" + url_pas(bbs_num_str) + "/" + url_pas(post_num_str))
+
+                view_count_data = await python_to_golang("get_json", path = "v2/bbs/w/page_view/" + url_pas(bbs_num_str) + "/" + url_pas(post_num_str))
+                view_count = view_count_data['data']
 
                 return await render_template(
                     bbs_name,
                     data,
                     '(' + await get_lang('bbs') + ')',
-                    [['bbs/in/' + bbs_num_str, await get_lang('return')], ['bbs/edit/' + bbs_num_str + '/' + post_num_str, await get_lang('edit')], ['bbs/tool/' + bbs_num_str + '/' + post_num_str, await get_lang('tool')]]
+                    [['bbs/in/' + bbs_num_str, await get_lang('return')], ['bbs/edit/' + bbs_num_str + '/' + post_num_str, await get_lang('edit')], ['bbs/tool/' + bbs_num_str + '/' + post_num_str, await get_lang('tool')]],
+                    [temp_dict['date'], 0, 0, view_count],
                 )

+ 0 - 7
route/go_api_w_page_view.py

@@ -1,7 +0,0 @@
-from .tool.func import *
-
-async def api_w_page_view(name = 'Test'):
-    other_set = {}
-    other_set["doc_name"] = name
-
-    return flask.jsonify(await python_to_golang(sys._getframe().f_code.co_name, other_set))

+ 26 - 7
route/tool/func.py

@@ -108,7 +108,7 @@ async def render_template(name, data, sub, menu, other = []):
     other_set["sub"] = [sub] + other
     other_set["menu"] = menu
 
-    return await python_to_golang("template", other_set)
+    return await python_to_golang("post", other_set = other_set, path = "template")
 
 global_lang_data = {}
 global_some_set = {}
@@ -147,7 +147,7 @@ def global_some_set_do(set_name, data = None):
     else:
         return None
 
-async def python_to_golang(func_name, other_set = {}):    
+async def python_to_golang(func_name, other_set = {}, path = ''):    
     headers = {}
     if flask.has_request_context():
         if "Cookie" in flask.request.headers:
@@ -171,12 +171,31 @@ async def python_to_golang(func_name, other_set = {}):
                     data = await res.text()
 
                     return data
-    elif func_name == "template":
-        async with aiohttp.ClientSession() as session:
-            async with session.post('http://localhost:' + port_data + "/api/template", data = json_dumps(other_set), headers = headers) as res:
-                data = await res.text()
+    elif path != "":
+        if func_name == "get":
+            async with aiohttp.ClientSession() as session:
+                async with session.get('http://localhost:' + port_data + "/api/" + path, headers = headers) as res:
+                    data = await res.text()
+
+                    return data
+        elif func_name == "post":
+            async with aiohttp.ClientSession() as session:
+                async with session.post('http://localhost:' + port_data + "/api/" + path, data = json_dumps(other_set), headers = headers) as res:
+                    data = await res.text()
 
-                return data
+                    return data
+        elif func_name == "get_json":
+            async with aiohttp.ClientSession() as session:
+                async with session.get('http://localhost:' + port_data + "/api/" + path, headers = headers) as res:
+                    data = await res.json()
+
+                    return data
+        else:
+            async with aiohttp.ClientSession() as session:
+                async with session.post('http://localhost:' + port_data + "/api/" + path, data = json_dumps(other_set), headers = headers) as res:
+                    data = await res.json()
+
+                    return data
     else:
         async with aiohttp.ClientSession() as session:
             async with session.post('http://localhost:' + port_data + '/compatible_api/' + func_name, data = json_dumps(other_set), headers = headers) as res:

+ 4 - 11
route/view_w.py

@@ -2,7 +2,6 @@ from .tool.func import *
 
 from .go_api_w_raw import api_w_raw
 from .go_api_w_render import api_w_render
-from .go_api_w_page_view import api_w_page_view
 
 async def view_w(name = 'Test', do_type = '', doc_rev = ''):
     with get_db_connect() as conn:
@@ -197,7 +196,7 @@ async def view_w(name = 'Test', do_type = '', doc_rev = ''):
             end_data = ''
 
         if doc_rev == '':
-            await api_w_page_view(name)
+            await python_to_golang("get_json", path = "v2/page_view_post/" + url_pas(name))
             curs.execute(db_change("select data from data where title = ?"), [name])
         else:
             curs.execute(db_change("select data from history where title = ? and id = ?"), [name, doc_rev])
@@ -320,15 +319,6 @@ async def view_w(name = 'Test', do_type = '', doc_rev = ''):
         r_date = curs.fetchall()
         r_date = r_date[0][0] if r_date else 0
 
-        curs.execute(db_change("select data from other where name = 'not_use_view_count'"))
-        view_count_set = curs.fetchall()
-        if view_count_set and view_count_set[0][0] != "":
-            view_count = 0
-        else:
-            curs.execute(db_change("select set_data from data_set where doc_name = ? and set_name = 'view_count' and doc_rev = ''"), [name])
-            view_count = curs.fetchall()
-            view_count = view_count[0][0] if view_count else 0
-
         div = file_data + user_doc + end_data + category_total
         
         if doc_type == '':
@@ -366,6 +356,9 @@ async def view_w(name = 'Test', do_type = '', doc_rev = ''):
         if doc_rev != '':
             sub = '(' + str(doc_rev) + ')'
 
+        view_count_data = await python_to_golang("get_json", path = "v2/page_view/" + url_pas(name))
+        view_count = view_count_data['data']
+
         return await render_template(
             name_view,
             div,