mirror of
https://github.com/ZSCGR/CloudFlare-ImgBed.git
synced 2026-08-13 04:03:42 +08:00
feat: refresh announcement read status
This commit is contained in:
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -1 +1 @@
|
|||||||
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/static/media/logo.png"><link rel="apple-touch-icon" href="/static/media/logo.png"><link rel="mask-icon" href="/static/media/logo.png" color="#f4b400"><meta name="description" content="Sanyue ImgHub - A modern file hosting platform"><meta name="keywords" content="Sanyue, ImgHub, file hosting, image hosting, cloud storage"><meta name="author" content="SanyueQi"><title>Sanyue ImgHub</title><script defer="defer" src="/js/chunk-vendors.6243340b.js"></script><script defer="defer" src="/js/app.4a2a0cd3.js"></script><link href="/css/chunk-vendors.f9cd4701.css" rel="stylesheet"><link href="/css/app.a5d6bf3c.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but sanyue_imghub doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/static/media/logo.png"><link rel="apple-touch-icon" href="/static/media/logo.png"><link rel="mask-icon" href="/static/media/logo.png" color="#f4b400"><meta name="description" content="Sanyue ImgHub - A modern file hosting platform"><meta name="keywords" content="Sanyue, ImgHub, file hosting, image hosting, cloud storage"><meta name="author" content="SanyueQi"><title>Sanyue ImgHub</title><script defer="defer" src="/js/chunk-vendors.6243340b.js"></script><script defer="defer" src="/js/app.1e6d1e36.js"></script><link href="/css/chunk-vendors.f9cd4701.css" rel="stylesheet"><link href="/css/app.a5d6bf3c.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but sanyue_imghub doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
||||||
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
@@ -27,7 +27,9 @@ export async function onRequest(context) {
|
|||||||
// POST保存设置
|
// POST保存设置
|
||||||
if (request.method === 'POST') {
|
if (request.method === 'POST') {
|
||||||
const body = await request.json()
|
const body = await request.json()
|
||||||
const settings = body
|
const previousSettings = await getPageConfig(db, env)
|
||||||
|
const settings = processAnnouncementInfo(body, previousSettings)
|
||||||
|
|
||||||
// 写入数据库
|
// 写入数据库
|
||||||
await db.put('manage@sysConfig@page', JSON.stringify(settings))
|
await db.put('manage@sysConfig@page', JSON.stringify(settings))
|
||||||
|
|
||||||
@@ -46,6 +48,10 @@ export async function getPageConfig(db, env) {
|
|||||||
const settingsStr = await db.get('manage@sysConfig@page')
|
const settingsStr = await db.get('manage@sysConfig@page')
|
||||||
const settingsKV = settingsStr ? JSON.parse(settingsStr) : {}
|
const settingsKV = settingsStr ? JSON.parse(settingsStr) : {}
|
||||||
|
|
||||||
|
if (Number.isFinite(Number(settingsKV.announcementRefreshAt))) {
|
||||||
|
settings.announcementRefreshAt = Number(settingsKV.announcementRefreshAt)
|
||||||
|
}
|
||||||
|
|
||||||
const config = []
|
const config = []
|
||||||
settings.config = config
|
settings.config = config
|
||||||
config.push(
|
config.push(
|
||||||
@@ -317,3 +323,32 @@ export async function getPageConfig(db, env) {
|
|||||||
|
|
||||||
return settings
|
return settings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理公告内容及其刷新状态。
|
||||||
|
* 公告内容变化或管理员主动刷新时生成新版本;否则沿用旧版本,
|
||||||
|
* 确保修改标题、背景等无关设置不会让公告重复弹出。
|
||||||
|
*/
|
||||||
|
function processAnnouncementInfo(settings, previousSettings) {
|
||||||
|
const previousAnnouncement = Array.isArray(previousSettings.config)
|
||||||
|
? previousSettings.config.find(item => item?.id === 'announcement')?.value ?? ''
|
||||||
|
: ''
|
||||||
|
const nextAnnouncement = Array.isArray(settings.config)
|
||||||
|
? settings.config.find(item => item?.id === 'announcement')?.value ?? ''
|
||||||
|
: ''
|
||||||
|
const shouldRefreshAnnouncement =
|
||||||
|
previousAnnouncement !== nextAnnouncement || settings.refreshAnnouncement === true
|
||||||
|
|
||||||
|
// 该字段只是前端发来的单次操作指令,不应进入持久化配置。
|
||||||
|
delete settings.refreshAnnouncement
|
||||||
|
|
||||||
|
if (shouldRefreshAnnouncement) {
|
||||||
|
settings.announcementRefreshAt = Date.now()
|
||||||
|
} else if (previousSettings.announcementRefreshAt) {
|
||||||
|
settings.announcementRefreshAt = previousSettings.announcementRefreshAt
|
||||||
|
} else {
|
||||||
|
delete settings.announcementRefreshAt
|
||||||
|
}
|
||||||
|
|
||||||
|
return settings
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* 用户端页面配置 API
|
* 用户端页面配置 API
|
||||||
* 负责读取页面配置并转换为前端可直接使用的用户配置对象
|
* 负责读取页面配置并转换为前端可直接使用的用户配置对象
|
||||||
*/
|
*/
|
||||||
import { fetchPageConfig } from "../utils/sysConfig";
|
import { fetchPageConfig } from "../utils/sysConfig.js";
|
||||||
|
|
||||||
export async function onRequest(context) {
|
export async function onRequest(context) {
|
||||||
const { env } = context;
|
const { env } = context;
|
||||||
@@ -24,6 +24,10 @@ export async function onRequest(context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Number.isFinite(Number(PageConfig.announcementRefreshAt))) {
|
||||||
|
userConfig.announcementRefreshAt = Number(PageConfig.announcementRefreshAt);
|
||||||
|
}
|
||||||
|
|
||||||
// 检查 USER_CONFIG 是否为空或未定义
|
// 检查 USER_CONFIG 是否为空或未定义
|
||||||
if (!userConfig) {
|
if (!userConfig) {
|
||||||
return new Response(JSON.stringify({}), { status: 200 });
|
return new Response(JSON.stringify({}), { status: 200 });
|
||||||
|
|||||||
Reference in New Issue
Block a user