Skip to content

Commit

Permalink
feat(core): get website info by api
Browse files Browse the repository at this point in the history
  • Loading branch information
LarchLiu committed May 7, 2023
1 parent 7f0fce2 commit 11b3bd5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export interface WebsiteInfo {
}

export interface WebsiteMeta {
domain: string
website: string
domain?: string
website?: string
cover?: string
prompts?: string
}
Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/website/github.com/paths/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ async function getRepoInfo(urls: LoaderUrls, header: Record<string, string> = {
let title = ''
let content = ''
let url = urls.webUrl
const githubMeta: GithubMeta = {
domain: '',
website: '',
}
const githubMeta: GithubMeta = {}
const githubRepo = urls.webPath
try {
if (githubRepo) {
Expand Down
17 changes: 16 additions & 1 deletion packages/core/src/website/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FetchWebsite, LoaderUrls, Routes } from '../types'
import { getDomain } from '../utils'
import { fetchPost, getDomain } from '../utils'
import { routes } from './routes-auto-imports'

export async function getWebsiteInfo(urls: LoaderUrls, header?: Record<string, string>, otherRoutes: Routes = {}): Promise<FetchWebsite> {
Expand Down Expand Up @@ -29,3 +29,18 @@ export async function getWebsiteInfo(urls: LoaderUrls, header?: Record<string, s

return info
}

export async function getWebsiteInfoByApi(urls: LoaderUrls, header?: Record<string, string>): Promise<FetchWebsite> {
try {
if (!urls.webHub)
return { error: 'StarNexus error: No WebHub Url' }

const info: FetchWebsite = await fetchPost(`${urls.webHub}/api/webinfo`, header, {
webUrl: urls.webUrl,
})
return info
}
catch (error: any) {
return { error: error.message }
}
}
8 changes: 3 additions & 5 deletions packages/core/src/website/twitter.com/paths/tweet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ async function getTweetInfo(urls: LoaderUrls, header: Record<string, string> = {
let title = ''
let content = ''
const url = urls.webUrl
const meta: TwitterMeta = { domain: '', website: '' }
const regexPath = /https:\/\/twitter.com\/([^\/]*\/status\/[^\?]*)/g // match github.com/user/repo/
const pathMatch = regexPath.exec(url)
const path = pathMatch ? pathMatch[1] : ''
const status = path.split('/')[2]
const meta: TwitterMeta = {}
const path = urls.webPath
const webHub = urls.webHub || STAR_NEXUS_HUB_API
try {
if (path && webHub) {
const status = path.split('/')[2]
// fetch tweets info
const resJson = await fetchGet<any>(`${webHub}/twitter/tweet/${path}/original=true`, header)
const tweets = resJson.item as any[]
Expand Down

0 comments on commit 11b3bd5

Please sign in to comment.