Explorar o código

fix some js & api

2du %!s(int64=3) %!d(string=hai) anos
pai
achega
1897b53b94

+ 3 - 2
app.py

@@ -579,7 +579,6 @@ app.route('/api/raw/<everything:name>')(api_raw)
 app.route('/api/version', defaults = { 'version_list' : version_list })(api_version)
 app.route('/api/skin_info')(api_skin_info)
 app.route('/api/skin_info/<name>')(api_skin_info)
-app.route('/api/markup')(api_markup)
 app.route('/api/user_info/<name>', methods = ['POST', 'GET'])(api_user_info)
 app.route('/api/setting/<name>')(api_setting)
 
@@ -599,7 +598,9 @@ app.route('/api/recent_discuss/<get_type>/<int:num>')(api_recent_discuss)
 app.route('/api/recent_discuss/<int:num>')(api_recent_discuss)
 app.route('/api/recent_discuss')(api_recent_discuss)
 
-app.route('/api/sha224/<everything:data>', methods = ['POST', 'GET'])(api_sha224)
+# app.route('/api/lang/<data>', methods = ['POST', 'GET'])(api_func_lang)
+app.route('/api/sha224/<everything:data>', methods = ['POST', 'GET'])(api_func_sha224)
+
 app.route('/api/title_index')(api_title_index)
 app.route('/api/image/<everything:name>', methods = ['POST', 'GET'])(api_image_view)
 # 이건 API 영역이 아닌 것 같아서 고심 중

+ 0 - 0
route/api_func_lang.py


+ 1 - 1
route/api_sha224.py → route/api_func_sha224.py

@@ -1,6 +1,6 @@
 from .tool.func import *
 
-def api_sha224(data = 'Test'):
+def api_func_sha224(data = 'Test'):
     if flask.request.method == 'POST':
         try:
             title_list = json.loads(flask.request.form.get('title_list', ''))

+ 0 - 12
route/api_markup.py

@@ -1,12 +0,0 @@
-from .tool.func import *
-
-def api_markup():
-    with get_db_connect() as conn:
-        curs = conn.cursor()
-
-        curs.execute(db_change('select data from other where name = "markup"'))
-        rep_data = curs.fetchall()
-        if rep_data and rep_data[0][0] != '':
-            return flask.jsonify({ "markup" : rep_data[0][0] })
-        else:
-            return flask.jsonify({})

+ 53 - 75
route/api_user_info.py

@@ -15,6 +15,9 @@ def api_user_info(name = ''):
             for user_name in data_list:
                 data_result[user_name] = {}
                 
+                # name part
+                data_result[user_name]['render'] = ip_pas(user_name)
+                
                 # auth part
                 curs.execute(db_change("select data from user_set where id = ? and name = 'acl'"), [user_name])
                 db_data = curs.fetchall()
@@ -24,18 +27,62 @@ def api_user_info(name = ''):
                         if curs.fetchall():
                             data_result[user_name]['auth'] = db_data[0][0]
                         else:
-                            data_result[user_name]['auth'] = 1
+                            data_result[user_name]['auth'] = '1'
                     else:
-                        data_result[user_name]['auth'] = 1
+                        data_result[user_name]['auth'] = '1'
+                else:
+                    data_result[user_name]['auth'] = '0'
+                    
+                # ban part
+                if ban_check(name) == 0:
+                    data_result[user_name]['ban'] = '0'
                 else:
-                    data_result[user_name]['auth'] = 0
+                    data_result[user_name]['ban'] = {}
+                    regex_ban = 0
+                    
+                    curs.execute(db_change("select login, block, end, why from rb where band = 'regex' and ongoing = '1'"))
+                    for db_data in curs.fetchall():
+                        if re.compile(db_data[1]).search(user_name):
+                            regex_ban = 1
+                            
+                            data_result[user_name]['ban']['type'] = 'regex'
+                            if db_data[0] == 'O':
+                                data_result[user_name]['ban']['login_able'] = '1'
+                            else:
+                                data_result[user_name]['ban']['login_able'] = '0'
+                                
+                            if db_data[2] == '':
+                                data_result[user_name]['ban']['period'] = '0'
+                            else:
+                                data_result[user_name]['ban']['period'] = db_data[2]
+                                
+                            data_result[user_name]['ban']['reason'] = db_data[3]
+                            
+                            break
+                            
+                    if regex_ban == 0:
+                        curs.execute(db_change("select login, block, end, why from rb where block = ? and ongoing = '1'"), [user_name])
+                        db_data = curs.fetchall()
+                        if db_data:
+                            data_result[user_name]['ban']['type'] = 'normal'
+                            if db_data[0][0] == 'O':
+                                data_result[user_name]['ban']['login_able'] = '1'
+                            else:
+                                data_result[user_name]['ban']['login_able'] = '0'
+                                
+                            if db_data[0][2] == '':
+                                data_result[user_name]['ban']['period'] = '0'
+                            else:
+                                data_result[user_name]['ban']['period'] = db_data[0][2]
+                                
+                            data_result[user_name]['ban']['reason'] = db_data[0][3]
                 
                 # user document part
                 curs.execute(db_change("select title from data where title = ?"), ['user:' + user_name])
                 if curs.fetchall():
