fix: 修复 eslint 报错

This commit is contained in:
LooseLi
2025-05-27 10:52:32 +08:00
parent d9bbf58aa6
commit e631507ce2
12 changed files with 52 additions and 43 deletions

View File

@@ -6,10 +6,10 @@ const cacheInvalidSeconds = 1000000000 * 1000
// 文件名
const jsonFile = path.resolve('./data.json')
export async function getCache (key) {
const exist = await fs.existsSync(jsonFile)
export function getCache(key) {
const exist = fs.existsSync(jsonFile)
if (!exist) return null
const data = await fs.readFileSync(jsonFile)
const data = fs.readFileSync(jsonFile)
let json = null
if (!data) return null
try {
@@ -19,7 +19,9 @@ export async function getCache (key) {
return null
}
// 缓存超过有效期就作废
const cacheValidTime = new Date(parseInt(json[key + '_expire_time']) + cacheInvalidSeconds)
const cacheValidTime = new Date(
parseInt(json[key + '_expire_time']) + cacheInvalidSeconds
)
const currentTime = new Date()
if (!cacheValidTime || cacheValidTime < currentTime) {
return null
@@ -33,17 +35,17 @@ export async function getCache (key) {
* @param data
* @returns {Promise<null>}
*/
export async function setCache (key, data) {
const exist = await fs.existsSync(jsonFile)
const json = exist ? JSON.parse(await fs.readFileSync(jsonFile)) : {}
export function setCache(key, data) {
const exist = fs.existsSync(jsonFile)
const json = exist ? JSON.parse(fs.readFileSync(jsonFile)) : {}
json[key] = data
json[key + '_expire_time'] = new Date().getTime()
fs.writeFileSync(jsonFile, JSON.stringify(json))
}
export async function delCache (key) {
const exist = await fs.existsSync(jsonFile)
const json = exist ? JSON.parse(await fs.readFileSync(jsonFile)) : {}
export function delCache(key) {
const exist = fs.existsSync(jsonFile)
const json = exist ? JSON.parse(fs.readFileSync(jsonFile)) : {}
delete json.key
json[key + '_expire_time'] = new Date().getTime()
fs.writeFileSync(jsonFile, JSON.stringify(json))
@@ -52,7 +54,7 @@ export async function delCache (key) {
/**
* 清理缓存
*/
export async function cleanCache() {
export function cleanCache() {
const json = {}
fs.writeFileSync(jsonFile, JSON.stringify(json))
}

View File

@@ -13,7 +13,7 @@ export async function getCache(key) {
const data = await redisClient.get(key)
return data ? JSON.parse(data) : null
} catch (e) {
console.error('redisClient读取失败 ' + e)
console.error(`redisClient读取失败 ${String(e)}`)
}
}
@@ -26,7 +26,7 @@ export async function setCache(key, data, customCacheTime) {
customCacheTime || cacheTime
)
} catch (e) {
console.error('redisClient写入失败 ' + e)
console.error(`redisClient写入失败 ${String(e)}`)
}
}
@@ -34,7 +34,7 @@ export async function delCache(key) {
try {
await redisClient.del(key)
} catch (e) {
console.error('redisClient删除失败 ' + e)
console.error(`redisClient删除失败 ${String(e)}`)
}
}

View File

@@ -39,8 +39,9 @@ export function GlobalContextProvider(props) {
// 登录验证相关
const enableClerk = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
const clerkUser = useUser()
const { isLoaded, isSignedIn, user } = enableClerk
? useUser()
? clerkUser
: { isLoaded: true, isSignedIn: false, user: false }
// 是否全屏
@@ -99,9 +100,11 @@ export function GlobalContextProvider(props) {
useEffect(() => {
const handleStart = url => {
const { theme } = router.query
if (theme && !url.includes(`theme=${theme}`)) {
const newUrl = `${url}${url.includes('?') ? '&' : '?'}theme=${theme}`
const themeValue = router.query.theme
const themeStr = Array.isArray(themeValue) ? themeValue[0] : themeValue
if (themeStr && !url.includes(`theme=${themeStr}`)) {
const newUrl = `${url}${url.includes('?') ? '&' : '?'}theme=${themeStr}`
router.push(newUrl)
}
if (!onLoading) {