Browse Source

Merge pull request #744 from visuddhinanda/laravel

🐛 选经界面术语显示不出来
visuddhinanda 4 years ago
parent
commit
0f83d4c079

+ 33 - 0
app/Http/Controllers/DhammaTermController.php

@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
 
 
 use App\Models\DhammaTerm;
 use App\Models\DhammaTerm;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\DB;
 
 
 class DhammaTermController extends Controller
 class DhammaTermController extends Controller
 {
 {
@@ -50,6 +52,37 @@ class DhammaTermController extends Controller
 									->orderBy('created_at','desc')
 									->orderBy('created_at','desc')
 									->get();
 									->get();
 				break;
 				break;
+            case 'hot-meaning':
+                $key='term/hot_meaning';
+                $value = Cache::get($key, function()use($request) {
+                    $hotMeaning=[];
+                    $words = DhammaTerm::select('word')
+                                ->where('language',$request->get("language"))
+                                ->groupby('word')
+                                ->get();
+                    
+                    foreach ($words as $key => $word) {
+                        # code...
+                        $result = DhammaTerm::select(DB::raw('count(*) as word_count, meaning'))
+                                ->where('language',$request->get("language"))
+                                ->where('word',$word['word'])
+                                ->groupby('meaning')
+                                ->orderby('word_count','desc')
+                                ->first();
+                        if($result){
+                            $hotMeaning[]=[
+                                'word'=>$word['word'],
+                                'meaning'=>$result['meaning'],
+                                'language'=>$request->get("language"),
+                                'owner'=>'',
+                            ];
+                        }
+                    }
+                    Cache::put($key, $hotMeaning, 3600);
+                    return $hotMeaning;
+                });
+                return $this->ok(["rows"=>$value,"count"=>count($value)]);
+                break;
 			default:
 			default:
 				# code...
 				# code...
 				break;
 				break;

+ 10 - 0
deploy/mint.yml

@@ -19,3 +19,13 @@
 - hosts: db
 - hosts: db
   roles:
   roles:
     - mint-db
     - mint-db
+
+- hosts: zone
+  roles:
+    - mint-zone
+    - certbot-nginx
+
+- hosts: main
+  roles:
+    - mint-main
+    - certbot-nginx

+ 1 - 1
deploy/roles/certbot-nginx/tasks/main.yml

@@ -7,7 +7,7 @@
 - name: add Let's Encrypt support
 - name: add Let's Encrypt support
   become: true
   become: true
   ansible.builtin.shell:
   ansible.builtin.shell:
-    cmd: certbot --nginx --non-interactive --agree-tos -m {{ app_master_email }} --domains {{ inventory_hostname }} --redirect
+    cmd: certbot --nginx --non-interactive --agree-tos -m {{ app_master_email }} --domains {{ inventory_hostname }} "{{ '--redirect' if app_nginx_force_https else '' }}"
 
 
 - name: restart nginx
 - name: restart nginx
   become: true
   become: true

+ 2 - 2
deploy/roles/mint-clone/templates/config-v1.js.j2

@@ -1,4 +1,4 @@
-var RPC_SERVER="https://rpc.wikipali.org";
+var RPC_SERVER="https://{{ app_rpc_host }}";
 
 
 /*
 /*
   |---------------
   |---------------
@@ -11,4 +11,4 @@ var RPC_SERVER="https://rpc.wikipali.org";
   |------------------------
   |------------------------
 */
 */
 
 
-var ASSETS_SERVER = "https://assets-{{ app_cluster_id }}.wikipali.org"
+var ASSETS_SERVER = "https://assets-{{ app_cluster_domain }}"

+ 3 - 3
deploy/roles/mint-clone/templates/config-v1.php.j2

@@ -1,8 +1,8 @@
 <?php
 <?php
 
 
 #域名设置
 #域名设置
-define("RPC_SERVER","https://rpc.wikipali.org");
-define("ASSETS_SERVER","https://assets-{{ app_cluster_id }}.wikipali.org");
+define("RPC_SERVER","https://{{ app_rpc_host }}");
+define("ASSETS_SERVER","https://assets-{{ app_cluster_domain }}");
 /*
 /*
 电子邮件设置
 电子邮件设置
 PHPMailer
 PHPMailer
@@ -38,7 +38,7 @@ define("Redis",[
 	"host" => "{{ app_redis_host }}",
 	"host" => "{{ app_redis_host }}",
 	"port" => 6379,
 	"port" => 6379,
 	"password" => "",
 	"password" => "",
-	"prefix"=>"mint://"
+	"namespace" => "{{ app_redis_namespace }}"
 ]);
 ]);
 
 
 # 雪花id
 # 雪花id

+ 3 - 2
deploy/roles/mint-clone/templates/env-v2.j2

@@ -31,6 +31,7 @@ MEMCACHED_HOST=127.0.0.1
 REDIS_HOST={{ app_redis_host }}
 REDIS_HOST={{ app_redis_host }}
 REDIS_PASSWORD=null
 REDIS_PASSWORD=null
 REDIS_PORT=6379
 REDIS_PORT=6379
+REDIS_NAMESPACE="{{ app_redis_namespace }}"
 
 
 MAIL_MAILER=smtp
 MAIL_MAILER=smtp
 MAIL_HOST=smtp.gmail.com
 MAIL_HOST=smtp.gmail.com
@@ -55,7 +56,7 @@ PUSHER_APP_CLUSTER=mt1
 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
 MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
 MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
 
 
-ASSETS_SERVER="https://assets-{{ app_cluster_id }}.wikipali.org"
-RPC_SERVER="https://rpc.wikipali.org"
+ASSETS_SERVER="https://assets-{{ app_cluster_domain }}"
+RPC_SERVER="https://{{ app_rpc_host }}"
 SNOWFLAKE_DATA_CENTER_ID=1
 SNOWFLAKE_DATA_CENTER_ID=1
 SNOWFLAKE_WORKER_ID=1
 SNOWFLAKE_WORKER_ID=1

+ 27 - 0
deploy/roles/mint-main/tasks/main.yml

@@ -0,0 +1,27 @@
+- name: Creates deploy directory
+  become: true
+  file:
+    path: "{{ app_deploy_target }}"
+    state: directory
+    owner: "{{ ansible_user }}"
+
+- name: upload index.html
+  ansible.builtin.template:
+    src: index.html.j2
+    dest: "{{ app_deploy_target }}/index.html"
+    mode: '0444'
+
+- name: Create a current link
+  ansible.builtin.file:
+    src: "{{ app_deploy_target }}"
+    dest: /var/www/{{ inventory_hostname }}/current
+    state: link
+
+- name: upload nginx.conf
+  become: true
+  ansible.builtin.template:
+    src: nginx.conf.j2
+    dest: "/etc/nginx/sites-enabled/{{ inventory_hostname }}.conf"
+    owner: www-data
+    group: www-data
+    mode: '0400'

+ 8 - 0
deploy/roles/mint-main/templates/index.html.j2

@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta http-equiv="refresh" content="0; url='https://www-{{ app_cluster_domain }}'" />
+  </head>
+  <body>
+  </body>
+</html>

+ 14 - 0
deploy/roles/mint-main/templates/nginx.conf.j2

@@ -0,0 +1,14 @@
+server {
+    listen 80;
+    listen [::]:80;
+
+    gzip on;
+    server_name {{ inventory_hostname }};
+    root {{ app_deploy_target }};
+    client_max_body_size 16M;
+    index index.html;
+    charset utf-8;
+
+    access_log off;
+    error_log /var/log/nginx/{{ inventory_hostname }}.error.log warn;
+}

+ 1 - 1
deploy/roles/mint-www/templates/nginx.conf.j2

@@ -8,7 +8,7 @@ server {
     add_header X-Content-Type-Options "nosniff";
     add_header X-Content-Type-Options "nosniff";
 
 
     gzip on;
     gzip on;
-    server_name {{ inventory_hostname }};
+    server_name {{ inventory_hostname }} {% for it in groups['zone'] %} {{ it }} {% endfor %};
     root {{ app_deploy_target }}/public;
     root {{ app_deploy_target }}/public;
     client_max_body_size 16M;
     client_max_body_size 16M;
     index index.php;
     index index.php;

+ 8 - 0
deploy/roles/mint-zone/tasks/main.yml

@@ -0,0 +1,8 @@
+- name: upload nginx.conf
+  become: true
+  ansible.builtin.template:
+    src: nginx.conf.j2
+    dest: "/etc/nginx/sites-enabled/{{ inventory_hostname }}.conf"
+    owner: www-data
+    group: www-data
+    mode: '0400'

+ 24 - 0
deploy/roles/mint-zone/templates/nginx.conf.j2

@@ -0,0 +1,24 @@
+upstream {{ app_cluster_domain }} {
+{% for it in groups['www'] %}
+    server {{ it }};
+{% endfor %}
+    fair;
+}
+
+server {
+    listen 80;
+    listen [::]:80;
+
+    gzip on;
+    server_name {{ inventory_hostname }};
+    client_max_body_size 16M;
+    charset utf-8;
+
+    access_log off;
+    error_log /var/log/nginx/{{ inventory_hostname }}.error.log warn;
+
+    location / {
+        proxy_set_header Host $host;
+        proxy_pass http://{{ app_cluster_domain }};
+    }
+}

+ 0 - 1
deploy/roles/os/tasks/main.yml

@@ -1,4 +1,3 @@
-- import_tasks: init.yml
 - import_tasks: sshd.yml
 - import_tasks: sshd.yml
 - import_tasks: ulimits.yml
 - import_tasks: ulimits.yml
 
 

+ 0 - 0
deploy/roles/os/tasks/init.yml → deploy/roles/ubuntu/tasks/init.yml


+ 26 - 4
deploy/roles/ubuntu/tasks/main.yml

@@ -19,6 +19,20 @@
 #     state: absent
 #     state: absent
 #     path: /etc/apt/sources.list.d
 #     path: /etc/apt/sources.list.d
 
 
+- import_tasks: init.yml
+
+# https://github.com/nodesource/distributions#deb
+# - name: Download nodejs-ppa installer
+#   get_url:
+#     url: https://deb.nodesource.com/setup_lts.x
+#     dest: "{{ app_downloads }}/setup_node_lts.sh"
+#     mode: '0755'
+
+# - name: Install nodejs ppa
+#   become: true
+#   ansible.builtin.shell: "{{ app_downloads }}/setup_node_lts.sh"
+
+
 - name: add PPA for Ubuntu Toolchain
 - name: add PPA for Ubuntu Toolchain
   become: true
   become: true
   ansible.builtin.apt_repository:
   ansible.builtin.apt_repository:
@@ -78,27 +92,35 @@
       - zip
       - zip
       - unzip
       - unzip
       - nginx
       - nginx
+      - libnginx-mod-http-upstream-fair
       - certbot
       - certbot
       - python3-certbot-nginx
       - python3-certbot-nginx
       - openvpn
       - openvpn
       - snmpd
       - snmpd
       - mutt
       - mutt
       - systemd-cron
       - systemd-cron
-      - systemd-timesyncd
       - screen
       - screen
       - tmux
       - tmux
       - hugo
       - hugo
+      - nodejs
       - python3
       - python3
       - python3-pip
       - python3-pip
       - python3-distutils
       - python3-distutils
       - python3-dev
       - python3-dev
-      - nodejs
-      - npm
-      - yarnpkg
       - libssl-dev
       - libssl-dev
       - libpq-dev
       - libpq-dev
       - libmysqlclient-dev
       - libmysqlclient-dev
 
 
+- name: Install dependicy packages(>bionic)
+  become: true
+  apt:
+    pkg:
+      - systemd-timesyncd
+      - yarnpkg
+  # ansible_facts['distribution'] == "Ubuntu"
+  when: ansible_facts['distribution_major_version'] | int >= 20
+
+
 
 
 - import_tasks: locales.yml
 - import_tasks: locales.yml
 
 

+ 19 - 7
public/app/palicanon/palicanon.js

@@ -22,18 +22,30 @@ function palicanon_onload() {
 }
 }
 
 
 function palicanon_load_term() {
 function palicanon_load_term() {
-	$.post(
-		"../term/get_term_index.php",
+    let lang =getCookie("language");
+    switch (lang) {
+        case 'zh-cn':
+            lang = 'zh-hans';
+            break;
+        case 'zh-tw':
+            lang = 'zh-hant';
+            break;    
+        case '':
+            lang = 'en';
+            break;  
+    }
+	$.get(
+		"/api/v2/terms",
 		{
 		{
-			lang: getCookie("language"),
+            view:'hot-meaning',
+			language: lang,
 		},
 		},
 		function (data) {
 		function (data) {
-			let result = JSON.parse(data);
-			if (result.status == 0) {
-				arrMyTerm = result.data;
+			if (data.ok) {
+				arrMyTerm = data.data.rows;
 				render_main_tag();
 				render_main_tag();
 			} else {
 			} else {
-				alert(result.error);
+				alert(data.message);
 			}
 			}
 		}
 		}
 	);
 	);

+ 17 - 4
public/app/term/note.js

@@ -6,6 +6,7 @@ var _channal = "";
 var _lang = "";
 var _lang = "";
 var _author = "";
 var _author = "";
 
 
+
 var _arrData = new Array();
 var _arrData = new Array();
 var _channalData;
 var _channalData;
 
 
@@ -115,12 +116,17 @@ function note_update_background_style() {
 }
 }
 //
 //
 function note_refresh_new(callback = null) {
 function note_refresh_new(callback = null) {
+    let Params={
+        maxSentenceOneRequest:100
+    };
 	note_update_background_style();
 	note_update_background_style();
 	let objNotes = document.querySelectorAll("note");
 	let objNotes = document.querySelectorAll("note");
 	let arrSentInfo = new Array();
 	let arrSentInfo = new Array();
+    let noteCounter = 0;
 	for (const iterator of objNotes) {
 	for (const iterator of objNotes) {
 		let id = iterator.id;
 		let id = iterator.id;
 		if (id == null || id == "") {
 		if (id == null || id == "") {
+            
 			//查看这个节点是第几层note嵌套。大于预定层数退出。
 			//查看这个节点是第几层note嵌套。大于预定层数退出。
 			let layout = 1;
 			let layout = 1;
 			let parent = iterator.parentNode;
 			let parent = iterator.parentNode;
@@ -135,6 +141,7 @@ function note_refresh_new(callback = null) {
 				}
 				}
 				parent = parent.parentNode;
 				parent = parent.parentNode;
 			}
 			}
+            
 			id = com_guid();
 			id = com_guid();
 			iterator.id = id;
 			iterator.id = id;
 			if (iterator.hasAttribute("info")) {
 			if (iterator.hasAttribute("info")) {
@@ -151,6 +158,10 @@ function note_refresh_new(callback = null) {
 					arrSentInfo.push({ id: id, data: info });
 					arrSentInfo.push({ id: id, data: info });
 				}
 				}
 			}
 			}
+            noteCounter++;
+            if(noteCounter>=Params.maxSentenceOneRequest){
+                break;
+            }
 		}
 		}
 	}
 	}
 	if (arrSentInfo.length > 0) {
 	if (arrSentInfo.length > 0) {
@@ -190,7 +201,7 @@ function note_refresh_new(callback = null) {
 						_arrData = _arrData.concat(sentData);
 						_arrData = _arrData.concat(sentData);
 						note_ref_init();
 						note_ref_init();
 						//获取术语字典
 						//获取术语字典
-						term_get_dict();
+						term_get_dict(callback);
 						//刷新channel列表
 						//刷新channel列表
 						note_channal_list();
 						note_channal_list();
 						//显示不同的巴利语脚本
 						//显示不同的巴利语脚本
@@ -199,9 +210,7 @@ function note_refresh_new(callback = null) {
 						splite_pali_word();
 						splite_pali_word();
 						//处理编辑框消息
 						//处理编辑框消息
 						tran_sent_textarea_event_init();
 						tran_sent_textarea_event_init();
-						if (callback) {
-							callback();
-						}
+
 						//初始化mermaid
 						//初始化mermaid
 						mermaid.initialize({startOnLoad:true});
 						mermaid.initialize({startOnLoad:true});
 
 
@@ -214,6 +223,10 @@ function note_refresh_new(callback = null) {
 	} else {
 	} else {
 		term_get_dict();
 		term_get_dict();
 	}
 	}
+    if(arrSentInfo.length>0){
+        note_refresh_new(callback);
+    }
+    
 }
 }
 
 
 //渲染巴利原文句子
 //渲染巴利原文句子

+ 12 - 5
public/app/term/term.js

@@ -405,8 +405,12 @@ function term_array_updata() {
 		);
 		);
 	}
 	}
 }
 }
-
-function term_updata_translation() {
+/*
+*-----------------------
+*更新术语显示
+*-----------------------
+*/
+function term_updata_translation(callback=null) {
 	termCounter = new Array();
 	termCounter = new Array();
 	noteCounter = 1;
 	noteCounter = 1;
 	//计算有效模版数量
 	//计算有效模版数量
@@ -551,6 +555,9 @@ function term_updata_translation() {
 		}
 		}
 	});
 	});
 	term_popup_init();
 	term_popup_init();
