|
|
|
@@ -190,7 +190,11 @@ public final class VideoCache {
|
|
|
|
public static void preload(String url) {
|
|
|
|
public static void preload(String url) {
|
|
|
|
if (url == null || url.isEmpty()) return;
|
|
|
|
if (url == null || url.isEmpty()) return;
|
|
|
|
if (!(url.startsWith("http://") || url.startsWith("https://"))) return;
|
|
|
|
if (!(url.startsWith("http://") || url.startsWith("https://"))) return;
|
|
|
|
if (READY.containsKey(url)) {
|
|
|
|
// Use lookup() (which also verifies the file exists on disk) instead of
|
|
|
|
|
|
|
|
// READY.containsKey — defends against READY containing a stale entry whose
|
|
|
|
|
|
|
|
// backing file was removed by clearAll() / a user-side file delete. Without this,
|
|
|
|
|
|
|
|
// a stale key would silently block a re-preload.
|
|
|
|
|
|
|
|
if (lookup(url) != null) {
|
|
|
|
VideoPlayerMod.LOG.info("[{}] preload: already cached {}", VideoPlayerMod.MOD_ID, url);
|
|
|
|
VideoPlayerMod.LOG.info("[{}] preload: already cached {}", VideoPlayerMod.MOD_ID, url);
|
|
|
|
notifyChat("[videopreload] 이미 캐시됨: " + url, ChatFormatting.GRAY);
|
|
|
|
notifyChat("[videopreload] 이미 캐시됨: " + url, ChatFormatting.GRAY);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
@@ -255,8 +259,22 @@ public final class VideoCache {
|
|
|
|
// Resume-friendly: if the file's already on disk from an earlier session, just
|
|
|
|
// Resume-friendly: if the file's already on disk from an earlier session, just
|
|
|
|
// index it without re-downloading.
|
|
|
|
// index it without re-downloading.
|
|
|
|
if (Files.exists(finalPath) && Files.size(finalPath) > 0) {
|
|
|
|
if (Files.exists(finalPath) && Files.size(finalPath) > 0) {
|
|
|
|
|
|
|
|
// Pre-publish check — bail if clearAll has run since submit.
|
|
|
|
if (CACHE_EPOCH.get() != startEpoch) return;
|
|
|
|
if (CACHE_EPOCH.get() != startEpoch) return;
|
|
|
|
READY.put(url, finalPath);
|
|
|
|
READY.put(url, finalPath);
|
|
|
|
|
|
|
|
// Post-publish re-check: same window as the post-move check on the download
|
|
|
|
|
|
|
|
// path. If clearAll landed between the epoch read above and the READY.put,
|
|
|
|
|
|
|
|
// it would have wiped READY + the file, and our put() resurrected a stale
|
|
|
|
|
|
|
|
// entry pointing at a now-deleted path. Roll it back: remove our entry
|
|
|
|
|
|
|
|
// (compareAndRemove via remove(key, value) to avoid clobbering a concurrent
|
|
|
|
|
|
|
|
// legitimate re-put) and best-effort delete the file.
|
|
|
|
|
|
|
|
if (CACHE_EPOCH.get() != startEpoch) {
|
|
|
|
|
|
|
|
READY.remove(url, finalPath);
|
|
|
|
|
|
|
|
try { Files.deleteIfExists(finalPath); } catch (Throwable ignored) {}
|
|
|
|
|
|
|
|
VideoPlayerMod.LOG.info("[{}] preload: reindex cancelled (clearAll ran) — {}",
|
|
|
|
|
|
|
|
VideoPlayerMod.MOD_ID, url);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
VideoPlayerMod.LOG.info("[{}] preload: indexed existing cache {} -> {}",
|
|
|
|
VideoPlayerMod.LOG.info("[{}] preload: indexed existing cache {} -> {}",
|
|
|
|
VideoPlayerMod.MOD_ID, url, finalPath.getFileName());
|
|
|
|
VideoPlayerMod.MOD_ID, url, finalPath.getFileName());
|
|
|
|
notifyChat("[videopreload] 기존 캐시 사용: " + url, ChatFormatting.GREEN);
|
|
|
|
notifyChat("[videopreload] 기존 캐시 사용: " + url, ChatFormatting.GREEN);
|
|
|
|
|