mirror of
https://github.com/friendica/friendica
synced 2025-01-03 16:02:19 +00:00
Fix fetching additional media information
This commit is contained in:
parent
dc145bb440
commit
9da42e551d
1 changed files with 18 additions and 18 deletions
|
@ -181,25 +181,25 @@ class Media
|
||||||
// Fetch the mimetype or size if missing.
|
// Fetch the mimetype or size if missing.
|
||||||
if (Network::isValidHttpUrl($media['url']) && (empty($media['mimetype']) || empty($media['size']))) {
|
if (Network::isValidHttpUrl($media['url']) && (empty($media['mimetype']) || empty($media['size']))) {
|
||||||
$timeout = DI::config()->get('system', 'xrd_timeout');
|
$timeout = DI::config()->get('system', 'xrd_timeout');
|
||||||
$curlResult = DI::httpClient()->head($media['url'], [HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]);
|
try {
|
||||||
|
$curlResult = DI::httpClient()->head($media['url'], [HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]);
|
||||||
|
|
||||||
// Workaround for systems that can't handle a HEAD request
|
// Workaround for systems that can't handle a HEAD request
|
||||||
if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
|
if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
|
||||||
try {
|
|
||||||
$curlResult = DI::httpClient()->get($media['url'], HttpClientAccept::DEFAULT, [HttpClientOptions::TIMEOUT => $timeout]);
|
$curlResult = DI::httpClient()->get($media['url'], HttpClientAccept::DEFAULT, [HttpClientOptions::TIMEOUT => $timeout]);
|
||||||
if ($curlResult->isSuccess()) {
|
|
||||||
if (empty($media['mimetype'])) {
|
|
||||||
$media['mimetype'] = $curlResult->getContentType() ?? '';
|
|
||||||
}
|
|
||||||
if (empty($media['size'])) {
|
|
||||||
$media['size'] = (int)($curlResult->getHeader('Content-Length')[0] ?? 0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Logger::notice('Could not fetch head', ['media' => $media]);
|
|
||||||
}
|
|
||||||
} catch (\Throwable $th) {
|
|
||||||
Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
|
|
||||||
}
|
}
|
||||||
|
if ($curlResult->isSuccess()) {
|
||||||
|
if (empty($media['mimetype'])) {
|
||||||
|
$media['mimetype'] = $curlResult->getContentType() ?? '';
|
||||||
|
}
|
||||||
|
if (empty($media['size'])) {
|
||||||
|
$media['size'] = (int)($curlResult->getHeader('Content-Length')[0] ?? 0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Logger::notice('Could not fetch head', ['media' => $media]);
|
||||||
|
}
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -684,7 +684,7 @@ class Media
|
||||||
foreach ($matches[1] as $url) {
|
foreach ($matches[1] as $url) {
|
||||||
Logger::info('Got page url (link without description)', ['uri-id' => $uriid, 'url' => $url]);
|
Logger::info('Got page url (link without description)', ['uri-id' => $uriid, 'url' => $url]);
|
||||||
$result = self::insert(['uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $url], false, $network);
|
$result = self::insert(['uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $url], false, $network);
|
||||||
if ($result && !in_array($network, [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA])) {
|
if ($result && !in_array($network, [Protocol::ACTIVITYPUB, Protocol::DIASPORA])) {
|
||||||
self::revertHTMLType($uriid, $url, $fullbody);
|
self::revertHTMLType($uriid, $url, $fullbody);
|
||||||
Logger::debug('Revert HTML type', ['uri-id' => $uriid, 'url' => $url]);
|
Logger::debug('Revert HTML type', ['uri-id' => $uriid, 'url' => $url]);
|
||||||
} elseif ($result) {
|
} elseif ($result) {
|
||||||
|
@ -700,7 +700,7 @@ class Media
|
||||||
foreach ($matches[1] as $url) {
|
foreach ($matches[1] as $url) {
|
||||||
Logger::info('Got page url (link with description)', ['uri-id' => $uriid, 'url' => $url]);
|
Logger::info('Got page url (link with description)', ['uri-id' => $uriid, 'url' => $url]);
|
||||||
$result = self::insert(['uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $url], false, $network);
|
$result = self::insert(['uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $url], false, $network);
|
||||||
if ($result && !in_array($network, [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA])) {
|
if ($result && !in_array($network, [Protocol::ACTIVITYPUB, Protocol::DIASPORA])) {
|
||||||
self::revertHTMLType($uriid, $url, $fullbody);
|
self::revertHTMLType($uriid, $url, $fullbody);
|
||||||
Logger::debug('Revert HTML type', ['uri-id' => $uriid, 'url' => $url]);
|
Logger::debug('Revert HTML type', ['uri-id' => $uriid, 'url' => $url]);
|
||||||
} elseif ($result) {
|
} elseif ($result) {
|
||||||
|
|
Loading…
Reference in a new issue