diff --git a/data/index.php b/data/index.php index d562a2c..4bdbe1f 100644 --- a/data/index.php +++ b/data/index.php @@ -134,19 +134,39 @@ $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); - // Check status - if ($status != 200) { - echo ''; - exit(); + if ($status == 200) { + // Parse result from Imgur + $pms = json_decode($output,true); + $page_url = 'https://imgur.com/'.$pms['data']['id']; + $image_url = $pms['data']['link']; + $delete_hash = $pms['data']['deletehash']; + // For debugging: var_dump($pms); + } else { + // Imgur API returned an error, try ImgBB + if ((getenv('IMGBB_KEY'))) { + $imgbb_post = [ + 'key' => getenv('IMGBB_KEY'), + 'image' => base64_encode($data), + 'expiration' => 120 + ]; + $ch = curl_init('https://api.imgbb.com/1/upload'); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $imgbb_post); + // Upload image to ImgBB + $output = curl_exec($ch); + curl_close($ch); + // TODO: Parse ImgBB errors + // Parse result + $pms = json_decode($output,true); + $page_url = $pms['data']['url']; // url_viewer is having issues + $image_url = $pms['data']['url']; + } else { + // Show error message + echo ''; + exit(); + } } - // Parse result - $pms = json_decode($output,true); - $id = $pms['data']['id']; - $imgurl = $pms['data']['link']; - $delete_hash = $pms['data']['deletehash']; - // For debugging: var_dump($pms); - // Send to Discord if enabled if (isset($_COOKIE["discord_webhook"])) { $webhook_curl = curl_init(); @@ -161,13 +181,13 @@ "embeds": [ { "title": "'.$software.'", - "url": "https://imgur.com/'.$id.'", + "url": "'.$page_url.'", "color": null, "footer": { "text": "Uploader: '.$_SERVER["HTTP_USER_AGENT"].'" }, "image": { - "url": "'.$imgurl.'" + "url": "'.$image_url.'" } } ], @@ -184,18 +204,25 @@ } // Display result + if (str_contains($page_url, 'imgur')) { + $host_options = ' +
+

+ +
+ '; + } else { + $host_options = '

The Imgur API was unavailable, ImgBB was used instead. You have two minutes to save your image before it is automatically deleted.

'; + } $out = '
'.$software.'
- - QR code (click to open page in new window) + + QR code (click to open page in new window) -
-

- -
+ '.$host_options.'
'; @@ -232,14 +259,6 @@
Upload Image
- If you can no longer connect to ImageShare on the 3DS, Wii U, or other legacy browser/device, replace HTTPS in the bookmark with HTTP.

'; - } - ?>

@@ -256,7 +275,8 @@

ImageShare is a lightweight web app for uploading images with QR codes, created for the Nintendo 3DS and other legacy web browsers. See tinyurl.com/imgsharegit for more information.

If you find ImageShare useful, please consider donating to support development and server costs!

-

cash.app/$corbdavpaypal.me/corbindav

+

patreon.com/corbindavenport

+

cash.app/$corbdavpaypal.me/corbindav


Join Discord server: discord.gg/tqJDRsmQVn

Follow on Mastodon: @corbin@toot.community diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml index 2c103bc..5426966 100644 --- a/docker-compose-prod.yml +++ b/docker-compose-prod.yml @@ -31,6 +31,7 @@ services: dockerfile: php/Dockerfile-production environment: API_KEY: ${API_KEY} + IMGBB_KEY: ${IMGBB_KEY} networks: - internal networks: diff --git a/docker-compose.yml b/docker-compose.yml index 691992f..6223125 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,6 +25,7 @@ services: image: php:fpm-alpine environment: API_KEY: ${API_KEY} + IMGBB_KEY: ${IMGBB_KEY} build: context: . dockerfile: php/Dockerfile