Skip to content

Commit

Permalink
chore: debugging deployment issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chengpeiquan committed Oct 29, 2024
1 parent b748ba7 commit 03db4bf
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 23 deletions.
28 changes: 28 additions & 0 deletions src/app/api/search/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { getContentCache } from '@/cache/content-cache'

export async function POST(req: Request) {
try {
const body = await req.json()
console.log('-----')
console.log(body)
console.log('-----')

const { folder, locale } = body

const data = await getContentCache(folder, locale)
console.log('-----')
console.log(data)
console.log('-----')

return Response.json({
code: 0,
data,
})
} catch (e) {
console.error(e)

return Response.json({
code: 1,
})
}
}
41 changes: 20 additions & 21 deletions src/cache/content-cache/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
import {
// ContentFolder,
type ListFolder,
} from '@/config/content-config'
'use server'

import { ContentFolder, type ListFolder } from '@/config/content-config'
import { type Locale } from '@/config/locale-config'
import {
type CacheMapKey,
type ContentCacheItem,
getCacheMapKey,
} from '@/config/cache-config'
// import article_en from './article-en.json'
// import article_zh from './article-zh.json'
// import cookbook_zh from './cookbook-zh.json'
import article_en from './article-en.json'
import article_zh from './article-zh.json'
import cookbook_zh from './cookbook-zh.json'

const contentCacheMap = new Map<CacheMapKey, ContentCacheItem[]>([
// [
// getCacheMapKey(ContentFolder.Article, 'zh'),
// article_zh as ContentCacheItem[],
// ],
// [
// getCacheMapKey(ContentFolder.Article, 'en'),
// article_en as ContentCacheItem[],
// ],
// [
// getCacheMapKey(ContentFolder.Cookbook, 'zh'),
// cookbook_zh as ContentCacheItem[],
// ],
[
getCacheMapKey(ContentFolder.Article, 'zh'),
article_zh as ContentCacheItem[],
],
[
getCacheMapKey(ContentFolder.Article, 'en'),
article_en as ContentCacheItem[],
],
[
getCacheMapKey(ContentFolder.Cookbook, 'zh'),
cookbook_zh as ContentCacheItem[],
],
])

export const getContentCache = (
export const getContentCache = async (
folder: ListFolder,
locale: Locale,
): ContentCacheItem[] => {
): Promise<ContentCacheItem[]> => {
const key = getCacheMapKey(folder, locale)
const cache = contentCacheMap.get(key)
return cache || []
Expand Down
12 changes: 10 additions & 2 deletions src/core/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
} from '@/config/cache-config'
import { type Locale } from '@/config/locale-config'
import { type ListFolder } from '@/config/content-config'
import { getContentCache } from '@/cache/content-cache'

interface SearchDocumentItem extends Omit<ContentCacheItem, 'slug'> {
id: FlexSearch.Id
Expand Down Expand Up @@ -49,7 +48,16 @@ export const getSearchEngine = async (folder: ListFolder, locale: Locale) => {
const engine = searchEngineMap.get(key)
if (engine) return engine

const data = getContentCache(...args)
// const data = await getContentCache(...args)
const res = await fetch('https://chengpeiquan.com/api/search', {
method: 'POST',
body: JSON.stringify({
folder: 'article',
locale: 'zh',
}),
})
// @ts-ignore
const data = res.data
const instance = await initializeEngine(data)
searchEngineMap.set(key, instance)

Expand Down

0 comments on commit 03db4bf

Please sign in to comment.