Remove unused file transforms

Summary:
Ref T7707.

  - Modernize the file transform endpoint a bit.
  - Delete transforms which are no longer used in the product.

Test Plan:
  - Used Pholio (navigation, inline thumbs).
  - Uploaded images (embed thumb).
  - Changed profile picture (profile thumb).

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7707

Differential Revision: https://secure.phabricator.com/D12807
This commit is contained in:
epriestley
2015-05-12 06:16:08 -07:00
parent 6c049d06ce
commit ae32d1afb8
13 changed files with 20 additions and 101 deletions

View File

@@ -2824,7 +2824,6 @@ phutil_register_library_map(array(
'PholioImageUploadController' => 'applications/pholio/controller/PholioImageUploadController.php', 'PholioImageUploadController' => 'applications/pholio/controller/PholioImageUploadController.php',
'PholioInlineController' => 'applications/pholio/controller/PholioInlineController.php', 'PholioInlineController' => 'applications/pholio/controller/PholioInlineController.php',
'PholioInlineListController' => 'applications/pholio/controller/PholioInlineListController.php', 'PholioInlineListController' => 'applications/pholio/controller/PholioInlineListController.php',
'PholioInlineThumbController' => 'applications/pholio/controller/PholioInlineThumbController.php',
'PholioMock' => 'applications/pholio/storage/PholioMock.php', 'PholioMock' => 'applications/pholio/storage/PholioMock.php',
'PholioMockCommentController' => 'applications/pholio/controller/PholioMockCommentController.php', 'PholioMockCommentController' => 'applications/pholio/controller/PholioMockCommentController.php',
'PholioMockEditController' => 'applications/pholio/controller/PholioMockEditController.php', 'PholioMockEditController' => 'applications/pholio/controller/PholioMockEditController.php',
@@ -6311,7 +6310,6 @@ phutil_register_library_map(array(
'PholioImageUploadController' => 'PholioController', 'PholioImageUploadController' => 'PholioController',
'PholioInlineController' => 'PholioController', 'PholioInlineController' => 'PholioController',
'PholioInlineListController' => 'PholioController', 'PholioInlineListController' => 'PholioController',
'PholioInlineThumbController' => 'PholioController',
'PholioMock' => array( 'PholioMock' => array(
'PholioDAO', 'PholioDAO',
'PhabricatorMarkupInterface', 'PhabricatorMarkupInterface',

View File

@@ -3,43 +3,36 @@
final class PhabricatorFileTransformController final class PhabricatorFileTransformController
extends PhabricatorFileController { extends PhabricatorFileController {
private $transform;
private $phid;
private $key;
public function shouldRequireLogin() { public function shouldRequireLogin() {
return false; return false;
} }
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->transform = $data['transform']; $viewer = $this->getViewer();
$this->phid = $data['phid'];
$this->key = $data['key'];
}
public function processRequest() {
$viewer = $this->getRequest()->getUser();
// NOTE: This is a public/CDN endpoint, and permission to see files is // NOTE: This is a public/CDN endpoint, and permission to see files is
// controlled by knowing the secret key, not by authentication. // controlled by knowing the secret key, not by authentication.
$source_phid = $request->getURIData('phid');
$file = id(new PhabricatorFileQuery()) $file = id(new PhabricatorFileQuery())
->setViewer(PhabricatorUser::getOmnipotentUser()) ->setViewer(PhabricatorUser::getOmnipotentUser())
->withPHIDs(array($this->phid)) ->withPHIDs(array($source_phid))
->executeOne(); ->executeOne();
if (!$file) { if (!$file) {
return new Aphront404Response(); return new Aphront404Response();
} }
if (!$file->validateSecretKey($this->key)) { $secret_key = $request->getURIData('key');
if (!$file->validateSecretKey($secret_key)) {
return new Aphront403Response(); return new Aphront403Response();
} }
$transform = $request->getURIData('transform');
$xform = id(new PhabricatorTransformedFile()) $xform = id(new PhabricatorTransformedFile())
->loadOneWhere( ->loadOneWhere(
'originalPHID = %s AND transform = %s', 'originalPHID = %s AND transform = %s',
$this->phid, $source_phid,
$this->transform); $transform);
if ($xform) { if ($xform) {
return $this->buildTransformedFileResponse($xform); return $this->buildTransformedFileResponse($xform);
@@ -48,35 +41,26 @@ final class PhabricatorFileTransformController
$type = $file->getMimeType(); $type = $file->getMimeType();
if (!$file->isViewableInBrowser() || !$file->isTransformableImage()) { if (!$file->isViewableInBrowser() || !$file->isTransformableImage()) {
return $this->buildDefaultTransformation($file); return $this->buildDefaultTransformation($file, $transform);
} }
// We're essentially just building a cache here and don't need CSRF // We're essentially just building a cache here and don't need CSRF
// protection. // protection.
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
switch ($this->transform) { switch ($transform) {
case 'thumb-profile': case 'thumb-profile':
$xformed_file = $this->executeThumbTransform($file, 50, 50); $xformed_file = $this->executeThumbTransform($file, 50, 50);
break; break;
case 'thumb-280x210': case 'thumb-280x210':
$xformed_file = $this->executeThumbTransform($file, 280, 210); $xformed_file = $this->executeThumbTransform($file, 280, 210);
break; break;
case 'thumb-220x165':
$xformed_file = $this->executeThumbTransform($file, 220, 165);
break;
case 'preview-100': case 'preview-100':
$xformed_file = $this->executePreviewTransform($file, 100); $xformed_file = $this->executePreviewTransform($file, 100);
break; break;
case 'preview-220': case 'preview-220':
$xformed_file = $this->executePreviewTransform($file, 220); $xformed_file = $this->executePreviewTransform($file, 220);
break; break;
case 'thumb-160x120':
$xformed_file = $this->executeThumbTransform($file, 160, 120);
break;
case 'thumb-60x45':
$xformed_file = $this->executeThumbTransform($file, 60, 45);
break;
default: default:
return new Aphront400Response(); return new Aphront400Response();
} }
@@ -85,16 +69,18 @@ final class PhabricatorFileTransformController
return new Aphront400Response(); return new Aphront400Response();
} }
$xform = new PhabricatorTransformedFile(); $xform = id(new PhabricatorTransformedFile())
$xform->setOriginalPHID($this->phid); ->setOriginalPHID($source_phid)
$xform->setTransform($this->transform); ->setTransform($transform)
$xform->setTransformedPHID($xformed_file->getPHID()); ->setTransformedPHID($xformed_file->getPHID())
$xform->save(); ->save();
return $this->buildTransformedFileResponse($xform); return $this->buildTransformedFileResponse($xform);
} }
private function buildDefaultTransformation(PhabricatorFile $file) { private function buildDefaultTransformation(
PhabricatorFile $file,
$transform) {
static $regexps = array( static $regexps = array(
'@application/zip@' => 'zip', '@application/zip@' => 'zip',
'@image/@' => 'image', '@image/@' => 'image',
@@ -111,16 +97,10 @@ final class PhabricatorFileTransformController
} }
} }
switch ($this->transform) { switch ($transform) {
case 'thumb-280x210': case 'thumb-280x210':
$suffix = '280x210'; $suffix = '280x210';
break; break;
case 'thumb-160x120':
$suffix = '160x120';
break;
case 'thumb-60x45':
$suffix = '60x45';
break;
case 'preview-100': case 'preview-100':
$suffix = '.p100'; $suffix = '.p100';
break; break;

View File

@@ -784,14 +784,6 @@ final class PhabricatorFile extends PhabricatorFileDAO
return $this->getTransformedURI('thumb-profile'); return $this->getTransformedURI('thumb-profile');
} }
public function getThumb60x45URI() {
return $this->getTransformedURI('thumb-60x45');
}
public function getThumb160x120URI() {
return $this->getTransformedURI('thumb-160x120');
}
public function getPreview100URI() { public function getPreview100URI() {
return $this->getTransformedURI('preview-100'); return $this->getTransformedURI('preview-100');
} }
@@ -800,10 +792,6 @@ final class PhabricatorFile extends PhabricatorFileDAO
return $this->getTransformedURI('preview-220'); return $this->getTransformedURI('preview-220');
} }
public function getThumb220x165URI() {
return $this->getTransfomredURI('thumb-220x165');
}
public function getThumb280x210URI() { public function getThumb280x210URI() {
return $this->getTransformedURI('thumb-280x210'); return $this->getTransformedURI('thumb-280x210');
} }

View File

@@ -49,7 +49,6 @@ final class PhabricatorPholioApplication extends PhabricatorApplication {
'inline/' => array( 'inline/' => array(
'(?:(?P<id>\d+)/)?' => 'PholioInlineController', '(?:(?P<id>\d+)/)?' => 'PholioInlineController',
'list/(?P<id>\d+)/' => 'PholioInlineListController', 'list/(?P<id>\d+)/' => 'PholioInlineListController',
'thumb/(?P<imageid>\d+)/' => 'PholioInlineThumbController',
), ),
'image/' => array( 'image/' => array(
'upload/' => 'PholioImageUploadController', 'upload/' => 'PholioImageUploadController',

View File

@@ -1,46 +0,0 @@
<?php
final class PholioInlineThumbController extends PholioController {
private $imageid;
public function shouldAllowPublic() {
return true;
}
public function willProcessRequest(array $data) {
$this->imageid = idx($data, 'imageid');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$image = id(new PholioImage())->load($this->imageid);
if ($image == null) {
return new Aphront404Response();
}
$mock = id(new PholioMockQuery())
->setViewer($user)
->withIDs(array($image->getMockID()))
->executeOne();
if (!$mock) {
return new Aphront404Response();
}
$file = id(new PhabricatorFileQuery())
->setViewer($user)
->witHPHIDs(array($image->getFilePHID()))
->executeOne();
if (!$file) {
return new Aphront404Response();
}
return id(new AphrontRedirectResponse())->setURI($file->getThumb60x45URI());
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1006 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 762 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB