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