[ATTACHMENTS][GSFile] Rename ValidateAndStore functions
This commit is contained in:
parent
a3860e6257
commit
c9090e6cee
@ -106,7 +106,7 @@ class Avatar extends Controller
|
|||||||
} else {
|
} else {
|
||||||
throw new ClientException('Invalid form');
|
throw new ClientException('Invalid form');
|
||||||
}
|
}
|
||||||
$attachment = GSFile::validateAndStoreAttachment($sfile, Common::config('avatar', 'dir'), $title = null, $is_local = true, $use_unique = $gsactor_id);
|
$attachment = GSFile::validateAndStoreFileAsAttachment($sfile, Common::config('avatar', 'dir'), $title = null, $is_local = true, $use_unique = $gsactor_id);
|
||||||
$old_attachment = null;
|
$old_attachment = null;
|
||||||
$avatar = DB::find('avatar', ['gsactor_id' => $gsactor_id]);
|
$avatar = DB::find('avatar', ['gsactor_id' => $gsactor_id]);
|
||||||
// Must get old id before inserting another one
|
// Must get old id before inserting another one
|
||||||
|
@ -115,7 +115,7 @@ END;
|
|||||||
|
|
||||||
$processed_attachments = [];
|
$processed_attachments = [];
|
||||||
foreach ($attachments as $f) {
|
foreach ($attachments as $f) {
|
||||||
$processed_attachments[] = GSFile::validateAndStoreAttachment(
|
$processed_attachments[] = GSFile::validateAndStoreFileAsAttachment(
|
||||||
$f, Common::config('attachments', 'dir'),
|
$f, Common::config('attachments', 'dir'),
|
||||||
Security::sanitize($f->getClientOriginalName()),
|
Security::sanitize($f->getClientOriginalName()),
|
||||||
is_local: true, actor_id: $actor_id
|
is_local: true, actor_id: $actor_id
|
||||||
@ -125,7 +125,7 @@ END;
|
|||||||
$matched_urls = [];
|
$matched_urls = [];
|
||||||
preg_match_all(self::URL_REGEX, $content, $matched_urls, PREG_SET_ORDER);
|
preg_match_all(self::URL_REGEX, $content, $matched_urls, PREG_SET_ORDER);
|
||||||
foreach ($matched_urls as $match) {
|
foreach ($matched_urls as $match) {
|
||||||
$processed_attachments[] = GSFile::validateAndStoreURL($match[0]);
|
$processed_attachments[] = GSFile::validateAndStoreURLAsAttachment($match[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
DB::persist($note);
|
DB::persist($note);
|
||||||
|
@ -38,11 +38,11 @@ class GSFile
|
|||||||
/**
|
/**
|
||||||
* Perform file validation (checks and normalization) and store the given file
|
* Perform file validation (checks and normalization) and store the given file
|
||||||
*/
|
*/
|
||||||
public static function validateAndStoreAttachment(SymfonyFile $sfile,
|
public static function validateAndStoreFileAsAttachment(SymfonyFile $sfile,
|
||||||
string $dest_dir,
|
string $dest_dir,
|
||||||
?string $title = null,
|
?string $title = null,
|
||||||
bool $is_local = true,
|
bool $is_local = true,
|
||||||
int $actor_id = null): Attachment
|
int $actor_id = null): Attachment
|
||||||
{
|
{
|
||||||
Event::handle('HashFile', [$sfile->getPathname(), &$hash]);
|
Event::handle('HashFile', [$sfile->getPathname(), &$hash]);
|
||||||
// The following properly gets the mimetype with `file` or other
|
// The following properly gets the mimetype with `file` or other
|
||||||
@ -69,7 +69,7 @@ class GSFile
|
|||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public static function validateAndStoreURL(string $url): Attachment
|
public static function validateAndStoreURLAsAttachment(string $url): Attachment
|
||||||
{
|
{
|
||||||
if (Common::isValidHttpUrl($url)) {
|
if (Common::isValidHttpUrl($url)) {
|
||||||
$head = HTTPClient::head($url);
|
$head = HTTPClient::head($url);
|
||||||
|
Loading…
Reference in New Issue
Block a user