working in just 70 minutes!
This commit is contained in:
parent
27aa2e870c
commit
0ceacf6390
4 changed files with 115 additions and 1 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.idea/
|
58
LBRY.class.php
Normal file
58
LBRY.class.php
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
if (!defined('ROOT_PAGE')) { die('not allowed'); }
|
||||||
|
|
||||||
|
class LBRY
|
||||||
|
{
|
||||||
|
public static function api($function, array $params = [])
|
||||||
|
{
|
||||||
|
$ch = curl_init();
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_URL, 'http://localhost:5279/lbryapi');
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['method' => $function, 'params' => $params]));
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
|
$server_output = curl_exec($ch);
|
||||||
|
|
||||||
|
if ($server_output)
|
||||||
|
{
|
||||||
|
$responseData = json_decode($server_output, true);
|
||||||
|
return $responseData['result'];
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_close ($ch);
|
||||||
|
|
||||||
|
return $server_output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function findTopPublicFreeClaim($name)
|
||||||
|
{
|
||||||
|
$claims = LBRY::api('claim_list', ['name' => $name]);
|
||||||
|
if (!$claims || !isset($claims['claims']))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$freePublicClaims = array_filter($claims['claims'], function($claim) {
|
||||||
|
$metadata = json_decode($claim['value'], true);
|
||||||
|
return
|
||||||
|
//TODO: Expand these checks
|
||||||
|
($metadata['license'] == "Public Domain" || stripos($metadata['license'], 'Creative Commons') !== false) &&
|
||||||
|
!isset($metadata['fee']);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (count($freePublicClaims) > 1)
|
||||||
|
{
|
||||||
|
usort($freePublicClaims, function($claimA, $claimB) {
|
||||||
|
if ($claimA['amount'] == $claimB['amount'])
|
||||||
|
{
|
||||||
|
return $claimA['height'] < $claimB['height'] ? -1 : 1;
|
||||||
|
}
|
||||||
|
return $claimA['amount'] > $claimB['amount'] ? -1 : 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return reset($freePublicClaims);
|
||||||
|
}
|
||||||
|
}
|
37
image.php
Normal file
37
image.php
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
if (!defined('ROOT_PAGE')) { die('not allowed'); }
|
||||||
|
|
||||||
|
$claim = LBRY::findTopPublicFreeClaim($name);
|
||||||
|
|
||||||
|
//echo '<pre>';
|
||||||
|
//print_r($claim);
|
||||||
|
//die('over');
|
||||||
|
|
||||||
|
if ($claim)
|
||||||
|
{
|
||||||
|
$getResult = LBRY::api('get', ['name' => $name, 'claim_id' => $claim['claim_id']]);
|
||||||
|
|
||||||
|
if (isset($getResult['completed']) && $getResult['completed'] && isset($getResult['download_path']))
|
||||||
|
{
|
||||||
|
$path = $getResult['download_path'];
|
||||||
|
header('Content-type: image/jpeg');
|
||||||
|
header('Content-length: ' . filesize($path));
|
||||||
|
readfile($getResult['download_path']);
|
||||||
|
}
|
||||||
|
elseif (isset($getResult['written_bytes']))
|
||||||
|
{
|
||||||
|
echo 'This image is on it\'s way... maybe.<br/>';
|
||||||
|
echo 'Received: ' . $getResult['written_bytes'] . " / " . $getResult['total_bytes'] . ' bytes';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo 'There seems to be a valid claim, but are having trouble retrieving the content.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo 'No valid claim for this name. Make one! https://lbry.io/quickstart';
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(0);
|
18
index.php
18
index.php
|
@ -1,5 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
define('ROOT_PAGE', 1);
|
||||||
|
|
||||||
|
require_once './LBRY.class.php';
|
||||||
|
|
||||||
|
$name = ltrim(urldecode($_SERVER['REQUEST_URI']), '/');
|
||||||
|
|
||||||
|
if ($name)
|
||||||
|
{
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
|
||||||
|
include './image.php';
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<h1>spee.ch</h1>
|
<h1>spee.ch</h1>
|
||||||
|
<p>OMG we are live, it is actually happening. It is still happening.</p>
|
||||||
<p>In just a few hours, this site will morph from this utterly bare 6 lines of HTML into a decentralized, censorship-resistant, truly free image sharing site powered by <a href="https://lbry.io">LBRY</a>.
|
<p>In just a few hours, this site will morph from this utterly bare 6 lines of HTML into a decentralized, censorship-resistant, truly free image sharing site powered by <a href="https://lbry.io">LBRY</a>.
|
||||||
<p>You can watch it happen in real time, starting at 6pm EST tonight (March 29th):</p>
|
<p>You can watch it happen in real time, starting at 6pm EST tonight (March 29th):</p>
|
||||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/C9LCapt_OYw" frameborder="0" allowfullscreen></iframe>
|
<iframe width="560" height="315" src="https://www.youtube.com/embed/C9LCapt_OYw" frameborder="0" allowfullscreen></iframe>
|
||||||
|
|
Loading…
Reference in a new issue