+    if(callback){
+        callback();
+    }
 }
 }
 
 
 function term_show_win(guid, keyWord = "",channel="",lang="") {
 function term_show_win(guid, keyWord = "",channel="",lang="") {
@@ -674,9 +681,9 @@ function term_show_new() {
 	guide_init();
 	guide_init();
 }
 }
 
 
-function term_get_dict() {
+function term_get_dict(callback=null) {
 	if (arrMyTerm.length > 0) {
 	if (arrMyTerm.length > 0) {
-		term_updata_translation();
+		term_updata_translation(callback);
 		return;
 		return;
 	}
 	}
 	let termwordlist = new Array();
 	let termwordlist = new Array();
@@ -707,7 +714,7 @@ function term_get_dict() {
 			if (data.length > 0) {
 			if (data.length > 0) {
 				try {
 				try {
 					arrMyTerm = JSON.parse(data);
 					arrMyTerm = JSON.parse(data);
-					term_updata_translation();
+					term_updata_translation(callback);
 				} catch (e) {
 				} catch (e) {
 					console.error(e.error + " data:" + data);
 					console.error(e.error + " data:" + data);
 				}
 				}

+ 2 - 2
v1/scripts/migrations/20211218133000_article_collection_copy.php

@@ -34,12 +34,12 @@ fwrite(STDOUT,"migarate _TABLE_ARTICLE_COLLECTION_".PHP_EOL);
 
 
 #打开源数据库
 #打开源数据库
 $PDO_SRC = new PDO($src_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
 $PDO_SRC = new PDO($src_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
-$PDO_SRC->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+$PDO_SRC->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 fwrite(STDOUT,"open src table".PHP_EOL);
 fwrite(STDOUT,"open src table".PHP_EOL);
 
 
 #打开目标数据库
 #打开目标数据库
 $PDO_DEST = new PDO($dest_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
 $PDO_DEST = new PDO($dest_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
-$PDO_DEST->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+$PDO_DEST->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 fwrite(STDOUT,"open dest table".PHP_EOL);
 fwrite(STDOUT,"open dest table".PHP_EOL);
 
 
 #删除目标数据表中全部数据
 #删除目标数据表中全部数据