Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get post 500 https://github.com/tangly1024/NotionNext/issues/3167 #3168

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions lib/notion/getNotionPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { idToUuid } from 'notion-utils'
import { defaultMapImageUrl } from 'react-notion-x'
import formatDate from '../utils/formatDate'
import { getPage } from './getPostBlocks'
import { checkStrIsNotionId, checkStrIsUuid } from '@/lib/utils'

/**
* 根据页面ID获取内容
Expand All @@ -14,14 +15,22 @@ export async function getPost(pageId) {
if (!blockMap) {
return null
}

const postInfo = blockMap?.block?.[idToUuid(pageId)].value
if (checkStrIsNotionId(pageId)) {
pageId = idToUuid(pageId)
}
if (!checkStrIsUuid(pageId)) {
return null
}
const postInfo = blockMap?.block?.[pageId]?.value
if (!postInfo) {
return null
}
return {
id: pageId,
type: postInfo,
type: postInfo.type,
category: '',
tags: [],
title: postInfo?.properties?.title?.[0],
title: postInfo?.properties?.title?.[0] || null,
status: 'Published',
createdTime: formatDate(
new Date(postInfo.created_time).toString(),
Expand All @@ -32,7 +41,7 @@ export async function getPost(pageId) {
BLOG.LANG
),
fullWidth: postInfo?.fullWidth || false,
page_cover: getPageCover(postInfo) || BLOG.HOME_BANNER_IMAGE,
page_cover: getPageCover(postInfo) || BLOG.HOME_BANNER_IMAGE || null,
date: {
start_date: formatDate(
new Date(postInfo?.last_edited_time).toString(),
Expand Down
11 changes: 11 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ export function checkStartWithHttp(str) {
}
}

// 检查一个字符串是否UUID https://ihateregex.io/expr/uuid/
export function checkStrIsUuid(str) {
if (!str) {
return false
}
// 使用正则表达式进行匹配
const regex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/
return regex.test(str)
}


// 检查一个字符串是否notionid : 32位,仅由数字英文构成
export function checkStrIsNotionId(str) {
if (!str) {
Expand Down
Loading