Video Cache should "work"" now ?!

This commit is contained in:
Violet 2023-10-30 14:09:17 +00:00
parent d0fdc8a05f
commit ccd462b62a
2 changed files with 28 additions and 18 deletions

View file

@ -19,8 +19,7 @@ const searchCacheDur = (process.env.SEARCH_DUR || 24) * 3600000
const playerPath = path.join(resources, 'player.html')
const searchPath = path.join(resources, 'searchPage.html')
const cssHeader = `<style> ${fs.readFileSync(cssPath)} </style>`
const cssHeader = `<link rel="stylesheet" href="/mainStyle.css">`
if (fs.existsSync(cachePath)) {
@ -60,7 +59,7 @@ async function cacher(id, ready) {
"size": et,
"downloaded": false,
"download%": 0,
"lastUsed": new Date().getTime(),
"lastUsed": Date.now(),
"duration": (vidInfo.videoDetails.lengthSeconds + 1) * 1000
}
@ -163,7 +162,6 @@ app.get("/search", async (req, res) => {
const item = searchCache[itemName];
if (item[1] < Date.now()) {
console.log("Deleted!")
delete searchCache[search]
}
}
@ -230,12 +228,10 @@ app.get("/video", async (req, res) => {
}
}
console.log(videoCache)
if (id in videoCache) {
if ("path" in videoCache[id]) {
ready(videoCache[id].path)
videoCache[id].lastUsed = new Date().getTime()
videoCache[id].lastUsed = Date.now()
}
} else {
videoCache[id] = []
@ -253,6 +249,20 @@ app.get("/video", async (req, res) => {
res.writeHead(200, head)
fs.createReadStream(path).pipe(res)
}
var tA = Object.keys(videoCache)
for (let index = 0; index < tA.length; index++) {
const itemName = tA[index];
const item = videoCache[itemName]
const itemPath = item.path
if ("lastUsed" in item && item.lastUsed + (item.duration * 2.5) < Date.now()) {
delete videoCache[itemName]
if (fs.existsSync(itemPath)) {
fs.unlinkSync(itemPath)
}
}
}
})
app.get("/watch", async (req, res) => {

View file

@ -7,7 +7,7 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<link rel="stylesheet" href="./mainStyle.css">
<link rel="stylesheet" href="/mainStyle.css">
<title>SimpleTube</title>
</head>