Skip to content

Commit

Permalink
feat(server): nuxt3
Browse files Browse the repository at this point in the history
  • Loading branch information
LarchLiu committed May 10, 2023
1 parent b286f41 commit 130f2a8
Show file tree
Hide file tree
Showing 47 changed files with 7,753 additions and 1,300 deletions.
15 changes: 9 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

# dependencies
node_modules
.pnp
.pnp.js

# local files
dist
.idea/
.eslintcache

# testing
coverage

#nuxt
.output
.nuxt

# next.js
.next/
out/
Expand All @@ -32,7 +39,3 @@ yarn-error.log*

# turbo
.turbo

.eslintcache

dist
10 changes: 10 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"recommendations": [
"antfu.iconify",
"antfu.unocss",
"antfu.goto-alias",
"csstools.postcss",
"dbaeumer.vscode-eslint",
"vue.volar"
]
}
11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"prettier.enable": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"files.associations": {
"*.css": "postcss"
},
"editor.formatOnSave": false,
"unocss.root": [
"packages/chrome-extension"
"app/extension/chrome",
"server/nuxt3"
]
}
6 changes: 3 additions & 3 deletions app/bot/telegram-cl/src/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ interface WebsiteInfo {
title: string
url: string
content: string
meta?: GithubMeta
meta?: GithubRepoMeta
}

