<commit_before><?php
include "var/pswd.php";
//ini_set('display_errors', 1);
if( !isset($_GET['hash']) ) {
	$hash = "QmYqA8GiZ4MCeyJkERReLwGRnjSdQBx5SzjvMgiNwQZfx6";
} else {
	if (preg_match('/^([A-z0-9])+$/', $_GET['hash']) ) {
		$hash = $_GET['hash'];
	} else {
		exit("wrong hash");
	}
}


define("defaultTitle", "A picture hosted on the permanent web");
define("defaultThumbnail", "http://ipfs.pics/ipfs/$hash");
define("defaultDescription", "Click to see it");

$db = new PDO('mysql:host=localhost;dbname=hashes;charset=utf8', $db_user, $db_pswd);

$info = $db->query("SElECT * FROM hash_info WHERE hash='$hash'")->fetch();

if ( $info['hash'] ) {
	$isDir = ($info['type'] == "dir");
	$isBanned = $info['banned'];
	$dirContent = `curl localhost:8090/$hash?dirContent`;
	$isBackendWorking = True;
	$isSafe = $info['sfw'];
} else {
	$isBanned = false;
	$isSafe = false;
	$dirContent = `curl localhost:8090/$hash?dirContent`;
	$isBackendWorking = $dirContent != "";
	$isDir = ($dirContent != "empty" and count(split(" ", explode(PHP_EOL, $dirContent)[0])) > 3);
	if ($isDir) {
		$type = "dir";
	} else {
		$type = "file";
	}
	if($dirContent != "") {
		$add = $db->prepare("INSERT INTO hash_info (hash, type, first_seen) VALUES (:hash, :type, UNIX_TIMESTAMP())");
		$add->execute(array(
			"hash" => $hash,
			"type" => $type
		));
	}
}


$title = constant("defaultTitle");
$thumbnail = constant("defaultThumbnail");
$description = constant("defaultDescription");

if ($isDir and !$isBanned and $isBackendWorking) {
	$size = `curl localhost:8090/$hash?size`;
	$lines = explode(PHP_EOL, $dirContent);	
	array_pop($lines);
	list ($firstElementHash, $firstElementSize, $firstElementName) = split(" ", $lines[0]);
	if ( $firstElementSize < 400 ) {
		$title = `curl localhost:8080/ipfs/$firstElementHash`;
		foreach ( $lines as $e ) {
			list ($eHash, $eSize, $eName) = split(" ", $e);
			if ($eSize > 400) {
				$thumbnail = "http://ipfs.pics/ipfs/$eHash";
				break;
			}	
		}	
		foreach ( $lines as $e ) {<commit_msg>fix for random deletion of unpined hashes not uploaded directly<commit_after><?php
include "var/pswd.php";
//ini_set('display_errors', 1);
if( !isset($_GET['hash']) ) {
	$hash = "QmYqA8GiZ4MCeyJkERReLwGRnjSdQBx5SzjvMgiNwQZfx6";
} else {
	if (preg_match('/^([A-z0-9])+$/', $_GET['hash']) ) {
		$hash = $_GET['hash'];
	} else {
		exit("wrong hash");
	}
}


define("defaultTitle", "A picture hosted on the permanent web");
define("defaultThumbnail", "http://ipfs.pics/ipfs/$hash");
define("defaultDescription", "Click to see it");

$db = new PDO('mysql:host=localhost;dbname=hashes;charset=utf8', $db_user, $db_pswd);

$info = $db->query("SElECT * FROM hash_info WHERE hash='$hash'")->fetch();

if ( $info['hash'] ) {
	$isDir = ($info['type'] == "dir");
	$isBanned = $info['banned'];
	$dirContent = `curl localhost:8090/$hash?dirContent`;
	$isBackendWorking = True;
	$isSafe = $info['sfw'];
} else {
	$isBanned = false;
	$isSafe = false;
	$dirContent = `curl localhost:8090/$hash?dirContent`;
	$isBackendWorking = $dirContent != "";
	$isDir = ($dirContent != "empty" and count(split(" ", explode(PHP_EOL, $dirContent)[0])) > 3);
	if ($isDir) {
		$type = "dir";
	} else {
		$type = "file";
	}
	if($dirContent != "") {
		$add = $db->prepare("INSERT INTO hash_info (hash, type, first_seen) VALUES (:hash, :type, UNIX_TIMESTAMP())");
		$add->execute(array(
			"hash" => $hash,
			"type" => $type
		));
		$x = `ipfs pin -r $hash`;
	}
}


$title = constant("defaultTitle");
$thumbnail = constant("defaultThumbnail");
$description = constant("defaultDescription");

if ($isDir and !$isBanned and $isBackendWorking) {
	$size = `curl localhost:8090/$hash?size`;
	$lines = explode(PHP_EOL, $dirContent);	
	array_pop($lines);
	list ($firstElementHash, $firstElementSize, $firstElementName) = split(" ", $lines[0]);
	if ( $firstElementSize < 400 ) {
		$title = `curl localhost:8080/ipfs/$firstElementHash`;
		foreach ( $lines as $e ) {
			list ($eHash, $eSize, $eName) = split(" ", $e);
			if ($eSize > 400) {
				$thumbnail = "http://ipfs.pics/ipfs/$eHash";
				break;
			}	
		}	
		foreach ( $lines as $e ) {
{'fraction_non_alphanumeric': 0.21338199513381995, 'fraction_numerical': 0.016058394160583942, 'mean_word_length': 4.983988355167394, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3541561', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1589, 'n_words': 316}