2026-04-23 01:08:18 +08:00
|
|
|
'use server'
|
|
|
|
|
|
|
|
|
|
import { revalidatePath } from 'next/cache'
|
|
|
|
|
import { redirect } from 'next/navigation'
|
|
|
|
|
|
|
|
|
|
const CACHE_PATHS = [
|
|
|
|
|
'/en',
|
|
|
|
|
'/zh',
|
|
|
|
|
'/en/about',
|
|
|
|
|
'/zh/about',
|
|
|
|
|
'/en/dealers',
|
|
|
|
|
'/zh/dealers',
|
|
|
|
|
'/en/downloads',
|
|
|
|
|
'/zh/downloads',
|
|
|
|
|
'/en/news',
|
|
|
|
|
'/zh/news',
|
|
|
|
|
'/en/products',
|
|
|
|
|
'/zh/products',
|
|
|
|
|
'/en/support',
|
|
|
|
|
'/zh/support',
|
|
|
|
|
'/en/support/contact',
|
|
|
|
|
'/zh/support/contact',
|
|
|
|
|
'/en/support/faq',
|
|
|
|
|
'/zh/support/faq',
|
|
|
|
|
'/en/support/warranty',
|
|
|
|
|
'/zh/support/warranty',
|
|
|
|
|
] as const
|
|
|
|
|
|
2026-04-28 00:55:07 +08:00
|
|
|
const CACHE_ROUTE_PATTERNS = [
|
|
|
|
|
'/en/downloads/[slug]',
|
|
|
|
|
'/zh/downloads/[slug]',
|
|
|
|
|
'/en/news/[slug]',
|
|
|
|
|
'/zh/news/[slug]',
|
|
|
|
|
'/en/products/[slug]',
|
|
|
|
|
'/zh/products/[slug]',
|
|
|
|
|
] as const
|
|
|
|
|
|
2026-04-23 01:08:18 +08:00
|
|
|
function normalizeReturnPath(value: FormDataEntryValue | null) {
|
|
|
|
|
if (typeof value !== 'string') return '/admin'
|
|
|
|
|
if (!value.startsWith('/admin')) return '/admin'
|
|
|
|
|
return value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function clearFrontendCache(formData: FormData) {
|
|
|
|
|
const returnTo = normalizeReturnPath(formData.get('returnTo'))
|
|
|
|
|
|
|
|
|
|
for (const path of CACHE_PATHS) {
|
|
|
|
|
revalidatePath(path)
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 00:55:07 +08:00
|
|
|
for (const path of CACHE_ROUTE_PATTERNS) {
|
|
|
|
|
revalidatePath(path, 'page')
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 01:08:18 +08:00
|
|
|
redirect(`${returnTo}${returnTo.includes('?') ? '&' : '?'}cache=cleared`)
|
|
|
|
|
}
|