forked from transitive-bullshit/nextjs-notion-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add redis db to persist images; bug fixes
- Loading branch information
1 parent
5417bb9
commit 40972ec
Showing
10 changed files
with
166 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Keyv from 'keyv' | ||
|
||
import { | ||
isPreviewImageSupportEnabled, | ||
redisUrl, | ||
redisNamespace | ||
} from './config' | ||
|
||
let db: Keyv | ||
if (isPreviewImageSupportEnabled) { | ||
db = new Keyv(redisUrl, { namespace: redisNamespace || undefined }) | ||
} | ||
|
||
export { db } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,3 @@ | ||
import { Block } from 'notion-types' | ||
import { imageCDNHost } from './config' | ||
import { defaultMapImageUrl } from 'react-notion-x' | ||
|
||
export const mapNotionImageUrl = (url: string, block: Block) => { | ||
if (!url) { | ||
return null | ||
} | ||
|
||
if (url.startsWith('data:')) { | ||
return url | ||
} | ||
|
||
if (imageCDNHost && url.startsWith(imageCDNHost)) { | ||
return url | ||
} | ||
|
||
// const origUrl = url | ||
|
||
if (url.startsWith('/images')) { | ||
url = `https://www.notion.so${url}` | ||
} | ||
|
||
// more recent versions of notion don't proxy unsplash images | ||
if (!url.startsWith('https://images.unsplash.com')) { | ||
url = `https://www.notion.so${ | ||
url.startsWith('/image') ? url : `/image/${encodeURIComponent(url)}` | ||
}` | ||
|
||
const notionImageUrlV2 = new URL(url) | ||
let table = block.parent_table === 'space' ? 'block' : block.parent_table | ||
if (table === 'collection') { | ||
table = 'block' | ||
} | ||
notionImageUrlV2.searchParams.set('table', table) | ||
notionImageUrlV2.searchParams.set('id', block.id) | ||
notionImageUrlV2.searchParams.set('cache', 'v2') | ||
|
||
url = notionImageUrlV2.toString() | ||
} | ||
|
||
// console.log({ url, origUrl }) | ||
return mapImageUrl(url) | ||
} | ||
|
||
export const mapImageUrl = (imageUrl: string) => { | ||
if (imageUrl.startsWith('data:')) { | ||
return imageUrl | ||
} | ||
|
||
if (imageCDNHost) { | ||
return `${imageCDNHost}/${encodeURIComponent(imageUrl)}` | ||
} else { | ||
return imageUrl | ||
} | ||
} | ||
export const mapImageUrl = defaultMapImageUrl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.