Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #4 from ikkentim/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ikkentim authored Sep 18, 2016
2 parents 8ac7b29 + 2f72426 commit 56f5a2e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/Http/Controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public function upload(NugetRequest $request)
$user = $request->getUser();
$file = $request->getUploadedFile('package');

if($file === false)
{
\Log::error('package not uploaded on second check');
return Response('package not uploaded on second check', 500);
}

Storage::makeDirectory('packages');
$nupkg = new NupkgFile($file);
$nupkg->savePackage($user);
Expand Down
14 changes: 13 additions & 1 deletion app/Http/Requests/NugetRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Laget\User;

class NugetRequest {
private static $inputCache = false;

/**
* NugetRequest constructor.
*
Expand All @@ -30,6 +32,16 @@ public function getUser()
return User::fromApiKey($apiKey);
}

private function getInput()
{
if(self::$inputCache === false)
{
self::$inputCache = file_get_contents('php://input');
}

return self::$inputCache;
}

private function getFileBlock($name)
{
// Read boundary indicator from content type.
Expand All @@ -42,7 +54,7 @@ private function getFileBlock($name)
$boundary = trim($boundary[1], '"');

// Split request body into blocks.
$blocks = preg_split("/-+{$boundary}/", file_get_contents('php://input'));
$blocks = preg_split("/-+{$boundary}/", $this->getInput());

// Strip last block. This block is always empty because it is after the last terminator.
array_pop($blocks);
Expand Down
8 changes: 5 additions & 3 deletions app/Nuget/NupkgFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ public function savePackage($uploader)
->where('version', $nuspec->version)
->first();

$isNewPackageId = $package === null;

if ($package === null)
{
$package = new NugetPackage();
Expand All @@ -115,7 +113,7 @@ public function savePackage($uploader)
$package->is_absolute_latest_version = true;
$package->is_listed = true;
$package->is_prerelease = str_contains(strtolower($nuspec->version), ['alpha', 'beta', 'rc', 'prerelease']);
$package->is_latest_version = $isNewPackageId || !$package->is_prerelease;
$package->is_latest_version = !$package->is_prerelease;

// Hash
$package->hash = $this->getHash($hash_algorithm);
Expand Down Expand Up @@ -145,6 +143,10 @@ public function savePackage($uploader)

$package->download_count = $absolute_latest_package->download_count;
}
else
{
$package->is_latest_version = true;
}

if (!$package->is_prerelease)
{
Expand Down

0 comments on commit 56f5a2e

Please sign in to comment.