Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 } );
}
Expand Down
10 changes: 9 additions & 1 deletion public_html/class-mshots.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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",
Expand Down