Jeremy Newman : remove appimage loader and load images from CDN

Jeremy Newman jnewman at winehq.org
Tue Sep 21 11:19:16 CDT 2021


Module: appdb
Branch: master
Commit: 0f74052d3a7f447d79d17ef1fcedcdd243d2f0fd
URL:    https://source.winehq.org/git/appdb.git/?a=commit;h=0f74052d3a7f447d79d17ef1fcedcdd243d2f0fd

Author: Jeremy Newman <jnewman at codeweavers.com>
Date:   Tue Sep 21 11:15:46 2021 -0500

remove appimage loader and load images from CDN

this should reduce load on the winehq webserver

---

 appimage.php              | 88 -----------------------------------------------
 include/config.php.sample |  1 +
 include/screenshot.php    | 33 ++++--------------
 3 files changed, 7 insertions(+), 115 deletions(-)

diff --git a/appimage.php b/appimage.php
deleted file mode 100644
index f4d1b58..0000000
--- a/appimage.php
+++ /dev/null
@@ -1,88 +0,0 @@
-<?php
-/**
- * Shows a thumbnail or a full size screenshot.
- *
- * Mandatory parameters:
- *  - iId, image identifier
- * 
- * Optional parameters:
- *  - bThumbnail, "true" if we want to see a thumbnail, "false" otherwise
- *  - sREQUEST_METHOD
- * 
- * TODO:
- *  - rename and document sREQUEST_METHOD
- *  - replace iId with iScreenshotId
- */
-
-/**
- *  parse all the date formats required by HTTP 1.1 into PHP time values
- */
-function pHttpDate($sDate) {
-   $iDate = strtotime($sDate);
-   if ($iDate != -1) return $iDate;
-        /* the RFC also requires asctime() format... */
-   $aTs = strptime($sDate,"%a %b  %e %H:%M:%S %Y");
-   $iDate = gmmktime($aTs[2],$aTs[1],$aTs[0],$aTs[4],$aTs[3],$aTs[5],0);
-   return $iDate;
-}
-
-// application environment
-require("path.php");
-require(BASE."include/incl.php");
-require_once(BASE."include/screenshot.php");
-
-// an image doesn't have a link, so a cookie makes no sense
-header("Set-Cookie: ");
-header("Pragma: ");
-
-// is the user supposed to be viewing this image ?
-if(!$_SESSION['current']->canViewImage($aClean['iId']))
-    util_show_error_page_and_exit("Insufficient privileges.");
-
-$oScreenshot = new Screenshot($aClean['iId']);
-$fImage = fopen(appdb_fullpath("data/screenshots/".$oScreenshot->sUrl), "rb");
-
-/* if we can open the image we should get its last modified time and read */
-/* a few bytes from its header information and close it */
-if($fImage)
-{
-   $fstat_val = fstat($fImage);
-   $iModTime = $fstat_val['mtime'];
-   $sMagic = fread($fImage, 8); /* read 8 bytes from the header, that lets us idenfity the type of
-                                 image without loading it */
-   fclose($fImage); /* don't leave the fopened image open */
-}
-
-/* identify what kind of image this is, if we can't identify it */
-/* we should report that its a bad image */
-if (strcmp("\x89PNG\r\n\x1A\n", $sMagic)==0) 
-{
-    header("Content-Type: image/png");
-} else if (preg_match("^\xD8\xFF^", $sMagic)) {
-    header("Content-Type: image/jpeg");
-} else {
-    header("500 Bad image format");
-    exit;
-}
-
-header("Cache-Control: public");
-header("Expires: ");
-
-/* if the browser is asking if the file was modified since a particular date */
-/* and the date is the same that the file was modified, then we can report */
-/* that the file wasn't modified, the browser can used the cached image */
-if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && 
-    $iModTime == pHttpDate($_SERVER['HTTP_IF_MODIFIED_SINCE']))
-{
-   header("HTTP/1.0 304 Not Modified");
-   exit;
-}
-
-header("Last-Modified: ".gmdate("D, d M Y H:i:s",$iModTime)." GMT");
-
-if(!$aClean['bThumbnail'])
-    $oScreenshot->output_screenshot(false);
-else
-    $oScreenshot->output_screenshot(true);
-
-?>
diff --git a/include/config.php.sample b/include/config.php.sample
index f75d6d8..8531dca 100644
--- a/include/config.php.sample
+++ b/include/config.php.sample
@@ -18,6 +18,7 @@ define("APPDB_OWNER","WineHQ"); // with what product/company is this AppDB relat
 define("APPDB_OWNER_URL","https://www.winehq.org/"); // website of this product/company
 define("APPDB_OWNER_EMAIL","appdb at winehq.org"); // e-mail of this product/company
 define("APPDB_SENDER_EMAIL","appdb-noreply at winehq.org"); // The e-mail address which appears as the sender in mails sent by the AppDB
+define("APPDB_SCREENSHOT_URL","https://dl.winehq.org/winehq/appdb/"); // CDN URL of WineHQ appdb images, leave empty to use local
 define("BUGZILLA_ROOT","https://bugs.winehq.org/"); // path to bugzilla
 
 // Google reCaptcha Secret Key - required on account creations
diff --git a/include/screenshot.php b/include/screenshot.php
index a2f4da2..9102aa0 100644
--- a/include/screenshot.php
+++ b/include/screenshot.php
@@ -316,24 +316,6 @@ class screenshot
         return array();
     }
 
-    function get_screenshot_height()
-    {
-        $this->load_image(false);
-        return $this->oScreenshotImage->get_height();
-    }
-
-    function get_thumbnail_width()
-    {
-        $this->load_image(true);
-        return $this->oThumbnailImage->get_width();
-    }
-
-    function get_thumbnail_height()
-    {
-        $this->load_image(true);
-        return $this->oThumbnailImage->get_height();
-    }
-
     function objectGetSubmitterId()
     {
         return $this->iSubmitterId;
@@ -577,16 +559,13 @@ class screenshot
 
     function get_thumbnail_img()
     {
-        $sImgUrl = apidb_fullurl("appimage.php").'?iId='.$this->iScreenshotId;
-        $sImgWidth = $this->get_thumbnail_width();
-        $sImgHeight = $this->get_thumbnail_height();
-        if (!$sImgWidth)
-            $sImgWidth = '130';
-        if (!$sImgHeight)
-            $sImgHeight = '100';
+        if (defined("APPDB_SCREENSHOT_URL") and !empty(APPDB_SCREENSHOT_URL))
+            $url = APPDB_SCREENSHOT_URL;
+        else
+            $url = APPDB_ROOT."data/";
         $this->sDescription = preg_replace('/\n/', '', $this->sDescription);
-        return "<div class=\"whq-shot\"><img src=\"{$sImgUrl}&bThumbnail=true\" style=\"width:{$sImgWidth}px;height:{$sImgHeight}px;\" ".
-               "alt=\"{$this->sDescription}\" data-shot=\"{$sImgUrl}\"><i class=\"fa fa-search-plus\"></i></div>\n";
+        return "<div class=\"whq-shot\"><img src=\"".APPDB_SCREENSHOT_URL."thumbnails/".$this->iScreenshotId."\" style=\"width:130px;\" ".
+               "alt=\"{$this->sDescription}\" data-shot=\"".APPDB_SCREENSHOT_URL.$this->iScreenshotId."\"><i class=\"fa fa-search-plus\"></i></div>\n";
     }
 
     public static function objectGetItemsPerPage($sState = 'accepted')




More information about the wine-cvs mailing list