-                    data_result[user_name]['document'] = 1
+                    data_result[user_name]['document'] = '1'
                 else:
-                    data_result[user_name]['document'] = 0
+                    data_result[user_name]['document'] = '0'
 
                 # user title part
                 curs.execute(db_change('select data from user_set where name = "user_title" and id = ?'), [user_name])
@@ -47,73 +94,4 @@ def api_user_info(name = ''):
                     
             return flask.jsonify(data_result)
         else:
-            if flask.request.args.get('render', None):
-                plus_d = ''
-                plus_t = []
-
-                curs.execute(db_change("update rb set ongoing = '' where end < ? and end != '' and ongoing = '1'"), [get_time()])
-                conn.commit()
-
-                plus_d = '''
-                    <table class="user_info_table">
-                        <tbody>
-                            <tr>
-                                <td>''' + load_lang('user_name') + '''</td>
-                                <td>{}</td>
-                            </tr>
-                            <tr>
-                                <td>''' + load_lang('authority') + '''</td>
-                                <td>{}</td>
-                            </tr>
-                            <tr>
-                                <td>''' + load_lang('state') + '''</td>
-                                <td>{}</td>
-                            </tr>
-                        </tbody>
-                    </table>
-                '''
-
-                curs.execute(db_change("select data from user_set where id = ? and name = 'acl'"), [name])
-                data = curs.fetchall()
-                if data:
-                    if data[0][0] != 'user':
-                        curs.execute(db_change("select name from alist where name = ?"), [data[0][0]])
-                        if curs.fetchall():
-                            plus_t += [data[0][0]]
-                        else:
-                            plus_t += [load_lang('member')]
-                    else:
-                        plus_t += [load_lang('member')]
-                else:
-                    plus_t += [load_lang('normal')]
-
-                if ban_check(name) == 0:
-                    plus_t += [load_lang('normal')]
-                else:
-                    plus_t += [load_lang('blocked') + '<br>']
-                    regex_ban = 0
-
-                    curs.execute(db_change("select login, block, end, why from rb where band = 'regex' and ongoing = '1'"))
-                    for test_r in curs.fetchall():
-                        if re.compile(test_r[1]).search(name):
-                            plus_t[1] += load_lang('type') + ' : ' + load_lang('regex')
-                            plus_t[1] += '<br>' + load_lang('period') + ' : ' + (test_r[2] if test_r[2] != '' else load_lang('limitless'))
-                            plus_t[1] += ('<br>' + load_lang('login_able') if test_r[0] == 'O' else '')
-                            plus_t[1] += ('<br>' + load_lang('why') + ' : ' + test_r[3] if test_r[3] != '' else '')
-                            regex_ban = 1
-
-                    if regex_ban == 0:
-                        curs.execute(db_change("select end, login, band, why from rb where block = ? and ongoing = '1'"), [name])
-                        block_data = curs.fetchall()
-                        if block_data:
-                            plus_t[1] += load_lang('type') + ' : ' + (load_lang('band_blocked') if block_data[0][2] == 'O' else load_lang('normal'))
-                            plus_t[1] += (' (' + load_lang('login_able') + ')' if block_data[0][1] != '' else '')
-                            plus_t[1] += '<br>' + load_lang('period') + ' : ' + (block_data[0][0] if block_data[0][0] != '' else load_lang('limitless'))
-                            plus_t[1] += ('<br>' + load_lang('band_blocked') if block_data[0][2] == 'O' else '')
-                            plus_t[1] += ('<br>' + load_lang('why') + ' : ' + block_data[0][3] if block_data[0][3] != '' else '')
-
-                plus_d = plus_d.format(ip_pas(name), plus_t[0], plus_t[1])
-
-                return flask.jsonify({ "data" : plus_d })
-            else:
-                return flask.jsonify({})
+            return flask.jsonify({})

+ 65 - 4
views/main_css/js/func/insert_user_info.js

