Esempio n. 1
0
 /**
  * Apply resize
  * 
  * @param string $path
  * @return Psr-7 stream
  */
 public function apply($path)
 {
     $library = $this->libraryRepostiory->findByPath($path)->toArray();
     $storage = $library['description']['is_moved'] ? $library['description']['storage'] : 'local';
     $filesystem = $this->filesystemFactory->disk($storage);
     $stream = $filesystem->getDriver()->readStream($path);
     $lastModified = $filesystem->lastModified($path);
     return $this->imageManager->cache(function ($image) use($stream, $lastModified) {
         $this->process($image->setProperty('lastModified', $lastModified)->make($stream));
     }, $this->getLifetime());
 }
 /**
  * Perform rule validation
  * 
  * @param  mixed $attribute
  * @param  mixed $value
  * @param  mixed $parameters
  * @param  mixed $validator
  * 
  * @return bool
  */
 public function validate($attribute, $value, $parameters, $validator)
 {
     $path = $value;
     $mimes = $parameters;
     $library = $this->libraryRepostory->findByPath($path);
     if (!$library) {
         return false;
     }
     $library = $library->toArray();
     $storage = $library['description']['is_moved'] ? $library['description']['storage'] : 'local';
     $mime = $this->filesystemFactory->disk($storage)->mimeType($library['description']['path']);
     return in_array($mime, $mimes);
 }
Esempio n. 3
0
 /**
  * Download file
  * @param  Request  $request
  * @param  string   $path
  * @return response
  */
 public function getDownload(Request $request, $path)
 {
     $library = $this->libraryRepository->findByPath($path);
     if (is_null($library)) {
         abort(404);
     } else {
         $library = $library->toArray();
     }
     $this->authorizeDownload($request, $library);
     $this->validateEtag($request, $library);
     $headers = $this->prepareHeaders($library);
     $headers['Content-Disposition'] = 'attachment; filename="' . $library['description']['name'] . '"';
     $content = $this->getFileContent($library);
     return $this->renderer->setHeaders($headers)->render($content);
 }
Esempio n. 4
0
 public function putUpdateAvatar(Dispatcher $bus, Request $request, UserRepository $userRepository, LibraryRepository $libraryRepository, $id)
 {
     $userId = $this->authis->check('account.admin.users.update.get') ? $id : $request->user()->id;
     $library = $libraryRepository->findByPath($request->avatar);
     $user = $userRepository->findById($userId)->toArray();
     $description = $user['description'];
     $this->validate($request, ['avatar' => 'required']);
     $description['avatar'] = $request->avatar;
     $bus->dispatch(new DescribeUser($userId, $user['username'], $user['email'], $description));
     if ($library) {
         $library = $library->toArray();
         $libraryDescription = $library['description'];
         $libraryDescription['visibility'] = 'public';
         $bus->dispatch(new DescribeLibrary($library['id'], $libraryDescription));
     }
     return $this->formSuccess(route('account.admin.profile.index.get'), ['message' => trans('inoplate-account::messages.profile.avatar_updated')]);
 }