From f6dcaf476c269e36f9d454d503557622af7b98a8 Mon Sep 17 00:00:00 2001 From: Bohan Cheng <47214785+cbh778899@users.noreply.github.com> Date: Fri, 26 Jul 2024 18:17:42 +1000 Subject: [PATCH 1/2] Fix bugs of v0.1.7 (#54) * format link in markdown Signed-off-by: cbh778899 * move switchPage back to index.js, previous version can cause bugs Signed-off-by: cbh778899 * hide training page, we might recover it in furture Signed-off-by: cbh778899 * parse no more string to html document to make sure the program is secure Signed-off-by: cbh778899 * update email pattern Signed-off-by: cbh778899 * update version Signed-off-by: cbh778899 * comment out yeager route Signed-off-by: cbh778899 --------- Signed-off-by: cbh778899 --- components/sidebar.js | 5 ++-- components/training-page/index.js | 11 +++---- global/switchPage.js | 46 ----------------------------- index.js | 49 +++++++++++++++++++++++++++++-- nginx/default.conf | 6 ++-- settings.js | 2 +- tools/conversationFormat.js | 4 +++ tools/message.js | 11 +++---- tools/validators.js | 2 +- 9 files changed, 68 insertions(+), 68 deletions(-) delete mode 100644 global/switchPage.js diff --git a/components/sidebar.js b/components/sidebar.js index d6b8eae..4b865e6 100644 --- a/components/sidebar.js +++ b/components/sidebar.js @@ -1,17 +1,16 @@ import createInfoPage from "./info-page.js"; import getSVG from "../tools/svgs.js"; import createAccountPage from "./account-page/index.js"; -import switchSelectedPage from '../global/switchPage.js' const pages = [ { name: 'chat', svgName: 'chat-dots-fill' }, // { name: 'model-hero', svgName: 'hero' }, - { name: 'training' }, + // { name: 'training' }, { name: 'account', svgName: 'person-fill', not_page: true }, { name: 'info', svgName: 'info-circle-fill', not_page: true } ] -export default function createSideBar() { +export default function createSideBar(switchSelectedPage) { const sidebar = document.getElementById('sidebar'); sidebar.innerHTML = ` diff --git a/components/training-page/index.js b/components/training-page/index.js index e5c61c6..8a4101f 100644 --- a/components/training-page/index.js +++ b/components/training-page/index.js @@ -1,7 +1,7 @@ // const dataset_options = [] // const model_options = [] -import { loadDefaultPage } from "../../global/switchPage.js"; +// import { loadDefaultPage } from "../../global/switchPage.js"; import useUser from "../../global/useUser.js"; import showMessage from "../../tools/message.js"; import request from "../../tools/request.js"; @@ -14,7 +14,7 @@ const pages = [ {index: 'template', title: 'Find Models'}, {index: 'parameters', title: 'Start Training'}, {index: 'training-visualization', title: 'Training Visualization'}, - {index: 'faq', title: 'FAQ'}, + // {index: 'faq', title: 'FAQ'}, ] let training_page_main, current_page = '', @@ -51,15 +51,16 @@ function switchPage(page) { current_page = page; } -let logged_in; +let logged_in, loadDefaultPage; const { componentReMount, componetDismount } = useUser(user=>{ logged_in = user.logged_in; if(!logged_in) { - loadDefaultPage(); + loadDefaultPage && loadDefaultPage(); } }) -export default function createTrainingPage() { +export default function createTrainingPage(load_default_page) { + loadDefaultPage = load_default_page; componentReMount(); document.getElementById("main").innerHTML = ` diff --git a/global/switchPage.js b/global/switchPage.js deleted file mode 100644 index eeaa83d..0000000 --- a/global/switchPage.js +++ /dev/null @@ -1,46 +0,0 @@ -import createChatPage from "../components/chat-page/index.js"; -import createTrainingPage from "../components/training-page/index.js"; -import useUser from "../global/useUser.js"; -import showMessage from "../tools/message.js"; -import createAccountPage from "../components/account-page/index.js"; - -let last_selected_page = ''; -let componetDismount = null; - -let logged_in = false; -useUser(user=>{ - logged_in = user.logged_in; -}) - -export default function switchSelectedPage(page) { - if(page === last_selected_page) return; - if(!logged_in) { - if(/^(training)$/.test(page)) { - showMessage('Please login to use this function.', { type: 'warn' }); - createAccountPage(); - return; - } - } - - document.getElementById('main').innerHTML = ''; - componetDismount && componetDismount(); - componetDismount = null; - - switch(page) { - case 'training': - componetDismount = createTrainingPage(); - break; - case 'chat': default: - componetDismount = createChatPage(); - break; - } - - // change side-bar icon class - document.getElementById(`sidebar-icon-${page}`).classList.add('selected'); - last_selected_page && document.getElementById(`sidebar-icon-${last_selected_page}`).classList.remove('selected'); - last_selected_page = page; -} - -export function loadDefaultPage() { - switchSelectedPage('chat'); -} \ No newline at end of file diff --git a/index.js b/index.js index a350216..c9d2c0a 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,53 @@ import createSideBar from "./components/sidebar.js"; -import { loadDefaultPage } from "./global/switchPage.js"; +import createChatPage from "../components/chat-page/index.js"; +import createTrainingPage from "../components/training-page/index.js"; +import useUser from "../global/useUser.js"; +import showMessage from "../tools/message.js"; +import createAccountPage from "../components/account-page/index.js"; + +let last_selected_page = ''; +let componetDismount = null; + +let logged_in = false; +useUser(user=>{ + logged_in = user.logged_in; +}) + +function switchSelectedPage(page) { + if(page === last_selected_page) return; + if(!logged_in) { + if(/^(training)$/.test(page)) { + showMessage('Please login to use this function.', { type: 'warn' }); + createAccountPage(); + return; + } + } + + document.getElementById('main').innerHTML = ''; + componetDismount && componetDismount(); + componetDismount = null; + + switch(page) { + case 'training': + componetDismount = createTrainingPage(loadDefaultPage); + break; + case 'chat': default: + componetDismount = createChatPage(); + break; + } + + // change side-bar icon class + document.getElementById(`sidebar-icon-${page}`).classList.add('selected'); + last_selected_page && document.getElementById(`sidebar-icon-${last_selected_page}`).classList.remove('selected'); + last_selected_page = page; +} + +function loadDefaultPage() { + switchSelectedPage('chat'); +} function build() { - createSideBar(); + createSideBar(switchSelectedPage); loadDefaultPage(); } diff --git a/nginx/default.conf b/nginx/default.conf index d1cafd9..099e743 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -13,9 +13,9 @@ server { proxy_pass http://kirin/api; } - location /training-visualization { - proxy_pass http://yeager/; - } + # location /training-visualization { + # proxy_pass http://yeager/; + # } location / { root /usr/share/nginx/html; diff --git a/settings.js b/settings.js index 15db35a..ca6bd14 100644 --- a/settings.js +++ b/settings.js @@ -1,2 +1,2 @@ -export const VERSION = '0.1.7' +export const VERSION = '0.1.8' export const API_ADDRESS = '/api' diff --git a/tools/conversationFormat.js b/tools/conversationFormat.js index 9bc1ad3..611e896 100644 --- a/tools/conversationFormat.js +++ b/tools/conversationFormat.js @@ -49,6 +49,9 @@ export function formatMarkdown(str, target_elem, pending_elem, end_special_block case 'inline-code': plain_text_elems.push(createElement('span', group_1 || group_2, { className: 'inline-code' })) break; + case 'hyperlink': + plain_text_elems.push(createElement('a', group_1, { href: group_2, target: '_blank' })) + break; default: return ''; } @@ -93,6 +96,7 @@ export function formatMarkdown(str, target_elem, pending_elem, end_special_block .replaceAll(/__(.+?)__/g, parseSingleLine('italic')) .replaceAll(/^(\*|-){3,}$/g, parseSingleLine('hr')) .replaceAll(/``(.+?)``|`(.+?)`/g, parseSingleLine('inline-code')) + .replaceAll(/\[([^\]]*)\]\(([^)]*)\)/g, parseSingleLine('hyperlink')) .replace(/<\|end\|>$/, ''); const block = document.createElement('div'); diff --git a/tools/message.js b/tools/message.js index 5b71b6a..175e28c 100644 --- a/tools/message.js +++ b/tools/message.js @@ -17,9 +17,7 @@ message_dialog.show(); * Display a notification with given type on top-right corner * @param {String | any[]} message * The message to show, can be a `string` or an array with `string` or/and `HTMLElement`. - * **Note:** - * If pass a `string`, it will be parsed to HTML; - * If pass an `array` with `string`, strings in that array won't be parsed. + * **Note:** `string` will not be parsed, please add `HTMLElement` if you want to output html format. * @param {messageOptions} options - Options of showing messages */ export default function showMessage(message, options = {}) { @@ -46,11 +44,10 @@ export default function showMessage(message, options = {}) { const message_text = document.createElement('div'); message_text.className = 'message-text'; message_elem.appendChild(message_text); - if(typeof message === 'string') { - message_text.innerHTML = message; - } else if(Array.isArray(message)) { - message_text.append(...message); + if(!Array.isArray(message)) { + message = [message] } + message_text.append(...message); message_elem.style.animationDuration = `${animation_duration}ms` message_dialog.appendChild(message_elem); diff --git a/tools/validators.js b/tools/validators.js index 90908c4..ac1cd21 100644 --- a/tools/validators.js +++ b/tools/validators.js @@ -4,7 +4,7 @@ export const username_not_valid = 'Username should includes only letters, number export function validateEmail(string) { return ( - /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(string) + /^[a-zA-Z0-9_-][.a-zA-Z0-9_-]+[a-zA-Z0-9_-]@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(string) ) } From 7373b4c11876cf7e5dd16901a6a06728f59e1da8 Mon Sep 17 00:00:00 2001 From: Bohan Cheng <47214785+cbh778899@users.noreply.github.com> Date: Sun, 28 Jul 2024 14:22:22 +1000 Subject: [PATCH 2/2] Create FUNDING.yml (#56) Signed-off-by: Bohan Cheng <47214785+cbh778899@users.noreply.github.com> --- .github/FUNDING.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..3dcfc7b --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,14 @@ +# These are supported funding model platforms + +github: [cbh778899]# Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry +polar: # Replace with a single Polar username +buy_me_a_coffee: # Replace with a single Buy Me a Coffee username +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']