From c3d5ff3218fa64c84dbdb0d75c4ce0ceb30405ef Mon Sep 17 00:00:00 2001 From: Enej Bajgoric Date: Wed, 21 Oct 2020 16:13:57 -0700 Subject: [PATCH] Adds thumbnails-permanent for specific host --- lib/worker.js | 12 ++++++++++-- public_html/class-mshots.php | 10 +++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/worker.js b/lib/worker.js index 5d64035..3eefac9 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -71,11 +71,19 @@ function validateFileName( request ) { let s_filename = _cypher.createHash( 'md5' ).update( request.url ).digest( 'hex' ) + viewport + '.jpg'; let s_host = _cypher.createHash( 'sha1' ).update( host ).digest( 'hex' ); - let s_fullpath = '/opt/mshots/public_html/thumbnails/' + s_host.substring( 0, 3 ) + "/" + s_host + "/" + s_filename; + let s_fullpath = getPath( host ) + s_host.substring( 0, 3 ) + "/" + s_host + "/" + s_filename; return ( s_fullpath == request.file ); } +function getPath( host ) { + logger.error( 'getPath host: ' + host ); + if ( 'public-api.wordpress.com' === host ) { + return '/opt/mshots/public_html/thumbnails-permanent/'; + } + return '/opt/mshots/public_html/thumbnails/'; +} + var HTTPListner = function() { var routes = { @@ -124,7 +132,7 @@ var HTTPListner = function() { } if ( ! validateFileName( site ) ) { - logger.error( process.pid + ': invalid filename: validation failed' ); + logger.error( process.pid + ': invalid filename: validation failed :' + site ); } else { process.send( { replytype: 'queue-add', workerid: process.pid, payload: site } ); } diff --git a/public_html/class-mshots.php b/public_html/class-mshots.php index f31a4e8..444a801 100644 --- a/public_html/class-mshots.php +++ b/public_html/class-mshots.php @@ -8,6 +8,7 @@ class mShots { const disable_requeue = false; const location_header = 'X-Accel-Redirect: '; const location_base = '/opt/mshots/public_html/thumbnails'; + const permanent_base = '/opt/mshots/public_html/thumbnails-permanent'; const snapshot_default = 'https://s0.wp.com/mshots/v1/default'; const snapshot_default_file = '/opt/mshots/public_html/images/default.gif'; @@ -278,11 +279,18 @@ private function resolve_filename( $snap_url ) { $viewport = ''; if ( $this->viewport_w != self::VIEWPORT_DEFAULT_W || $this->viewport_h != self::VIEWPORT_DEFAULT_H ) $viewport = '_' . $this->viewport_w . 'x' . $this->viewport_h; - $fullpath = self::location_base . '/' . substr( $host, 0, 3 ) . '/' . $host . '/' . $file . $viewport. '.jpg'; + $fullpath = $this->get_base( $s_host ) . '/' . substr( $host, 0, 3 ) . '/' . $host . '/' . $file . $viewport. '.jpg'; return $fullpath; } + private function get_base( $host ) { + if ( 'public-api.wordpress.com' === $host ) { + return self::permanent_base; + } + return self::location_base; + } + private function resolve_mshots_url( $url ) { return sprintf( "/mshots/v1/%s",