Skip to content

Commit

Permalink
fix(app): create webCard by api
Browse files Browse the repository at this point in the history
  • Loading branch information
LarchLiu committed Jun 1, 2023
1 parent 14e8d60 commit 02ca24f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
21 changes: 9 additions & 12 deletions app/bot/telegram-cl/src/notion.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NotionDataStorage } from '@starnexus/core/storage/notion'
import { SupabaseImageStorage } from '@starnexus/core/storage/supabase'
import { WebCard } from '@starnexus/core/webCard'
import { WebCardByApi } from '@starnexus/core/webCard'
import { WebInfoByApi } from '@starnexus/core/webInfo'
import { OpenaiSummarizeContent } from '@starnexus/core/openai'
import { SaveWebInfoChain } from '@starnexus/core/chain/saveWebInfo'
import { errorMessage } from '@starnexus/core/utils'
import { ENV } from './env.js'

/**
Expand All @@ -19,6 +19,7 @@ async function saveToNotion(text) {
let i = 0
let success = 0
let fail = 0
let errInfo = ''
while (i < match.length) {
const notionApiKey = ENV.NOTION_API_KEY
const databaseId = ENV.NOTION_DATABASE_ID
Expand All @@ -32,14 +33,7 @@ async function saveToNotion(text) {
starNexusHub,
})

const supabaseImgStorage = new SupabaseImageStorage({
url: ENV.SUPABASE_URL || '',
anonKey: ENV.SUPABASE_ANON_KEY || '',
bucket: ENV.SUPABASE_STORAGE_BUCKET || '',
upsert: true,
})

const webCard = new WebCard({ starNexusHub, imgStorage: supabaseImgStorage })
const webCard = new WebCardByApi({ starNexusHub })

const summarize = new OpenaiSummarizeContent({ apiKey: openaiApiKey })
const notion = new NotionDataStorage(
Expand All @@ -57,15 +51,18 @@ async function saveToNotion(text) {
dataStorage: notion,
})

const info = await chain.call().then(_ => true).catch(_ => false)
const info = await chain.call().then(_ => true).catch((err) => {
errInfo += `${errorMessage(err)}\n`
return false
})

i++
if (info)
success++
else
fail++
}
return `Success: ${success}${fail ? (` Fail: ${fail}`) : ''}`
return `Success: ${success}${fail ? (` Fail: ${fail}\n${errInfo}`) : ''}`
}
else {
throw new Error('No Website Matched')
Expand Down
11 changes: 2 additions & 9 deletions app/extension/chrome/src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { errorMessage } from '@starnexus/core/utils'
import { NotionDataStorage } from '@starnexus/core/storage/notion'
import { SupabaseImageStorage } from '@starnexus/core/storage/supabase'
import { WebCard } from '@starnexus/core/webCard'
import { WebCardByApi } from '@starnexus/core/webCard'
import { WebInfoByApi } from '@starnexus/core/webInfo'
import { OpenaiSummarizeContent } from '@starnexus/core/openai'
import { SaveWebInfoChain } from '@starnexus/core/chain/saveWebInfo'
Expand Down Expand Up @@ -104,14 +103,8 @@ async function saveToNotion(pageInfo: PageInfo): Promise<SwResponse> {
},
starNexusHub,
})
const supabaseImgStorage = new SupabaseImageStorage({
url: process.env.SUPABASE_URL || '',
anonKey: process.env.SUPABASE_ANON_KEY || '',
bucket: process.env.SUPABASE_STORAGE_BUCKET || '',
upsert: true,
})

const webCard = new WebCard({ starNexusHub, imgStorage: supabaseImgStorage })
const webCard = new WebCardByApi({ starNexusHub })

const summarize = new OpenaiSummarizeContent({ apiKey: openaiApiKey, lang: promptsLang })
const notion = new NotionDataStorage(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function replaceHtmlReservedCharacters(str: string) {
}

function errorMessage(error: any) {
let message = error.message || ''
let message: string = error.message || ''
if (error.data)
message += JSON.stringify(error.data)

Expand Down

1 comment on commit 02ca24f

@vercel
Copy link

@vercel vercel bot commented on 02ca24f Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

star-nexus – ./

star-nexus.vercel.app
star-nexus-git-main-larchliu.vercel.app
star-nexus-larchliu.vercel.app

Please sign in to comment.