[ATTACHMENTS][GSFile] Rename ValidateAndStore functions

This commit is contained in:
Diogo Peralta Cordeiro 2021-05-01 22:14:38 +01:00 committed by Hugo Sales
parent a3860e6257
commit c9090e6cee
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
3 changed files with 9 additions and 9 deletions

View File

@ -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

View File

@ -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);

View File

@ -38,7 +38,7 @@ 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,
@ -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);