/** * @task info */ public static function getRawInput() { if (self::$rawInput === null) { $stream = new AphrontRequestStream(); if (isset($_SERVER['HTTP_CONTENT_ENCODING'])) { $encoding = trim($_SERVER['HTTP_CONTENT_ENCODING']); $stream->setEncoding($encoding); } $input = ''; do { $bytes = $stream->readData(); if ($bytes === null) { break; } $input .= $bytes; } while (true); self::$rawInput = $input; } return self::$rawInput; }
private function serveGitLFSUploadRequest(PhabricatorRepository $repository, PhabricatorUser $viewer, $oid) { $ref = id(new PhabricatorRepositoryGitLFSRefQuery())->setViewer($viewer)->withRepositoryPHIDs(array($repository->getPHID()))->withObjectHashes(array($oid))->executeOne(); if ($ref) { return DiffusionGitLFSResponse::newErrorResponse(405, pht('Content for object "%s" is already known to this server. It can ' . 'not be uploaded again.', $oid)); } // Remove the execution time limit because uploading large files may take // a while. set_time_limit(0); $request_stream = new AphrontRequestStream(); $request_iterator = $request_stream->getIterator(); $hashing_iterator = id(new PhutilHashingIterator($request_iterator))->setAlgorithm('sha256'); $source = id(new PhabricatorIteratorFileUploadSource())->setName('lfs-' . $oid)->setViewPolicy(PhabricatorPolicies::POLICY_NOONE)->setIterator($hashing_iterator); $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $file = $source->uploadFile(); unset($unguarded); $hash = $hashing_iterator->getHash(); if ($hash !== $oid) { return DiffusionGitLFSResponse::newErrorResponse(400, pht('Uploaded data is corrupt or invalid. Expected hash "%s", actual ' . 'hash "%s".', $oid, $hash)); } $ref = id(new PhabricatorRepositoryGitLFSRef())->setRepositoryPHID($repository->getPHID())->setObjectHash($hash)->setByteSize($file->getByteSize())->setAuthorPHID($viewer->getPHID())->setFilePHID($file->getPHID()); $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); // Attach the file to the repository to give users permission // to access it. $file->attachToObject($repository->getPHID()); $ref->save(); unset($unguarded); // This is just a plain HTTP 200 with no content, which is what `git lfs` // expects. return new DiffusionGitLFSResponse(); }