({ trackId }: { trackId: string })
| 16 | const VECTOR_SIZE = parseInt(process.env.VECTOR_SIZE!) || 768; |
| 17 | |
| 18 | export async function scrapeData({ trackId }: { trackId: string }) { |
| 19 | const notion = getNotionClient(); |
| 20 | const track = await getTrack(trackId); |
| 21 | const data = await Promise.all( |
| 22 | track?.problems.map(async (problem: any) => { |
| 23 | const notionDocId = problem.notionDocId; |
| 24 | const notionPage = await fetchNotionPage(notion, notionDocId); |
| 25 | const titles = Object.values<any>(notionPage?.block ?? {}) |
| 26 | .map((block) => { |
| 27 | const title = block?.value?.properties?.title; |
| 28 | if (title && title[0] && title[0][0]) { |
| 29 | return title[0][0]; |
| 30 | } else { |
| 31 | const source = block?.value?.properties?.source; |
| 32 | if (source && source[0] && source[0][0]) { |
| 33 | return source[0][0]; |
| 34 | } else { |
| 35 | return null; |
| 36 | } |
| 37 | } |
| 38 | }) |
| 39 | .filter((title) => title); |
| 40 | problem["titles"] = titles.flat().join(" "); |
| 41 | problem["trackId"] = track.id; |
| 42 | problem["trackTitle"] = track.title; |
| 43 | problem["image"] = track.image; |
| 44 | return problem; |
| 45 | }) || [] |
| 46 | ); |
| 47 | return data; |
| 48 | } |
| 49 | |
| 50 | export async function createCollection(){ |
| 51 | await client.createCollection("DailyCode",{ |
no test coverage detected