mirror of
https://github.com/Wx-2025/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 12:45:51 +00:00
Enhance fetchMessageBoardContent to use lastMessageId
Add support for fetching message board content with last message ID.
This commit is contained in:
21
core/api.js
21
core/api.js
@@ -48,17 +48,36 @@ const UPDATE_CHECK_URL =
|
||||
const MESSAGE_BOARD_URL =
|
||||
"https://amilyservice.amily49.cc/amily2_message_board.json";
|
||||
|
||||
let lastMessageId = null;
|
||||
|
||||
export async function fetchMessageBoardContent() {
|
||||
if (!MESSAGE_BOARD_URL) {
|
||||
console.log('[Amily2号-内务府] 任务取消:陛下尚未配置留言板URL。');
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const response = await fetch(MESSAGE_BOARD_URL, { cache: 'no-store' });
|
||||
let url = MESSAGE_BOARD_URL;
|
||||
if (lastMessageId) {
|
||||
const separator = url.includes('?') ? '&' : '?';
|
||||
url += `${separator}nowId=${encodeURIComponent(lastMessageId)}`;
|
||||
}
|
||||
|
||||
const response = await fetch(url, { cache: 'no-store' });
|
||||
|
||||
if (response.status === 304) {
|
||||
console.log('[Amily2号-内务府] 留言板内容未变更 (304)。');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`服务器响应异常: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
|
||||
if (data && data.id) {
|
||||
lastMessageId = data.id;
|
||||
}
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('[Amily2号-内务府] 获取留言板内容失败:', error);
|
||||
|
||||
Reference in New Issue
Block a user