@@ -4,14 +4,75 @@ function do_insert_user_info() {
     if(document.getElementById('opennamu_get_user_info')) {
         let name = document.getElementById('opennamu_get_user_info').innerHTML;
         
-        let url = "/api/user_info/" + encodeURI(name) + "?render=1";
         let xhr = new XMLHttpRequest();
-        xhr.open("GET", url, true);
-        xhr.send(null);
+        xhr.open("POST", "/api/user_info/" + opennamu_do_url_encode(name));
+        xhr.send();
 
         xhr.onreadystatechange = function() {
             if(this.readyState === 4 && this.status === 200) {
-                document.getElementById('opennamu_get_user_info').innerHTML = JSON.parse(this.responseText)['data'];
+                let get_data = JSON.parse(this.responseText);
+                
+                let get_data_auth = get_data[name]['auth'];
+                if(get_data_auth === '0') {
+                    get_data_auth = 'IP';
+                } else if(get_data_auth === '1') {
+                    get_data_auth = 'USER';
+                } else {
+                    get_data_auth = get_data[name]['auth'];
+                }
+                
+                let get_data_ban = get_data[name]['ban'];
+                if(get_data_ban === '0') {
+                    get_data_ban = 'NORMAL';
+                } else {
+                    get_data_ban = 'BAN';
+                    get_data_ban += '<br>';
+                    
+                    get_data_ban += 'TYPE : ';
+                    if(get_data[name]['ban']['type'] === 'normal') {
+                        get_data_ban += 'NORMAL'; 
+                    } else {
+                    	get_data_ban += 'REGEX';
+                    }
+                    get_data_ban += '<br>';
+                    
+                    get_data_ban += 'PERIOD : ';
+                    if(get_data[name]['ban']['period'] === '0') {
+                        get_data_ban += 'INF'; 
+                    } else {
+                    	get_data_ban += get_data[name]['ban']['period'];
+                    }
+                    get_data_ban += '<br>';
+                    
+                    get_data_ban += 'LOGIN ABLE : ';
+                    if(get_data[name]['ban']['login_able'] === '1') {
+                        get_data_ban += 'YES'; 
+                    } else {
+                    	get_data_ban += 'NO';
+                    }
+                    get_data_ban += '<br>';
+                    
+                    get_data_ban += 'REASON : ' + get_data[name]['ban']['reason'];
+                }
+                
+                let data = '' +
+                    '<table class="user_info_table">' +
+                        '<tr>' +
+                            '<td>NAME</td>' +
+                            '<td>' + get_data[name]['render'] + '</td>' +
+                        '</tr>' +
+                        '<tr>' +
+                            '<td>AUTH</td>' +
+                            '<td>' + get_data_auth + '</td>' +
+                        '</tr>' +
+                        '<tr>' +
+                            '<td>STATE</td>' +
+                            '<td>' + get_data_ban + '</td>' +
+                        '</tr>' +
+                    '</table>' +
+                '';
+                
+                document.getElementById('opennamu_get_user_info').innerHTML = data;
                 
                 opennamu_do_ip_parser();
             }

+ 7 - 3
views/main_css/js/func/render_user_name.js

@@ -22,20 +22,24 @@ function opennamu_do_user_document_check() {
                 let xhr_data = JSON.parse(this.responseText);
                 
                 // user document part
-                if(xhr_data[data]['document'] === 0) {
+                if(xhr_data[data]['document'] === '0') {
                     document.getElementsByClassName('opennamu_user_link')[for_a].id = "not_thing";
                 }
                 
                 // user auth part
                 let user_data = document.getElementsByClassName('opennamu_user_link')[for_a].innerHTML;
-                if(xhr_data[data]['auth'] === 0) {
+                if(xhr_data[data]['auth'] === '0') {
                     
-                } else if(xhr_data[data]['auth'] === 1) {
+                } else if(xhr_data[data]['auth'] === '1') {
                     
                 } else {
                     user_data = '<b>' + user_data + '</b>';
                 }
                 
+                if(xhr_data[data]['ban'] != '0') {
+                    user_data = '<s>' + user_data + '</s>';
+                }
+                
                 // user title part
                 user_data = xhr_data[data]['user_title'] + user_data;
                 

+ 3 - 9
views/main_css/js/load_editor.js

@@ -133,20 +133,14 @@ function load_preview(name) {
     var s_data = new FormData();
     s_data.append('data', document.getElementById('textarea_edit_view').value);
 
-    var url = "/api/w/" + name;
-    var url_2 = "/api/markup";
-
     var xhr = new XMLHttpRequest();
-    xhr.open("POST", url, true);
+    xhr.open("POST", "/api/w/" + name);
     xhr.send(s_data);
-
-    var xhr_2 = new XMLHttpRequest();
-    xhr_2.open("GET", url_2, true);
-    xhr_2.send();
-
+    
     xhr.onreadystatechange = function() {
         if(xhr.readyState === 4 && xhr.status === 200) {
             var o_p_data = JSON.parse(xhr.responseText);
+            
             document.getElementById('see_preview').innerHTML = o_p_data['data'];
             eval(o_p_data['js_data'])
         }