From 75af51f0ea3a8301421a0c73e7245c2dc7c2a56f Mon Sep 17 00:00:00 2001 From: srgooglo Date: Thu, 8 Oct 2020 16:17:05 +0200 Subject: [PATCH 1/4] added to core queryIndexer, used for index an input rules and returns parsed string with callback --- src/core/index.js | 24 +++++++++++++++++++++++- src/models/app.js | 23 +++++++++++++++++++++++ src/pages/@/[user].js | 21 +++++++++++++++++++++ src/pages/[indexer].js | 26 ++------------------------ 4 files changed, 69 insertions(+), 25 deletions(-) create mode 100644 src/pages/@/[user].js diff --git a/src/core/index.js b/src/core/index.js index e4c5b8bc..6de7cee9 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -29,6 +29,29 @@ export const app_info = { layout: platform.layout }; +export function queryIndexer(array, callback, params) { + if(!array) return false + + if (Array.isArray(array)) { + let opt = { + regex: /:id/gi + } + + if (params) { + opt = { ...opt, ...params } + } + + array.forEach((e) =>{ + if (e.match != null && e.to != null) { + const pathMatch = pathMatchRegexp(e.match, window.location.pathname) + if (pathMatch != null) { + return callback(e.to.replace(opt.regex, pathMatch[1])) + } + } + }) + } +} + export function createScreenshotFromElement(element){ if (!element) return false html2canvas(element, { @@ -341,7 +364,6 @@ export const time = { }; export function pathMatchRegexp(regexp, pathname) { - console.log('Regex => ', pathname) return pathToRegexp(regexp).exec(pathname) } diff --git a/src/models/app.js b/src/models/app.js index e94a6e1e..30d3a649 100755 --- a/src/models/app.js +++ b/src/models/app.js @@ -5,6 +5,7 @@ import { user, session } from 'core/helpers' import { router, verbosity, appInterface } from 'core/libs' import settings from 'core/libs/settings' import { uri_resolver } from 'api/lib' +import { queryIndexer } from 'core' import jwt from 'jsonwebtoken' import cookie from 'cookie_js' @@ -94,6 +95,28 @@ export default { window.PluginGlobals = [] + queryIndexer([ + { + match: '/s;:id', + to: `/settings?key=:id`, + }, + { + match: '/h;:id', + to: `/hashtag?key=:id`, + }, + { + match: '/p;:id', + to: `/post?key=:id`, + }, + { + match: '/@:id', + to: `/@/:id`, + } + ], (callback) => { + window.location = callback + }) + + if (!service) { } diff --git a/src/pages/@/[user].js b/src/pages/@/[user].js new file mode 100644 index 00000000..a0ad97ac --- /dev/null +++ b/src/pages/@/[user].js @@ -0,0 +1,21 @@ +import React from 'react' +import { pathMatchRegexp } from 'core' +import { router } from 'core/libs/router' +import { Invalid } from 'components' + +export default class UserIndexer extends React.Component { + render() { + const { location } = this.props + const matchRegexp = pathMatchRegexp('/@/:id', location.pathname) + + if (matchRegexp) { + return ( +
+ {matchRegexp[1]} +
+ ) + } + return + } +} + diff --git a/src/pages/[indexer].js b/src/pages/[indexer].js index 065206eb..8996c437 100644 --- a/src/pages/[indexer].js +++ b/src/pages/[indexer].js @@ -1,29 +1,9 @@ import React from 'react' -import { pathMatchRegexp } from 'core' import Error404 from './404.js' -// -import { Invalid } from 'components' -class PageIndexer extends React.Component { +export default class PageIndexer extends React.Component { render() { const { location } = this.props - const matchUser = pathMatchRegexp('/@:id', location.pathname) - const matchSetting = pathMatchRegexp('/~:id', location.pathname) - console.log(matchSetting) - if (matchUser) { - return ( -
- {matchUser} -
- ) - } - if (matchSetting) { - return( -
- -
- ) - } // By default return Error 404 return ( @@ -32,6 +12,4 @@ class PageIndexer extends React.Component { ) } -} - -export default PageIndexer +} \ No newline at end of file From ff4f2aba859294d5c4022df19cba1ecbe666cb85 Mon Sep 17 00:00:00 2001 From: srgooglo <38926803+srgooglo@users.noreply.github.com> Date: Thu, 8 Oct 2020 16:27:40 +0200 Subject: [PATCH 2/4] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 027134f3..386d98ac 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,4 @@ [![CodeFactor](https://www.codefactor.io/repository/github/srgooglo/comty/badge)](https://www.codefactor.io/repository/github/srgooglo/comty) [![Trello](https://img.shields.io/badge/Trello-Join%20dashboard-blue)](https://trello.com/invite/b/UbwvlG1I/2bc02725b9b210d2e9e9a82c5040b895/comty-development) [![Discord](https://img.shields.io/badge/dynamic/json?color=%235390d9&label=Discord&query=name&url=https%3A%2F%2Fdiscordapp.com%2Fapi%2Fguilds%2F713713091568861197%2Fwidget.json)](https://discord.gg/uMRSKDW) +![CodeQL](https://github.com/srgooglo/comty/workflows/CodeQL/badge.svg?branch=master) From 655811456e15b3cc2544ada59d7621a0e5bcee99 Mon Sep 17 00:00:00 2001 From: srgooglo <38926803+srgooglo@users.noreply.github.com> Date: Thu, 8 Oct 2020 16:39:26 +0200 Subject: [PATCH 3/4] Update codeql-analysis.yml --- .github/workflows/codeql-analysis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index b9c0ffec..a5f68d57 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -7,12 +7,10 @@ name: "CodeQL" on: push: - branches: [master] pull_request: - # The branches below must be a subset of the branches above branches: [master] schedule: - - cron: '0 18 * * 5' + - cron: '0 0 * * *' jobs: analyze: From a86d118a7a07cbd73623686a2fbdc7acb42a080c Mon Sep 17 00:00:00 2001 From: srgooglo <38926803+srgooglo@users.noreply.github.com> Date: Thu, 8 Oct 2020 16:40:21 +0200 Subject: [PATCH 4/4] Update codeql-analysis.yml --- .github/workflows/codeql-analysis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index a5f68d57..2e7f4c6d 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -6,7 +6,6 @@ name: "CodeQL" on: - push: pull_request: branches: [master] schedule: