Skip to content

Commit

Permalink
Fixing logging, cleanup js, general code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Sylvester committed Feb 10, 2023
1 parent 630f56b commit 3210e13
Show file tree
Hide file tree
Showing 3 changed files with 315 additions and 391 deletions.
57 changes: 11 additions & 46 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,17 @@ function getFileExt($fname)
// Return file hash
if (isset($_GET['hash']))
{

// Get file hash array and JSON encode it
$hashes = $lister->getFileHash($_GET['hash']);
$data = json_encode($hashes);

// Return the data
die($data);

}

if (isset($_GET['zip']))
{

$dirArray = $lister->zipDirectory($_GET['zip']);

}
else if(isset($_GET['file']))
{
Expand All @@ -67,20 +63,24 @@ function getFileExt($fname)
}
else
{

// Init temporary array to handle data
$downloads = array();

// Now it should exist regardless
if (file_exists("$path/resources/log") !== false)
if (file_exists($path."/resources/log") !== false)
{
$file = fopen("$path/resources/log","r");
$file = $path."/resources/log";

$downloads = array();

// Get file contents into array
$downloads = unserialize(fread($file,filesize("$path/resources/log")));
$log_content = unserialize(file_get_contents($file));

fclose($file);

if ($log_content != null && $log_content != "" && $log_content != " " && count($log_content) != 0)
{
$downloads = $log_content;
}

// Check if the key or filename already is in the array else append it
if (array_key_exists($fname, $downloads))
{
Expand All @@ -91,42 +91,7 @@ function getFileExt($fname)
$downloads[$fname] = 1;
}

// Massive debug code to figure out why this constantly overwrites with bad data

$debugfile = "$path/resources/log".time();

//touch($debugfile);
//$file = fopen($debugfile,"w");
//fwrite($file,serialize($downloads));
//fclose($file);


try
{
$file = fopen("$path/resources/log","w");

}
catch (Exception $e)
{
$file = fopen("$path/resources/logerror","w");
fwrite($file,$e->getMessage()."\n");
fclose($file);
}

try
{
fwrite($file,serialize($downloads));
}
catch (Exception $e)
{
$file = fopen("$path/resources/logerror","w");
fwrite($file,$e->getMessage()."\n");
fclose($file);
}

fclose($file);


file_put_contents($file, serialize($downloads));
}


Expand Down
Loading

0 comments on commit 3210e13

Please sign in to comment.