openlist增加定时扫描
This commit is contained in:
@@ -2544,6 +2544,7 @@ const OpenListConfigComponent = ({
|
|||||||
const [username, setUsername] = useState('');
|
const [username, setUsername] = useState('');
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
const [rootPath, setRootPath] = useState('/');
|
const [rootPath, setRootPath] = useState('/');
|
||||||
|
const [scanInterval, setScanInterval] = useState(0);
|
||||||
const [videos, setVideos] = useState<any[]>([]);
|
const [videos, setVideos] = useState<any[]>([]);
|
||||||
const [refreshing, setRefreshing] = useState(false);
|
const [refreshing, setRefreshing] = useState(false);
|
||||||
const [scanProgress, setScanProgress] = useState<{
|
const [scanProgress, setScanProgress] = useState<{
|
||||||
@@ -2560,6 +2561,7 @@ const OpenListConfigComponent = ({
|
|||||||
setUsername(config.OpenListConfig.Username || '');
|
setUsername(config.OpenListConfig.Username || '');
|
||||||
setPassword(config.OpenListConfig.Password || '');
|
setPassword(config.OpenListConfig.Password || '');
|
||||||
setRootPath(config.OpenListConfig.RootPath || '/');
|
setRootPath(config.OpenListConfig.RootPath || '/');
|
||||||
|
setScanInterval(config.OpenListConfig.ScanInterval || 0);
|
||||||
}
|
}
|
||||||
}, [config]);
|
}, [config]);
|
||||||
|
|
||||||
@@ -2597,6 +2599,7 @@ const OpenListConfigComponent = ({
|
|||||||
Username: username,
|
Username: username,
|
||||||
Password: password,
|
Password: password,
|
||||||
RootPath: rootPath,
|
RootPath: rootPath,
|
||||||
|
ScanInterval: scanInterval,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2774,6 +2777,23 @@ const OpenListConfigComponent = ({
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2'>
|
||||||
|
定时扫描间隔(分钟)
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type='number'
|
||||||
|
value={scanInterval}
|
||||||
|
onChange={(e) => setScanInterval(parseInt(e.target.value) || 0)}
|
||||||
|
placeholder='0'
|
||||||
|
min='0'
|
||||||
|
className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-transparent'
|
||||||
|
/>
|
||||||
|
<p className='mt-1 text-xs text-gray-500 dark:text-gray-400'>
|
||||||
|
设置为 0 关闭定时扫描,最低 60 分钟
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className='flex gap-3'>
|
<div className='flex gap-3'>
|
||||||
<button
|
<button
|
||||||
onClick={handleSave}
|
onClick={handleSave}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export async function POST(request: NextRequest) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { action, URL, Username, Password, RootPath } = body;
|
const { action, URL, Username, Password, RootPath, ScanInterval } = body;
|
||||||
|
|
||||||
const authInfo = getAuthInfoFromCookie(request);
|
const authInfo = getAuthInfoFromCookie(request);
|
||||||
if (!authInfo || !authInfo.username) {
|
if (!authInfo || !authInfo.username) {
|
||||||
@@ -56,6 +56,15 @@ export async function POST(request: NextRequest) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 验证扫描间隔
|
||||||
|
let scanInterval = parseInt(ScanInterval) || 0;
|
||||||
|
if (scanInterval > 0 && scanInterval < 60) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: '定时扫描间隔最低为 60 分钟' },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 验证账号密码是否正确
|
// 验证账号密码是否正确
|
||||||
try {
|
try {
|
||||||
console.log('[OpenList Config] 验证账号密码');
|
console.log('[OpenList Config] 验证账号密码');
|
||||||
@@ -76,6 +85,7 @@ export async function POST(request: NextRequest) {
|
|||||||
RootPath: RootPath || '/',
|
RootPath: RootPath || '/',
|
||||||
LastRefreshTime: adminConfig.OpenListConfig?.LastRefreshTime,
|
LastRefreshTime: adminConfig.OpenListConfig?.LastRefreshTime,
|
||||||
ResourceCount: adminConfig.OpenListConfig?.ResourceCount,
|
ResourceCount: adminConfig.OpenListConfig?.ResourceCount,
|
||||||
|
ScanInterval: scanInterval,
|
||||||
};
|
};
|
||||||
|
|
||||||
await db.saveAdminConfig(adminConfig);
|
await db.saveAdminConfig(adminConfig);
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ export async function GET(request: NextRequest) {
|
|||||||
async function cronJob() {
|
async function cronJob() {
|
||||||
await refreshConfig();
|
await refreshConfig();
|
||||||
await refreshAllLiveChannels();
|
await refreshAllLiveChannels();
|
||||||
|
await refreshOpenList();
|
||||||
await refreshRecordAndFavorites();
|
await refreshRecordAndFavorites();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,3 +265,59 @@ async function refreshRecordAndFavorites() {
|
|||||||
console.error('刷新播放记录/收藏任务启动失败', err);
|
console.error('刷新播放记录/收藏任务启动失败', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function refreshOpenList() {
|
||||||
|
try {
|
||||||
|
const config = await getConfig();
|
||||||
|
const openListConfig = config.OpenListConfig;
|
||||||
|
|
||||||
|
// 检查是否配置了 OpenList 和定时扫描
|
||||||
|
if (!openListConfig || !openListConfig.URL || !openListConfig.Username || !openListConfig.Password) {
|
||||||
|
console.log('跳过 OpenList 扫描:未配置');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const scanInterval = openListConfig.ScanInterval || 0;
|
||||||
|
if (scanInterval === 0) {
|
||||||
|
console.log('跳过 OpenList 扫描:定时扫描已关闭');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查间隔时间是否满足最低要求(60分钟)
|
||||||
|
if (scanInterval < 60) {
|
||||||
|
console.log(`跳过 OpenList 扫描:间隔时间 ${scanInterval} 分钟小于最低要求 60 分钟`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查上次扫描时间
|
||||||
|
const lastRefreshTime = openListConfig.LastRefreshTime || 0;
|
||||||
|
const now = Date.now();
|
||||||
|
const timeSinceLastRefresh = now - lastRefreshTime;
|
||||||
|
const intervalMs = scanInterval * 60 * 1000;
|
||||||
|
|
||||||
|
if (timeSinceLastRefresh < intervalMs) {
|
||||||
|
const remainingMinutes = Math.ceil((intervalMs - timeSinceLastRefresh) / 60000);
|
||||||
|
console.log(`跳过 OpenList 扫描:距离上次扫描仅 ${Math.floor(timeSinceLastRefresh / 60000)} 分钟,还需等待 ${remainingMinutes} 分钟`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`开始 OpenList 定时扫描(间隔: ${scanInterval} 分钟)`);
|
||||||
|
|
||||||
|
// 调用扫描接口
|
||||||
|
const response = await fetch(`${process.env.SITE_BASE || 'http://localhost:3000'}/api/openlist/refresh`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`扫描请求失败: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
console.log('OpenList 定时扫描已启动,任务ID:', result.taskId);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('OpenList 定时扫描失败:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ export interface AdminConfig {
|
|||||||
RootPath: string; // 根目录路径,默认 "/"
|
RootPath: string; // 根目录路径,默认 "/"
|
||||||
LastRefreshTime?: number; // 上次刷新时间戳
|
LastRefreshTime?: number; // 上次刷新时间戳
|
||||||
ResourceCount?: number; // 资源数量
|
ResourceCount?: number; // 资源数量
|
||||||
|
ScanInterval?: number; // 定时扫描间隔(分钟),0表示关闭,最低60分钟
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user