Differential D15953 Diff 38422 src/applications/files/controller/PhabricatorFileDropUploadController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/controller/PhabricatorFileDropUploadController.php
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | if ($is_allocate) { | ||||
$result = id(new ConduitCall('file.allocate', $params)) | $result = id(new ConduitCall('file.allocate', $params)) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->execute(); | ->execute(); | ||||
$file_phid = $result['filePHID']; | $file_phid = $result['filePHID']; | ||||
if ($file_phid) { | if ($file_phid) { | ||||
$file = $this->loadFile($file_phid); | $file = $this->loadFile($file_phid); | ||||
$result += $this->getFileDictionary($file); | $result += $file->getDragAndDropDictionary(); | ||||
} | } | ||||
return id(new AphrontAjaxResponse())->setContent($result); | return id(new AphrontAjaxResponse())->setContent($result); | ||||
} | } | ||||
// Read the raw request data. We're either doing a chunk upload or a | // Read the raw request data. We're either doing a chunk upload or a | ||||
// vanilla upload, so we need it. | // vanilla upload, so we need it. | ||||
$data = PhabricatorStartup::getRawInput(); | $data = PhabricatorStartup::getRawInput(); | ||||
Show All 11 Lines | if ($is_chunk_upload) { | ||||
->execute(); | ->execute(); | ||||
$file = $this->loadFile($file_phid); | $file = $this->loadFile($file_phid); | ||||
if ($file->getIsPartial()) { | if ($file->getIsPartial()) { | ||||
$result = array(); | $result = array(); | ||||
} else { | } else { | ||||
$result = array( | $result = array( | ||||
'complete' => true, | 'complete' => true, | ||||
) + $this->getFileDictionary($file); | ) + $file->getDragAndDropDictionary(); | ||||
} | } | ||||
return id(new AphrontAjaxResponse())->setContent($result); | return id(new AphrontAjaxResponse())->setContent($result); | ||||
} | } | ||||
$file = PhabricatorFile::newFromXHRUpload( | $file = PhabricatorFile::newFromXHRUpload( | ||||
$data, | $data, | ||||
array( | array( | ||||
'name' => $request->getStr('name'), | 'name' => $request->getStr('name'), | ||||
'authorPHID' => $viewer->getPHID(), | 'authorPHID' => $viewer->getPHID(), | ||||
'viewPolicy' => $view_policy, | 'viewPolicy' => $view_policy, | ||||
'isExplicitUpload' => true, | 'isExplicitUpload' => true, | ||||
)); | )); | ||||
$result = $this->getFileDictionary($file); | $result = $file->getDragAndDropDictionary(); | ||||
return id(new AphrontAjaxResponse())->setContent($result); | return id(new AphrontAjaxResponse())->setContent($result); | ||||
} | } | ||||
private function getFileDictionary(PhabricatorFile $file) { | |||||
return array( | |||||
'id' => $file->getID(), | |||||
'phid' => $file->getPHID(), | |||||
'uri' => $file->getBestURI(), | |||||
); | |||||
} | |||||
private function loadFile($file_phid) { | private function loadFile($file_phid) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$file = id(new PhabricatorFileQuery()) | $file = id(new PhabricatorFileQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs(array($file_phid)) | ->withPHIDs(array($file_phid)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$file) { | if (!$file) { | ||||
throw new Exception(pht('Failed to load file.')); | throw new Exception(pht('Failed to load file.')); | ||||
} | } | ||||
return $file; | return $file; | ||||
} | } | ||||
} | } |