Handle first line as nex format, limit file size to 10k

This commit is contained in:
Alexander 2023-07-30 02:46:16 +02:00
parent 90fd17c089
commit 897ed3f574
2 changed files with 13 additions and 5 deletions

View File

@ -43,9 +43,13 @@ if(strtolower(substr($path, -4, 4))==".jpg" || strtolower(substr($path, -5, 5))=
fwrite($fp, $path);
fwrite($fp, "\n");
$size=0;
while(!feof($fp)) {
$line=fread($fp, 4096);
echo($line);
$size+=strlen($fp);
if($size>10240) break;
}
fclose($fp);
} else {
@ -62,9 +66,10 @@ if(strtolower(substr($path, -4, 4))==".jpg" || strtolower(substr($path, -5, 5))=
echo "20 text/gemini\r\n";
echo "Nex url: ",$proto."//".$host.$path,"\n";
echo "\n";
echo $line;
while(($line=fgets($fp))!==false) {
$size=0;
do {
if(substr($line, 0, 2)=="=>") {
$line=substr($line, 0, strlen($line)-1);
if(preg_match("/^=>[^ ]/", $line)) {
@ -72,7 +77,7 @@ if(strtolower(substr($path, -4, 4))==".jpg" || strtolower(substr($path, -5, 5))=
}
$parts=explode(" ", $line, 3);
$link=$parts[1];
$text=$parts[2];
$text=count($parts)>2 ? $parts[2] : "";
if(substr($link, 0, 4)=="nex:") {
$line="=> nex.php?".urlencode($link)." ".$link." ".$text."\n";
@ -89,7 +94,10 @@ if(strtolower(substr($path, -4, 4))==".jpg" || strtolower(substr($path, -5, 5))=
}
}
echo $line;
}
$size+=strlen($line);
if($size>10240) break;
} while(($line=fgets($fp))!==false);
fclose($fp);
}

View File

@ -6,6 +6,6 @@ without any relevant order
=> gemini://raek.se/ Raek, user from Tilde chat
=> gemini://raek.se/orbits/space-elevator/ webring site run by Raek
=> gopher://gopher.black/ Tomasino, user from Tilde chat
=> gemini://bsdforall.org/pantasya siesta, user from Tilde chat
=> .. back to start page