From e8ba08b03092cbf0f33834ea9be7ab8b67a1951e Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Wed, 29 Mar 2017 19:49:26 -0400 Subject: [PATCH 1/3] ready for publish! --- LBRY.class.php | 2 +- image.php | 6 ++---- index.php | 27 ++++++++++++++++++--------- publish.php | 15 +++++++++++++++ 4 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 publish.php diff --git a/LBRY.class.php b/LBRY.class.php index 85906bef..b7eaef79 100644 --- a/LBRY.class.php +++ b/LBRY.class.php @@ -37,7 +37,7 @@ class LBRY $freePublicClaims = array_filter($claims['claims'], function($claim) { $metadata = json_decode($claim['value'], true); return - //TODO: Expand these checks + //TODO: Expand these checks AND verify it is an image claim! ($metadata['license'] == "Public Domain" || stripos($metadata['license'], 'Creative Commons') !== false) && !isset($metadata['fee']); }); diff --git a/image.php b/image.php index 7e6215d8..89a53493 100644 --- a/image.php +++ b/image.php @@ -4,10 +4,6 @@ if (!defined('ROOT_PAGE')) { die('not allowed'); } $claim = LBRY::findTopPublicFreeClaim($name); -//echo '
';
-//print_r($claim);
-//die('over');
-
 if ($claim)
 {
   $getResult = LBRY::api('get', ['name' => $name, 'claim_id' => $claim['claim_id']]);
@@ -15,6 +11,8 @@ if ($claim)
   if (isset($getResult['completed']) && $getResult['completed'] && isset($getResult['download_path']))
   {
     $path = $getResult['download_path'];
+    //TODO, verify it is an image
+    //TODO: serve the correct content type!
     header('Content-type: image/jpeg');
     header('Content-length: ' . filesize($path));
     readfile($getResult['download_path']);
diff --git a/index.php b/index.php
index a13ea6f5..0221f180 100644
--- a/index.php
+++ b/index.php
@@ -1,24 +1,33 @@
 
 
 

spee.ch

-

OMG we are live, it is actually happening. It is still happening.

-

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 LBRY. -

You can watch it happen in real time, starting at 6pm EST tonight (March 29th):

+

spee.ch is a single-serving site that reads (and will soon publish) images to and from the LBRY blockchain.

+

You can watch live right now as it is being built!

-

GitHub repo

+

Here are some sample images:

+ +

Publishing coming in just a few minutes!

diff --git a/publish.php b/publish.php new file mode 100644 index 00000000..db2e8c5f --- /dev/null +++ b/publish.php @@ -0,0 +1,15 @@ + + +

Publish

+
+
+ +
+ +
\ No newline at end of file From 0f7875eedad179bbbd8a6eb910bdd561d9908d75 Mon Sep 17 00:00:00 2001 From: Filip Hendrik Date: Thu, 30 Mar 2017 02:21:14 +0200 Subject: [PATCH 2/3] Filter on and output the correct content type. --- LBRY.class.php | 1 + image.php | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/LBRY.class.php b/LBRY.class.php index b7eaef79..0a5008b1 100644 --- a/LBRY.class.php +++ b/LBRY.class.php @@ -39,6 +39,7 @@ class LBRY return //TODO: Expand these checks AND verify it is an image claim! ($metadata['license'] == "Public Domain" || stripos($metadata['license'], 'Creative Commons') !== false) && + in_array($metadata['content_type'], ['image/jpeg', 'image/png']) && !isset($metadata['fee']); }); diff --git a/image.php b/image.php index 89a53493..d09f3469 100644 --- a/image.php +++ b/image.php @@ -11,9 +11,7 @@ if ($claim) if (isset($getResult['completed']) && $getResult['completed'] && isset($getResult['download_path'])) { $path = $getResult['download_path']; - //TODO, verify it is an image - //TODO: serve the correct content type! - header('Content-type: image/jpeg'); + header('Content-type: ' . $getResult['metadata']['content_type']); header('Content-length: ' . filesize($path)); readfile($getResult['download_path']); } From de012aacab1d3d9dfe0efedb2f9c9db17e807099 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Wed, 29 Mar 2017 20:40:44 -0400 Subject: [PATCH 3/3] working publish --- LBRY.class.php | 25 +++++++++++++++++++++++++ image.php | 9 +++++++-- index.php | 36 +++++++++++++++++++++++------------- publish.php | 21 ++++++++++----------- 4 files changed, 65 insertions(+), 26 deletions(-) diff --git a/LBRY.class.php b/LBRY.class.php index b7eaef79..2f5ae58a 100644 --- a/LBRY.class.php +++ b/LBRY.class.php @@ -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]); diff --git a/image.php b/image.php index 89a53493..5f501234 100644 --- a/image.php +++ b/image.php @@ -19,7 +19,7 @@ if ($claim) } elseif (isset($getResult['written_bytes'])) { - echo 'This image is on it\'s way... maybe.
'; + echo 'This image is on it\'s way...
'; 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); diff --git a/index.php b/index.php index 0221f180..b088882c 100644 --- a/index.php +++ b/index.php @@ -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 '

Something went wrong publishing your content. We are only somewhat sorry.

'; + } + exit(0); +} ?>

spee.ch

-

spee.ch is a single-serving site that reads (and will soon publish) images to and from the LBRY blockchain.

-

You can watch live right now as it is being built!

- -

Here are some sample images:

+

spee.ch is a single-serving site that read and publish images to and from the LBRY blockchain.

+

Examples:

-

Publishing coming in just a few minutes!

+

Publish Your Own

+ +

About This Site

+

It was built live in a little over 2 hours on March 29th, 2017. You can watch the video here:

+ diff --git a/publish.php b/publish.php index db2e8c5f..c9cb46a8 100644 --- a/publish.php +++ b/publish.php @@ -1,15 +1,14 @@ - - -

Publish

-
+
- + + + +
+ lbry:// +
+ + +

Publishing can take a few moments. Please be patient.

\ No newline at end of file