interface GithubMeta {
interface GithubRepoMeta {
host: string
website: 'Github'
tags?: string[]
Expand All @@ -136,6 +136,6 @@ interface SavedResponse {
}

export { TelegramWebhookRequest, TelegramMessage, TelegramUser,
TelegramChat, TelegramMessageEntity, WebsiteInfo, GithubMeta,
TelegramChat, TelegramMessageEntity, WebsiteInfo, GithubRepoMeta,
SavedResponse, FetchWebsite, FetchError
};
4 changes: 2 additions & 2 deletions app/extension/chrome/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {
GithubMeta,
GithubRepoMeta,
LoaderUrls,
WebsiteInfo,
} from '@starnexus/core'
Expand Down Expand Up @@ -47,7 +47,7 @@ export type {
SwResponse,
SwRequest,
ContentRequest,
GithubMeta,
GithubRepoMeta,
LoaderUrls,
PageInfo,
}
6 changes: 3 additions & 3 deletions packages/core/src/notion/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fetchPost } from '../utils'
import type { FetchRes, GithubMeta, NotionPage, SavedNotion, TwitterMeta } from '../types'
import type { FetchRes, GithubRepoMeta, NotionPage, SavedNotion, TwitterTweetMeta } from '../types'
import { GITHUB_DOMAIN, NOTION_API_URL, TWITTER_DOMAIN } from '../const'

async function saveToNotion(apiKey: string, info: NotionPage): Promise<FetchRes<SavedNotion>> {
Expand Down Expand Up @@ -75,7 +75,7 @@ async function saveToNotion(apiKey: string, info: NotionPage): Promise<FetchRes<
},
}
if (info.meta.domain === GITHUB_DOMAIN) {
const github = meta as GithubMeta
const github = meta as GithubRepoMeta
if (github.languages) {
const languages = github.languages.map((lang) => {
return {
Expand Down Expand Up @@ -104,7 +104,7 @@ async function saveToNotion(apiKey: string, info: NotionPage): Promise<FetchRes<
}
}
else if (info.meta.domain === TWITTER_DOMAIN) {
const twitter = meta as TwitterMeta
const twitter = meta as TwitterTweetMeta
if (twitter.tags) {
const tags = twitter.tags.map((tag) => {
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export interface WebsiteMeta {
prompts?: string
}

export interface GithubMeta extends WebsiteMeta {
export interface GithubRepoMeta extends WebsiteMeta {
username?: string
reponame?: string
description?: string
tags?: string[]
languages?: string[]
}

export interface TwitterMeta extends WebsiteMeta {
export interface TwitterTweetMeta extends WebsiteMeta {
name?: string
screenName?: string
avator?: string
Expand Down
13 changes: 9 additions & 4 deletions packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,15 @@ function strNotEqualWith(key: string, values: string[]): boolean {
}

function replaceHtmlReservedCharacters(str: string) {
const replaced = str.replaceAll('&lt;', '<').replaceAll('&gt;', '>').replace('&le;', '≤').replace('&ge;', '≥')
.replaceAll('&quot;', '"').replaceAll('&nbsp;', ' ').replaceAll('&trade;', '™').replaceAll('&asymp;', '≈')
.replaceAll('&ndash;', '-').replaceAll('&mdash;', '—').replace('&copy;', '©').replace('&reg;', '®')
.replaceAll('&ne;', '≠').replaceAll('&pound;', '£').replace('&euro;', '€').replace('&deg;', '°')
const replaced = str.replaceAll(/(&lt;)|(&#60;)/g, '<').replaceAll(/(&gt;)|(&#62;)/g, '>')
.replaceAll(/(&le;)|(&#8804;)/g, '≤')
.replaceAll(/(&ge;)|(&#8805;)/g, '≥').replaceAll(/(&quot;)|(&#34;)/g, '"')
.replaceAll(/(&trade;)|(&#8482;)/g, '™').replaceAll(/(&asymp;)|(&#8776;)/g, '≈')
.replaceAll(/(&ndash;)|(&#8211;)/g, '-').replaceAll(/(&mdash;)|(&#8212;)/g, '—')
.replaceAll(/(&copy;)|(&#169;)/g, '©').replaceAll(/(&reg;)|(&#174;)/g, '®')
.replaceAll(/(&ne;)|(&#8800;)/g, '≠').replaceAll(/(&pound;)|(&#163;)/g, '£')
.replaceAll(/(&euro;)|(&#8364;)/g, '€').replaceAll(/(&deg;)|(&#176;)/g, '°')
.replaceAll(/(&#39;)|(&apos;)/g, '\'').replaceAll(/(&nbsp;)|(&#160;)/g, ' ')

return replaced
}
Expand Down
23 changes: 23 additions & 0 deletions packages/core/src/webCard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { FetchRes, WebSiteCard, WebsiteInfo } from '../types'
import { fetchPost } from '../utils'

export class WebCard {
apiUrl = '/api/webcard'
webInfo?: WebsiteInfo = undefined
headers?: Record<string, string> = undefined
constructor(webInfo: WebsiteInfo, headers: Record<string, string>, webHub?: string) {
this.apiUrl = (webHub || '') + this.apiUrl
this.webInfo = webInfo
this.headers = headers
}

async getWebCardUrl(): Promise<FetchRes<WebSiteCard>> {
try {
const res = await fetchPost<WebSiteCard>(this.apiUrl, this.headers, this.webInfo)
return res
}
catch (error: any) {
return { error: error.message }
}
}
}
2 changes: 1 addition & 1 deletion packages/core/src/webInfo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function getWebsiteInfoByApi(urls: LoaderUrls, headers?: Record<str
if (!urls.webHub)
return { error: 'StarNexus error: No WebHub Url' }

const info = await fetchPost<WebsiteInfo>(`${urls.webHub}/api/webInfo`, headers, {
const info = await fetchPost<WebsiteInfo>(`${urls.webHub}/api/webinfo`, headers, {
webUrl: urls.webUrl,
})
return info
Expand Down
26 changes: 13 additions & 13 deletions packages/webHub/src/website/github.com/paths/repo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FetchError, FetchRes, GithubMeta, LoaderUrls, PathInfo, WebsiteInfo } from '@starnexus/core'
import type { FetchError, FetchRes, GithubRepoMeta, LoaderUrls, PathInfo, WebsiteInfo } from '@starnexus/core'
import { fetchGet, strNotEqualWith } from '@starnexus/core'
import { GITHUB_RAW_URL, GITHUB_REPOS_API, USER_AGENT } from '../../../const'

Expand All @@ -21,40 +21,40 @@ async function getRepoInfo(urls: LoaderUrls, headers: Record<string, string> = {
let title = ''
let content = ''
let url = urls.webUrl
const githubMeta: GithubMeta = {}
const githubRepo = urls.webPath
const meta: GithubRepoMeta = {}
const repo = urls.webPath
try {
if (githubRepo) {
if (repo) {
// fetch repo info
const { data: repoJson } = await fetchGet<Record<string, any>>(`${GITHUB_REPOS_API}/${githubRepo}`, headers)
const { data: repoJson } = await fetchGet<Record<string, any>>(`${GITHUB_REPOS_API}/${repo}`, headers)
// fetch languages
const { data: languagesJson } = await fetchGet<Record<string, string>>(`${GITHUB_REPOS_API}/${githubRepo}/languages`, headers)
const { data: languagesJson } = await fetchGet<Record<string, string>>(`${GITHUB_REPOS_API}/${repo}/languages`, headers)
if (repoJson) {
// fetch readme
const readmeRes = await fetchGet<string>(`${GITHUB_RAW_URL}/${githubRepo}/${repoJson.default_branch}/README.md`, headers, undefined, false)
const readmeRes = await fetchGet<string>(`${GITHUB_RAW_URL}/${repo}/${repoJson.default_branch}/README.md`, headers, undefined, false)
const readme = readmeRes.error ? '' : readmeRes.data

const description = repoJson.description.replace(/:\w+:/g, ' ')
title = `Repo · ${repoJson.full_name}`
url = repoJson.html_url
githubMeta.username = repoJson.owner.login
githubMeta.reponame = repoJson.name
githubMeta.description = description
meta.username = repoJson.owner.login
meta.reponame = repoJson.name
meta.description = description

const tags = repoJson.topics
if (tags && tags.length > 0)
githubMeta.tags = tags
meta.tags = tags

if (languagesJson)
githubMeta.languages = Object.keys(languagesJson)
meta.languages = Object.keys(languagesJson)

content = `${title}\n\n${readme}`
}
}
else {
return { error: 'Github error: Not supported website.' }
}
return { data: { title, url, content, meta: githubMeta } }
return { data: { title, url, content, meta } }
}
catch (error) {
return { error: `Github error: ${error as FetchError}` }
Expand Down
4 changes: 2 additions & 2 deletions packages/webHub/src/website/twitter.com/paths/tweet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FetchError, FetchRes, LoaderUrls, PathInfo, TwitterMeta, WebsiteInfo } from '@starnexus/core'
import type { FetchError, FetchRes, LoaderUrls, PathInfo, TwitterTweetMeta, WebsiteInfo } from '@starnexus/core'
import { replaceHtmlReservedCharacters, strNotEqualWith } from '@starnexus/core'
import { getTweetByStatus } from '../twitterApi'

Expand All @@ -18,7 +18,7 @@ async function getTweetInfo(urls: LoaderUrls): Promise<FetchRes<WebsiteInfo>> {
let title = ''
let content = ''
const url = urls.webUrl
const meta: TwitterMeta = {}
const meta: TwitterTweetMeta = {}
const path = urls.webPath
try {
if (path) {
Expand Down
Loading

0 comments on commit 130f2a8

Please sign in to comment.