예제 #1
0
 public function testNginxCachePurge()
 {
     $image = $this->getImage();
     $filename = 'tests/' . $this->fileRepository->savePicture($image, 'tests');
     $path = $this->dataDir . $filename;
     $s3Url = $this->s3Url . $filename;
     $cloudflareUrl = $this->cloudflareDataUrl . $filename;
     $directUrl = $this->directDataUrl . $filename;
     // Test that it is first served by nginx from the local filesystem
     $headers = $this->getHttpHeaders($directUrl);
     $this->assertNotContains('x-amz-request-id', $headers);
     $this->assertNotContains('X-Cache-Status', $headers);
     // Delete from local filesystem
     unlink($path);
     // Test that it is served from AWS via Nginx
     $headers = $this->getHttpHeaders($directUrl);
     $this->assertContains('x-amz-request-id', $headers);
     $this->assertContains('X-Cache-Status: MISS', $headers);
     sleep(1);
     // Test that it is cached by Nginx now
     $headers = $this->getHttpHeaders($directUrl);
     $this->assertContains('x-amz-request-id', $headers);
     $this->assertContains('X-Cache-Status: HIT', $headers);
     // Delete from remote
     $this->fileRepository->deleteRemoteFile($filename);
     $this->assertNotEquals(200, $this->getHttpResponseCode($s3Url), $s3Url);
     // Test that it is still cached by Nginx
     $headers = $this->getHttpHeaders($directUrl);
     $this->assertContains('HTTP/1.1 200', $headers);
     $this->assertContains('X-Cache-Status: HIT', $headers);
     // Purge nginx cache
     $this->assertEquals(true, $this->cacheManager->purgeNginx($directUrl));
     // Test it's no longer being served
     $this->assertNotEquals(200, $this->getHttpResponseCode($directUrl), $directUrl);
     $this->fileRepository->deleteFile($filename);
 }
예제 #2
0
 /**
  * Execute the job.
  *
  * @param FileManager $fileManager
  *
  * @throws Exception
  */
 public function handle(FileManager $fileManager)
 {
     $this->logger = $this->getJobLogger();
     $this->logger->debug("Generating thumbnail for image {$this->imageFile->getId()} {$this->imageFile->getPath()}" . " attempt {$this->attempts()}", $this->imageFile->toArray());
     // Get a fresh copy from the DB (checks if it's deleted)
     if (!($this->imageFile = $this->imageFile->fresh())) {
         throw new Exception("ImageFile no longer exists.");
     }
     // Get full size image
     $picture = $fileManager->getPictureForImageFile($this->imageFile);
     $filename = $this->imageFile->getFilename();
     // Generate 200x200 thumbnail
     $picture->fit(200, 200, function (Constraint $constraint) {
         $constraint->upsize();
     });
     if ($thumbnailImageFile = $fileManager->savePicture($picture, 'thumb', $filename, $this->imageFile)) {
         Image::where('imageFileID', $this->imageFile->getId())->update(['thumbnailImageFileId' => $thumbnailImageFile->getId()]);
     }
 }
예제 #3
0
 /**
  * @api            {put} /images/{imageId}/image?action=rotate Rotate an Image
  * @apiGroup       Manipulating Images
  * @apiDescription Rotate an image clockwise or counter-clockwise.
  * @apiParam {string=rotate} action Action to perform.
  * @apiParam {int=90,180,270} degrees Degrees to rotate by.
  * @apiParam {string=cw,ccw} [direction=cw] Direction to rotate in (clockwise or counter-clockwise respectively).
  * @apiUse         RequiresEditableImage
  * @apiUse         ImageSuccessResponse
  *
  * @param Image       $image
  * @param FileManager $fileManager
  *
  * @throws Exception
  * @return Response
  */
 protected function rotate(Image $image, FileManager $fileManager)
 {
     $success = false;
     $this->validate($this->request, ['degrees' => 'required|integer|in:90,180,270', 'direction' => 'in:cw,ccw']);
     if ($image->operationInProgress) {
         throw new HttpException(409, "Another operation is currently in progress for this image.");
     }
     $image->operationInProgress = true;
     $image->save();
     $degrees = (int) $this->request->input('degrees');
     $direction = $this->request->has('direction') ? $this->request->input('direction') : 'cw';
     if ($direction === 'cw') {
         $degrees = -$degrees;
     }
     $picture = $fileManager->getPictureForImageFile($image->imageFile);
     $picture->rotate($degrees);
     if ($newImageFile = $fileManager->savePicture($picture)) {
         $image->setImageFile($newImageFile);
         $image->operationInProgress = false;
         $success = $image->save();
     }
     return $this->response(['success' => $success, 'image' => $image->fresh()]);
 }