[ATTACHMENTS] Don't store an attachment if it's a dupplicate, reuse it
This commit is contained in:
parent
2b83a4b627
commit
4f936108a1
@ -22,12 +22,12 @@
|
||||
namespace App\Core;
|
||||
|
||||
use App\Core\DB\DB;
|
||||
use App\Util\Exception\NotFoundException;
|
||||
use function App\Core\I18n\_m;
|
||||
use App\Entity\Attachment;
|
||||
use App\Util\Common;
|
||||
use App\Util\Exception\ClientException;
|
||||
use App\Util\Exception\NoSuchFileException;
|
||||
use App\Util\Exception\NotFoundException;
|
||||
use App\Util\Exception\ServerException;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\File\File as SymfonyFile;
|
||||
@ -46,6 +46,9 @@ class GSFile
|
||||
int $actor_id = null): Attachment
|
||||
{
|
||||
Event::handle('HashFile', [$sfile->getPathname(), &$hash]);
|
||||
try {
|
||||
return DB::findOneBy('attachment', ['file_hash' => $hash]);
|
||||
} catch (NotFoundException) {
|
||||
// The following properly gets the mimetype with `file` or other
|
||||
// available methods, so should be safe
|
||||
$mimetype = $sfile->getMimeType();
|
||||
@ -66,6 +69,7 @@ class GSFile
|
||||
Event::handle('AttachmentStoreNew', [&$attachment]);
|
||||
return $attachment;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an attachment for the given URL, fetching the mimetype
|
||||
|
Loading…
Reference in New Issue
Block a user