Compare commits

...

4 commits

3 changed files with 15 additions and 4 deletions

View file

@ -115,7 +115,7 @@ class HttpDriver {
$opt = (\PHP_MAJOR_VERSION >= 8 && \PHP_MINOR_VERSION >= 2) ? \CURLOPT_XFERINFOFUNCTION : \CURLOPT_PROGRESSFUNCTION;
\curl_setopt_array($this->inner, [
\CURLOPT_NOPROGRESS => false,
$opt => fn($res, $next_dl, $dl, $next_up, $up) => (int)($dl <= $this->max_file_size),
$opt => fn($res, $next_dl, $dl, $next_up, $up) => (int)($dl > $this->max_file_size),
\CURLOPT_FAILONERROR => true,
\CURLOPT_FOLLOWLOCATION => false,
\CURLOPT_FILE => $fd,

View file

@ -16,11 +16,20 @@ class EmbedService {
private int $thumb_download_timeout;
public function __construct(LogDriver $log, OembedExtractor $oembed_extractor, array $embed_entries, int $thumb_download_timeout) {
public function __construct(
LogDriver $log,
OembedExtractor $oembed_extractor,
HttpDriver $http,
array $embed_entries,
int $thumb_download_timeout,
string $tmp_dir,
) {
$this->log = $log;
$this->oembed_extractor = $oembed_extractor;
$this->http = $http;
$this->embed_entries = $embed_entries;
$this->thumb_download_timeout = $thumb_download_timeout;
$this->tmp_dir = $tmp_dir;
}
private function make_tmp_file(): string {
@ -104,7 +113,7 @@ class EmbedService {
public function getEmbedThumb(string $url, int $entry_index): ?array {
$ret = $this->extractThumb($url, $entry_index);
list($thumbnail_url, $thumbnail_url_fallback) = $ret;
if (!isset($thumbnail_url, $thumbnail_url_fallback)) {
if (!isset($thumbnail_url)) {
return null;
}

View file

@ -94,8 +94,10 @@ function build_context(array $config): Context {
return new EmbedService(
$c->get(LogDriver::class),
$c->get(OembedExtractor::class),
$c->get(HttpDriver::class),
$config['embedding_2'],
$config['embed_thumb_timeout']
$config['embed_thumb_timeout'],
$config['tmp'],
);
}
]);