mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-03-29 23:51:43 +01:00
delete old files
This commit is contained in:
parent
0f96b26f31
commit
6a5395f244
@ -7,7 +7,7 @@
|
||||
public static function LoadHeader($path) : ?BlobFile {
|
||||
$input = fopen($path, "rb");
|
||||
$version = ord(fread($input, 1));
|
||||
error_log($version);
|
||||
//error_log($version);
|
||||
|
||||
$bf = new BlobFile();
|
||||
if($version == 1) {
|
||||
@ -24,7 +24,7 @@
|
||||
$header_data = unpack("H14magic/Vuploaded", $header);
|
||||
fclose($input);
|
||||
|
||||
error_log("Magic is: " . $header_data["magic"]);
|
||||
//error_log("Magic is: " . $header_data["magic"]);
|
||||
if($header_data["magic"] == "4f4944f09f90b1") { //OID🐱 as hex (UTF-8)
|
||||
$bf->Version = 2;
|
||||
$bf->Uploaded = $header_data["uploaded"];
|
||||
|
@ -4,11 +4,58 @@
|
||||
if(StaticRedis::Connect()) {
|
||||
echo "Connected to redis..\n";
|
||||
|
||||
Config::LoadConfig(array("upload_folder"));
|
||||
Config::LoadConfig(array("upload_folder", "discord_webhook_pub"));
|
||||
$fs = new FileStore(Config::$Instance->upload_folder, $_SERVER["cron_root"]);
|
||||
|
||||
//delete expired files
|
||||
$pmsg = "`" . gethostname() . ":\n";
|
||||
$redis = StaticRedis::ReadOp();
|
||||
$deleted = false;
|
||||
foreach($fs->ListFiles() as $file) {
|
||||
$id = basename($file);
|
||||
$file_key = REDIS_PREFIX . $id;
|
||||
$lv = $redis->hGet($file_key, "lastview");
|
||||
$expire = time() - (30 * 24 * 60 * 60);
|
||||
|
||||
//use the file upload timestamp if there is no view data recorded
|
||||
//if the file upload time is greater than the current timestamp, mark as old (!!abuse!!)
|
||||
//this will also force legacy file uploads with no views to be deleted (header will always fail to load)
|
||||
if($lv === false) {
|
||||
$file_header = BlobFile::LoadHeader($file);
|
||||
if($file_header !== null && $file_header->Uploaded <= time()){
|
||||
$lv = $file_header->Uploaded;
|
||||
} else {
|
||||
//cant read file header or upload timestamp is invalid, mark as old
|
||||
$lv = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if($lv !== false && intval($lv) < $expire) {
|
||||
$nmsg = "Deleting expired file: " . $id . " (lastview=" . date("Y-m-d h:i:s", intval($lv)) . ")\n";
|
||||
if(strlen($pmsg) + strlen($nmsg) >= 2000){
|
||||
//send to discord public hook
|
||||
$pmsg = $pmsg . "`";
|
||||
Discord::SendPublic(array(
|
||||
"content" => $pmsg
|
||||
));
|
||||
$pmsg = "`";
|
||||
}
|
||||
$pmsg = $pmsg . $nmsg;
|
||||
unlink($file);
|
||||
$deleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
//send last message if any
|
||||
if(strlen($pmsg) > 0 && $deleted) {
|
||||
$pmsg = $pmsg . "`";
|
||||
Discord::SendPublic(array(
|
||||
"content" => $pmsg
|
||||
));
|
||||
}
|
||||
|
||||
if(StaticRedis::$IsConnectedToSlave == False) {
|
||||
echo "Runing master node tasks..\n";
|
||||
$fs = new FileStore(Config::$Instance->upload_folder, $_SERVER["cron_root"]);
|
||||
Stats::Collect($fs);
|
||||
}
|
||||
}
|
||||
|
26
src/php/discord.php
Normal file
26
src/php/discord.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
class Discord {
|
||||
public static function SendPublic($msg) : void {
|
||||
self::CallWebhook(Config::$Instance->discord_webhook_pub, $msg);
|
||||
}
|
||||
|
||||
private static function CallWebhook($url, $data) : void {
|
||||
self::CurlPost($url, json_encode($data));
|
||||
}
|
||||
|
||||
private static function CurlPost($url, $data) : ?string {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -73,7 +73,7 @@ static int curl_upload_read(void *ptr, size_t size, size_t nmemb, void *stream)
|
||||
|
||||
VBFPayloadHeader h;
|
||||
h.len = flen;
|
||||
h.mime = "application/x-msdownload";
|
||||
h.mime = DEFAULT_MIME;
|
||||
h.filename = state->filename;
|
||||
|
||||
state->bo->len = state->bi->len -= ENC_ALGO::BLOCKSIZE - sizeof(VBFHeader); //reduce by 1 block to allow space for header
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <argtable2.h>
|
||||
|
||||
#define CLI_VERSION "void_util v0.1"
|
||||
#define DEFAULT_MIME "application/octet-stream"
|
||||
#define DEFAULT_HOST "v3.void.cat"
|
||||
|
||||
struct arg_lit *verb, *help;
|
||||
struct arg_file *upload, *pack;
|
||||
|
Loading…
x
Reference in New Issue
Block a user