working publish

This commit is contained in:
Jeremy Kauffman 2017-03-29 20:40:44 -04:00
parent e8ba08b030
commit de012aacab
4 changed files with 65 additions and 26 deletions

View file

@ -18,6 +18,10 @@ class LBRY
if ($server_output)
{
$responseData = json_decode($server_output, true);
if (isset($responseData['error']))
{
throw new Exception($responseData['error']['message'] ?? 'Something unknown went wrong');
}
return $responseData['result'];
}
@ -26,6 +30,27 @@ class LBRY
return $server_output;
}
public static function publishPublicClaim($name, $tmpFileName)
{
$filePath = '/home/lbry/spee.ch/publishes/newupload-' . random_int(1, PHP_INT_MAX);
move_uploaded_file($tmpFileName, $filePath);
$apiResult = LBRY::api('publish', [
'name' => $name,
'bid' => 1,
'file_path' => $filePath,
'description' => 'An image published from spee.ch',
'author' => 'https://spee.ch',
'language' => 'en',
'license' => 'Public Domain',
'nsfw' => 0,
'title' => 'Image published from spee.ch'
]);
return isset($apiResult['claim_id']);
}
public static function findTopPublicFreeClaim($name)
{
$claims = LBRY::api('claim_list', ['name' => $name]);

View file

@ -19,7 +19,7 @@ if ($claim)
}
elseif (isset($getResult['written_bytes']))
{
echo 'This image is on it\'s way... maybe.<br/>';
echo 'This image is on it\'s way...<br/>';
echo 'Received: ' . $getResult['written_bytes'] . " / " . $getResult['total_bytes'] . ' bytes';
}
else
@ -27,9 +27,14 @@ if ($claim)
echo 'There seems to be a valid claim, but are having trouble retrieving the content.';
}
}
elseif (isset($_GET['new']) && $_GET['new'])
{
echo 'Your image is on the way. It can take a few minutes to reach the blockchain and be public. You can refresh this page to check the progress.';
}
else
{
echo 'No valid claim for this name. Make one! https://lbry.io/quickstart';
echo 'No valid claim for this name. Make one!';
include './publish.php';
}
exit(0);

View file

@ -8,26 +8,36 @@ define('ROOT_PAGE', 1);
require_once './LBRY.class.php';
$name = ltrim(urldecode($_SERVER['REQUEST_URI']), '/');
if ($name == 'publish')
{
include './publish.php';
exit(0);
}
elseif ($name)
if ($name)
{
include './image.php';
exit(0);
}
if (isset($_POST['publish']) && isset($_POST['name']) && isset($_FILES['file']))
{
$success = LBRY::publishPublicClaim($_POST['name'], $_FILES['file']['tmp_name']);
if ($success)
{
header('Location: /' . $_POST['name'] . '?new=1');
}
else
{
echo '<p>Something went wrong publishing your content. We are only somewhat sorry.</p>';
}
exit(0);
}
?>
<!DOCTYPE html>
<h1>spee.ch</h1>
<p>spee.ch is a single-serving site that reads (and will soon publish) images to and from the LBRY blockchain.</p>
<p>You can watch live right now as it is being built!</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/C9LCapt_OYw" frameborder="0" allowfullscreen></iframe>
<p>Here are some sample images:</p>
<p>spee.ch is a single-serving site that read and publish images to and from the LBRY blockchain.</p>
<p>Examples:</p>
<ul>
<?php foreach(['thailand', 'doitlive', 'coconuts', 'cow-air-balloon'] as $name): ?>
<li><a href="/<?php echo $name ?>">spee.ch/<?php echo $name ?></a></li>
<?php foreach(['thailand', 'doitlive', 'coconuts', 'cow-air-balloon'] as $sampleName): ?>
<li><a href="/<?php echo $sampleName ?>">spee.ch/<?php echo $sampleName ?></a></li>
<?php endforeach ?>
</ul>
<p>Publishing coming in just a few minutes!</p>
<h3>Publish Your Own</h3>
<?php include './publish.php' ?>
<h3>About This Site</h3>
<p>It was built live in a little over 2 hours on March 29th, 2017. You can watch the video here:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/C9LCapt_OYw" frameborder="0" allowfullscreen></iframe>

View file

@ -1,15 +1,14 @@
<?php
if (isset($_POST['file']))
{
print_r($_POST['file']);
}
?>
<!DOCTYPE html>
<h1>Publish</h1>
<form method="POST" action="/publish" enctype="multipart/form-data">
<form method="POST" action="/" enctype="multipart/form-data">
<div>
<input type="file" name="file" />
</div>
<input type="submit" name="key" value="Go" />
<?php if (isset($name) && $name != ''): ?>
<input type="hidden" name="name" value="<?php echo $name ?>" />
<?php else: ?>
<div>
lbry://<input type="text" name="name" />
</div>
<?php endif ?>
<input type="submit" name="publish" value="Go" />
<p>Publishing can take a few moments. Please be patient.</p>
</form>