mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-23 02:09:03 +02:00
Allow to download and view attachments via part info page.
This commit is contained in:
parent
368645f0cb
commit
05fd753189
4 changed files with 202 additions and 2 deletions
|
@ -29,6 +29,7 @@
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Entity\Attachment;
|
||||
use App\Entity\AttachmentType;
|
||||
use App\Entity\Category;
|
||||
use App\Entity\Device;
|
||||
|
@ -82,11 +83,35 @@ class EntityURLGenerator
|
|||
return $this->listPartsURL($entity);
|
||||
case 'delete':
|
||||
return $this->deleteURL($entity);
|
||||
case 'file_download':
|
||||
return $this->downloadURL($entity);
|
||||
case 'file_view':
|
||||
return $this->viewURL($entity);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Method is not supported!');
|
||||
}
|
||||
|
||||
public function viewURL($entity) : string
|
||||
{
|
||||
if ($entity instanceof Attachment) {
|
||||
return $this->urlGenerator->generate('attachment_view', ['id' => $entity->getID()]);
|
||||
}
|
||||
|
||||
//Otherwise throw an error
|
||||
throw new EntityNotSupported('The given entity is not supported yet!');
|
||||
}
|
||||
|
||||
public function downloadURL($entity) : string
|
||||
{
|
||||
if ($entity instanceof Attachment) {
|
||||
return $this->urlGenerator->generate('attachment_download', ['id' => $entity->getID()]);
|
||||
}
|
||||
|
||||
//Otherwise throw an error
|
||||
throw new EntityNotSupported('The given entity is not supported yet!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an URL to a page, where info about this entity can be viewed.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue