|
1 | 1 | import { Client, downloadImages, downloadImagesWithRetry, type Post } from "notiondown"; |
2 | 2 |
|
3 | | -import config, { auth, databaseId, debug } from "./config"; |
| 3 | +import config, { auth, dataSourceId, debug } from "./config"; |
4 | 4 | import { ASSET_DIR, CACHE_DIR_ASSETS, CACHE_DIR_NOTION } from "./constants"; |
5 | 5 | import { postUrl } from "./utils"; |
6 | 6 |
|
7 | 7 | const pageSize = config.postsPerPage ?? 20; |
8 | 8 |
|
9 | | -if (!auth || !databaseId) { |
10 | | - throw new Error("NOTION_API_SECRET and DATABASE_ID environment variables must be set."); |
| 9 | +if (!auth || !dataSourceId) { |
| 10 | + throw new Error("NOTION_API_SECRET and DATA_SOURCE_ID environment variables must be set."); |
11 | 11 | } |
12 | 12 |
|
13 | 13 | const client = new Client({ |
14 | 14 | ...config.notiondown, |
15 | 15 | auth, |
16 | | - databaseId, |
| 16 | + dataSourceId, |
17 | 17 | cacheDir: CACHE_DIR_NOTION, |
18 | | - imageDir: "/" + ASSET_DIR, |
| 18 | + assetsDir: "/" + ASSET_DIR, |
19 | 19 | debug, |
20 | 20 | internalLink: (post) => postUrl(post.slug), |
21 | 21 | }); |
@@ -69,17 +69,17 @@ export async function getPostOnly(slug: string) { |
69 | 69 | } |
70 | 70 |
|
71 | 71 | export async function getPost(slug: string) { |
72 | | - const { database, posts, images } = await client.getDatabaseAndAllPosts(); |
| 72 | + const { database, posts, assets } = await client.getDatabaseAndAllPosts(); |
73 | 73 | const post = posts.find((p) => p.slug === slug); |
74 | 74 | if (!post) { |
75 | 75 | throw new Error(`Post with slug "${slug}" not found.`); |
76 | 76 | } |
77 | 77 |
|
78 | 78 | const content = await client.getPostContent(post.id); |
79 | | - for (const [key, value] of content.images?.entries() || []) { |
80 | | - images.set(key, value); |
| 79 | + for (const [key, value] of content.assets?.entries() || []) { |
| 80 | + assets.set(key, value); |
81 | 81 | } |
82 | | - await donwloadImages(images, post.id); |
| 82 | + await donwloadImages(assets, post.id); |
83 | 83 |
|
84 | 84 | return { |
85 | 85 | post, |
|
0 commit comments