mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-05 23:15:50 +01:00
Allow to download and view attachments via part info page.
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user