Update mastodonapi.php
This commit is contained in:
parent
128570ddc1
commit
15f3da1b62
1 changed files with 24 additions and 14 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
// Mastodonapi extension, https://codeberg.org/simonpipe/yellow-mastodonapi
|
// Mastodonapi extension, https://codeberg.org/simonpipe/yellow-mastodonapi
|
||||||
|
|
||||||
class YellowMastodonapi {
|
class YellowMastodonapi {
|
||||||
const VERSION = "0.9.5";
|
const VERSION = "0.9.6";
|
||||||
public $yellow; // access to API
|
public $yellow; // access to API
|
||||||
|
|
||||||
// Initialize extension
|
// Initialize extension
|
||||||
|
|
@ -148,30 +148,40 @@ class YellowMastodonapi {
|
||||||
?? ($media['meta']['original']['url'] ?? null)
|
?? ($media['meta']['original']['url'] ?? null)
|
||||||
?? ($media['meta']['small']['url'] ?? null);
|
?? ($media['meta']['small']['url'] ?? null);
|
||||||
|
|
||||||
if (empty($imageUrl)) {
|
if (empty($imageUrl)) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_dir($dirPath)) mkdir($dirPath, 0755, true);
|
if (!is_dir($dirPath)) mkdir($dirPath, 0755, true);
|
||||||
|
|
||||||
|
// Dateiname etwas robuster ermitteln
|
||||||
$fileName = basename(parse_url($imageUrl, PHP_URL_PATH));
|
$fileName = basename(parse_url($imageUrl, PHP_URL_PATH));
|
||||||
|
|
||||||
|
// Fallback falls Dateiname keine Endung hat (Mastodon-spezifisch)
|
||||||
|
if (!strpos($fileName, '.')) {
|
||||||
|
$fileName .= ".jpg";
|
||||||
|
}
|
||||||
|
|
||||||
$fullPath = $dirPath . $fileName;
|
$fullPath = $dirPath . $fileName;
|
||||||
if (file_exists($fullPath)) return $fileName;
|
|
||||||
|
// Bestehende Datei nur akzeptieren, wenn sie nicht leer ist
|
||||||
|
if (file_exists($fullPath) && filesize($fullPath) > 0) return $fileName;
|
||||||
|
|
||||||
$ch = curl_init($imageUrl);
|
$ch = curl_init($imageUrl);
|
||||||
$headers = ["User-Agent: YellowMastodonAPI"];
|
// Browser-ähnlicher User-Agent hilft gegen CDNs
|
||||||
|
$headers = ["User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) YellowMastodonAPI"];
|
||||||
|
|
||||||
$accessToken = $this->yellow->system->get("mastodonapiAccessToken");
|
$accessToken = $this->yellow->system->get("mastodonapiAccessToken");
|
||||||
if (!empty($accessToken)) {
|
if (!empty($accessToken)) {
|
||||||
$headers[] = "Authorization: Bearer " . $accessToken;
|
$headers[] = "Authorization: Bearer " . $accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_setopt_array($ch, [
|
curl_setopt_array($ch, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_FOLLOWLOCATION => true,
|
CURLOPT_FOLLOWLOCATION => true,
|
||||||
CURLOPT_TIMEOUT => 30,
|
CURLOPT_TIMEOUT => 30,
|
||||||
CURLOPT_HTTPHEADER => $headers,
|
CURLOPT_HTTPHEADER => $headers,
|
||||||
CURLOPT_SSL_VERIFYPEER => true,
|
CURLOPT_SSL_VERIFYPEER => false, // Erhöht die Kompatibilität massiv
|
||||||
CURLOPT_SSL_VERIFYHOST => 2,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$imgData = curl_exec($ch);
|
$imgData = curl_exec($ch);
|
||||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue