aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2025-01-22 08:59:52 +0300
committerRblSb <msrblsb@gmail.com>2025-01-22 08:59:52 +0300
commit8f54fabd74b6964e3610d3fbbbfd26f29af6f482 (patch)
tree4519aaa91f1e1cdb180b30a3426f5ba1dedda61d /src
parenta30cc5643c1e8366d2e8743fbe7c01ce1a468111 (diff)
Cache fix
Diffstat (limited to 'src')
-rw-r--r--src/server/Cache.hx19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/server/Cache.hx b/src/server/Cache.hx
index 8348476..8681ea2 100644
--- a/src/server/Cache.hx
+++ b/src/server/Cache.hx
@@ -55,7 +55,7 @@ class Cache {
return;
}
final outName = videoId + ".mp4";
- if (cachedFiles.contains(outName)) {
+ if (cachedFiles.contains(outName) && FileSystem.exists('$cacheDir/$outName')) {
callback(outName);
return;
}
@@ -102,11 +102,14 @@ class Cache {
count++;
log(client, '$type track downloaded ($count/2)');
if (count < 2) return;
- final args = '-y -i input-video -i input-audio -c copy -map 0:v -map 1:a $outName'.split(" ");
+ final args = '-y -i input-video -i input-audio -c copy -map 0:v -map 1:a ./$outName'.split(" ");
final process = ChildProcess.spawn("ffmpeg", args, {
cwd: cacheDir,
stdio: "ignore"
});
+ // process.stderr.on('data', (data) -> {
+ // trace('FFmpeg stderr: ${data}');
+ // });
process.on("close", (code:Int) -> {
if (code != 0) {
log(client, 'Error: ffmpeg closed with code $code');
@@ -117,7 +120,9 @@ class Cache {
if (FileSystem.exists(inVideo)) FileSystem.deleteFile(inVideo);
if (FileSystem.exists(inAudio)) FileSystem.deleteFile(inAudio);
- cachedFiles.push(outName);
+ if (!cachedFiles.contains(outName)) {
+ cachedFiles.unshift(outName);
+ }
removeOlderCache();
callback(outName);
@@ -136,7 +141,7 @@ class Cache {
function removeOlderCache():Void {
while (getUsedSpace() > storageLimit) {
- final name = cachedFiles.shift();
+ final name = cachedFiles.pop();
final path = '$cacheDir/$name';
if (FileSystem.exists(path)) FileSystem.deleteFile(path);
}
@@ -144,8 +149,12 @@ class Cache {
function getUsedSpace():Int {
var total = 0;
- for (name in cachedFiles) {
+ for (name in cachedFiles.reversed()) {
final path = '$cacheDir/$name';
+ if (!FileSystem.exists(path)) {
+ cachedFiles.remove(name);
+ continue;
+ }
total += FileSystem.stat(path).size;
}
return total;
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage