Пример #1
0
 /**
  * @param  FileWasFailedToUpload $event [description]
  * @return void
  */
 public function handle(LibraryWasCreated $event)
 {
     $library = $event->library;
     // If the media library was deleted before it moved
     // Delete this queue
     if (!$this->libraryRepository->findById($library->id())) {
         $this->delete();
     }
     $description = $library->description()->value();
     $storage = $description['storage'];
     // We don't need to move if storage is local
     if ($storage != 'local') {
         $preferredFilesystem = $this->filesystemFactory->disk($storage);
         $localFilesystem = $this->filesystemFactory->disk('local');
         $destination = $description['path'];
         $source = $destination;
         $stream = $localFilesystem->getDriver()->readStream($source);
         $preferredFilesystem->put($destination, $stream);
         // Remove local saved file
         $localFilesystem->delete($source);
     }
     // Mark as moved
     $description['is_moved'] = true;
     $library->describe(new Description($description));
     $this->libraryRepository->save($library);
 }
Пример #2
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());
 }
Пример #3
0
 /**
  * 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);
 }
Пример #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')]);
 }
Пример #5
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);
 }