Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/storage/PhabricatorFile.php
| Show All 34 Lines | final class PhabricatorFile extends PhabricatorFileDAO | ||||
| const METADATA_IMAGE_WIDTH = 'width'; | const METADATA_IMAGE_WIDTH = 'width'; | ||||
| const METADATA_IMAGE_HEIGHT = 'height'; | const METADATA_IMAGE_HEIGHT = 'height'; | ||||
| const METADATA_CAN_CDN = 'canCDN'; | const METADATA_CAN_CDN = 'canCDN'; | ||||
| const METADATA_BUILTIN = 'builtin'; | const METADATA_BUILTIN = 'builtin'; | ||||
| const METADATA_PARTIAL = 'partial'; | const METADATA_PARTIAL = 'partial'; | ||||
| const METADATA_PROFILE = 'profile'; | const METADATA_PROFILE = 'profile'; | ||||
| const METADATA_STORAGE = 'storage'; | const METADATA_STORAGE = 'storage'; | ||||
| const METADATA_INTEGRITY = 'integrity'; | const METADATA_INTEGRITY = 'integrity'; | ||||
| const METADATA_CHUNK = 'chunk'; | |||||
amckinleyUnsubmitted Not Done Inline Actions![]() amckinley: {F5323224} | |||||
| const STATUS_ACTIVE = 'active'; | const STATUS_ACTIVE = 'active'; | ||||
| const STATUS_DELETED = 'deleted'; | const STATUS_DELETED = 'deleted'; | ||||
| protected $name; | protected $name; | ||||
| protected $mimeType; | protected $mimeType; | ||||
| protected $byteSize; | protected $byteSize; | ||||
| protected $authorPHID; | protected $authorPHID; | ||||
| ▲ Show 20 Lines • Show All 354 Lines • ▼ Show 20 Lines | if (!$file->getMimeType()) { | ||||
| Filesystem::writeFile($tmp, $data); | Filesystem::writeFile($tmp, $data); | ||||
| $file->setMimeType(Filesystem::getMimeType($tmp)); | $file->setMimeType(Filesystem::getMimeType($tmp)); | ||||
| unset($tmp); | unset($tmp); | ||||
| } | } | ||||
| try { | try { | ||||
| $file->updateDimensions(false); | $file->updateDimensions(false); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| // Do nothing | // Do nothing. | ||||
| } | } | ||||
| $file->saveAndIndex(); | $file->saveAndIndex(); | ||||
| return $file; | return $file; | ||||
| } | } | ||||
| public static function newFromFileData($data, array $params = array()) { | public static function newFromFileData($data, array $params = array()) { | ||||
| ▲ Show 20 Lines • Show All 630 Lines • ▼ Show 20 Lines | public function updateDimensions($save = true) { | ||||
| if (!$this->isViewableImage()) { | if (!$this->isViewableImage()) { | ||||
| throw new Exception(pht('This file is not a viewable image.')); | throw new Exception(pht('This file is not a viewable image.')); | ||||
| } | } | ||||
| if (!function_exists('imagecreatefromstring')) { | if (!function_exists('imagecreatefromstring')) { | ||||
| throw new Exception(pht('Cannot retrieve image information.')); | throw new Exception(pht('Cannot retrieve image information.')); | ||||
| } | } | ||||
| if ($this->getIsChunk()) { | |||||
| throw new Exception( | |||||
| pht('Refusing to assess image dimensions of file chunk.')); | |||||
| } | |||||
| $engine = $this->instantiateStorageEngine(); | |||||
| if ($engine->isChunkEngine()) { | |||||
| throw new Exception( | |||||
| pht('Refusing to assess image dimensions of chunked file.')); | |||||
| } | |||||
| $data = $this->loadFileData(); | $data = $this->loadFileData(); | ||||
| $img = imagecreatefromstring($data); | $img = @imagecreatefromstring($data); | ||||
| if ($img === false) { | if ($img === false) { | ||||
| throw new Exception(pht('Error when decoding image.')); | throw new Exception(pht('Error when decoding image.')); | ||||
| } | } | ||||
| $this->metadata[self::METADATA_IMAGE_WIDTH] = imagesx($img); | $this->metadata[self::METADATA_IMAGE_WIDTH] = imagesx($img); | ||||
| $this->metadata[self::METADATA_IMAGE_HEIGHT] = imagesy($img); | $this->metadata[self::METADATA_IMAGE_HEIGHT] = imagesy($img); | ||||
| if ($save) { | if ($save) { | ||||
| ▲ Show 20 Lines • Show All 179 Lines • ▼ Show 20 Lines | public function getIsProfileImage() { | ||||
| return idx($this->metadata, self::METADATA_PROFILE); | return idx($this->metadata, self::METADATA_PROFILE); | ||||
| } | } | ||||
| public function setIsProfileImage($value) { | public function setIsProfileImage($value) { | ||||
| $this->metadata[self::METADATA_PROFILE] = $value; | $this->metadata[self::METADATA_PROFILE] = $value; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getIsChunk() { | |||||
| return idx($this->metadata, self::METADATA_CHUNK); | |||||
| } | |||||
| public function setIsChunk($value) { | |||||
| $this->metadata[self::METADATA_CHUNK] = $value; | |||||
| return $this; | |||||
| } | |||||
| public function setIntegrityHash($integrity_hash) { | public function setIntegrityHash($integrity_hash) { | ||||
| $this->metadata[self::METADATA_INTEGRITY] = $integrity_hash; | $this->metadata[self::METADATA_INTEGRITY] = $integrity_hash; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getIntegrityHash() { | public function getIntegrityHash() { | ||||
| return idx($this->metadata, self::METADATA_INTEGRITY); | return idx($this->metadata, self::METADATA_INTEGRITY); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | PhutilTypeSpec::checkMap( | ||||
| 'viewPolicy' => 'optional string', | 'viewPolicy' => 'optional string', | ||||
| 'isExplicitUpload' => 'optional bool', | 'isExplicitUpload' => 'optional bool', | ||||
| 'canCDN' => 'optional bool', | 'canCDN' => 'optional bool', | ||||
| 'profile' => 'optional bool', | 'profile' => 'optional bool', | ||||
| 'format' => 'optional string|PhabricatorFileStorageFormat', | 'format' => 'optional string|PhabricatorFileStorageFormat', | ||||
| 'mime-type' => 'optional string', | 'mime-type' => 'optional string', | ||||
| 'builtin' => 'optional string', | 'builtin' => 'optional string', | ||||
| 'storageEngines' => 'optional list<PhabricatorFileStorageEngine>', | 'storageEngines' => 'optional list<PhabricatorFileStorageEngine>', | ||||
| 'chunk' => 'optional bool', | |||||
| )); | )); | ||||
| $file_name = idx($params, 'name'); | $file_name = idx($params, 'name'); | ||||
| $this->setName($file_name); | $this->setName($file_name); | ||||
| $author_phid = idx($params, 'authorPHID'); | $author_phid = idx($params, 'authorPHID'); | ||||
| $this->setAuthorPHID($author_phid); | $this->setAuthorPHID($author_phid); | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | if ($profile) { | ||||
| $this->setIsProfileImage(true); | $this->setIsProfileImage(true); | ||||
| } | } | ||||
| $mime_type = idx($params, 'mime-type'); | $mime_type = idx($params, 'mime-type'); | ||||
| if ($mime_type) { | if ($mime_type) { | ||||
| $this->setMimeType($mime_type); | $this->setMimeType($mime_type); | ||||
| } | } | ||||
| $is_chunk = idx($params, 'chunk'); | |||||
| if ($is_chunk) { | |||||
| $this->setIsChunk(true); | |||||
| } | |||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getRedirectResponse() { | public function getRedirectResponse() { | ||||
| $uri = $this->getBestURI(); | $uri = $this->getBestURI(); | ||||
| // TODO: This is a bit iffy. Sometimes, getBestURI() returns a CDN URI | // TODO: This is a bit iffy. Sometimes, getBestURI() returns a CDN URI | ||||
| // (if the file is a viewable image) and sometimes a local URI (if not). | // (if the file is a viewable image) and sometimes a local URI (if not). | ||||
| ▲ Show 20 Lines • Show All 197 Lines • Show Last 20 Lines | |||||
