Skip to content

Commit 67aa4ed

Browse files
committed
Merge branch 'release/4.9.0' of https://github.com/tangly1024/NotionNext into release/4.9.0
2 parents c20345c + ab86d73 commit 67aa4ed

File tree

5 files changed

+78
-60
lines changed

5 files changed

+78
-60
lines changed

lib/notion/mapImage.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,20 @@ const compressImage = (image, width, quality = 50, fmt = 'webp') => {
123123
let urlObj
124124
let params
125125
try {
126-
// 将URL解析为一个对象
127126
urlObj = new URL(image)
128-
// 获取URL参数
129127
params = new URLSearchParams(urlObj.search)
130128
} catch (err) {
131-
// 捕获异常并打印错误的url
132-
console.error('compressImage: Invalid URL:', image, err)
133-
return image
129+
// 如果解析失败,尝试 decodeURIComponent 再解析
130+
try {
131+
const decoded = decodeURIComponent(image)
132+
urlObj = new URL(decoded)
133+
params = new URLSearchParams(urlObj.search)
134+
} catch (e) {
135+
console.error('compressImage: Invalid URL:', image, err)
136+
return image
137+
}
134138
}
135-
139+
136140
// Notion图床
137141
if (
138142
image.indexOf(BLOG.NOTION_HOST) === 0 &&

next.config.js

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -207,64 +207,68 @@ const nextConfig = {
207207
{
208208
source: '/:path*{/}?',
209209
headers: [
210-
// 安全头部
211-
{ key: 'X-Frame-Options', value: 'DENY' },
212-
{ key: 'X-Content-Type-Options', value: 'nosniff' },
213-
{ key: 'X-XSS-Protection', value: '1; mode=block' },
214-
{ key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
215-
{ key: 'Permissions-Policy', value: 'camera=(), microphone=(), geolocation=()' },
216-
{
217-
key: 'Strict-Transport-Security',
218-
value: 'max-age=31536000; includeSubDomains; preload'
219-
},
220-
{
221-
key: 'Content-Security-Policy',
222-
value: [
223-
"default-src 'self'",
224-
"script-src 'self' 'unsafe-inline' 'unsafe-eval' *.googleapis.com *.gstatic.com *.google-analytics.com *.googletagmanager.com",
225-
"style-src 'self' 'unsafe-inline' *.googleapis.com *.gstatic.com",
226-
"img-src 'self' data: blob: *.notion.so *.unsplash.com *.githubusercontent.com *.gravatar.com",
227-
"font-src 'self' *.googleapis.com *.gstatic.com",
228-
"connect-src 'self' *.google-analytics.com *.googletagmanager.com",
229-
"frame-src 'self' *.youtube.com *.vimeo.com",
230-
"object-src 'none'",
231-
"base-uri 'self'",
232-
"form-action 'self'"
233-
].join('; ')
234-
},
235-
236-
// CORS 配置(更严格)
237-
{ key: 'Access-Control-Allow-Credentials', value: 'false' },
238-
{
239-
key: 'Access-Control-Allow-Origin',
240-
value: process.env.NODE_ENV === 'production'
241-
? siteConfig('LINK') || 'https://yourdomain.com'
242-
: '*'
243-
},
210+
// 为了博客兼容性,不做过多安全限制
211+
{ key: 'Access-Control-Allow-Credentials', value: 'true' },
212+
{ key: 'Access-Control-Allow-Origin', value: '*' },
244213
{
245214
key: 'Access-Control-Allow-Methods',
246-
value: 'GET,OPTIONS,HEAD'
215+
value: 'GET,OPTIONS,PATCH,DELETE,POST,PUT'
247216
},
248217
{
249218
key: 'Access-Control-Allow-Headers',
250-
value: 'Accept, Accept-Version, Content-Length, Content-Type, Date'
251-
},
252-
{ key: 'Access-Control-Max-Age', value: '86400' }
253-
]
254-
},
255-
{
256-
source: '/api/:path*',
257-
headers: [
258-
// API 特定的安全头部
259-
{ key: 'X-Frame-Options', value: 'DENY' },
260-
{ key: 'X-Content-Type-Options', value: 'nosniff' },
261-
{ key: 'Cache-Control', value: 'no-store, max-age=0' },
262-
{
263-
key: 'Access-Control-Allow-Methods',
264-
value: 'GET,POST,PUT,DELETE,OPTIONS'
219+
value:
220+
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'
265221
}
222+
// 安全头部 相关配置,谨慎开启
223+
// { key: 'X-Frame-Options', value: 'DENY' },
224+
// { key: 'X-Content-Type-Options', value: 'nosniff' },
225+
// { key: 'X-XSS-Protection', value: '1; mode=block' },
226+
// { key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
227+
// { key: 'Permissions-Policy', value: 'camera=(), microphone=(), geolocation=()' },
228+
// {
229+
// key: 'Strict-Transport-Security',
230+
// value: 'max-age=31536000; includeSubDomains; preload'
231+
// },
232+
// {
233+
// key: 'Content-Security-Policy',
234+
// value: [
235+
// "default-src 'self'",
236+
// "script-src 'self' 'unsafe-inline' 'unsafe-eval' *.googleapis.com *.gstatic.com *.google-analytics.com *.googletagmanager.com",
237+
// "style-src 'self' 'unsafe-inline' *.googleapis.com *.gstatic.com",
238+
// "img-src 'self' data: blob: *.notion.so *.unsplash.com *.githubusercontent.com *.gravatar.com",
239+
// "font-src 'self' *.googleapis.com *.gstatic.com",
240+
// "connect-src 'self' *.google-analytics.com *.googletagmanager.com",
241+
// "frame-src 'self' *.youtube.com *.vimeo.com",
242+
// "object-src 'none'",
243+
// "base-uri 'self'",
244+
// "form-action 'self'"
245+
// ].join('; ')
246+
// },
247+
248+
// // CORS 配置(更严格)
249+
// { key: 'Access-Control-Allow-Credentials', value: 'false' },
250+
// {
251+
// key: 'Access-Control-Allow-Origin',
252+
// value: process.env.NODE_ENV === 'production'
253+
// ? siteConfig('LINK') || 'https://yourdomain.com'
254+
// : '*'
255+
// },
256+
// { key: 'Access-Control-Max-Age', value: '86400' }
266257
]
267-
}
258+
},
259+
// {
260+
// source: '/api/:path*',
261+
// headers: [
262+
// // API 特定的安全头部
263+
// { key: 'X-Frame-Options', value: 'DENY' },
264+
// { key: 'X-Content-Type-Options', value: 'nosniff' },
265+
// { key: 'Cache-Control', value: 'no-store, max-age=0' },
266+
// {
267+
// key: 'Access-Control-Allow-Methods',
268+
// value: 'GET,POST,PUT,DELETE,OPTIONS'
269+
// }
270+
// ]
271+
// }
268272
]
269273
},
270274
webpack: (config, { dev, isServer }) => {

pages/500.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Custom500() {
2+
return <div>服务器内部错误,请稍后重试。</div>
3+
}

pages/_error.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function ErrorPage({ statusCode }) {
2+
return <div>发生错误,状态码:{statusCode || 404}</div>
3+
}
4+
ErrorPage.getInitialProps = ({ res, err }) => {
5+
const statusCode = res ? res.statusCode : err ? err.statusCode : 404
6+
return { statusCode }
7+
}

types/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,6 @@ export interface EnvironmentVariables {
237237
}
238238

239239
// 导出所有类型
240-
export * from './blog'
241-
export * from './notion'
242-
export * from './theme'
240+
// export * from './blog'
241+
// export * from './notion'
242+
// export * from './theme'

0 commit comments

Comments
 (0)