more typing
This commit is contained in:
parent
cb81f6b94a
commit
5455adf88a
3 changed files with 38 additions and 13 deletions
|
@ -8,6 +8,10 @@ use GQLA\Query;
|
||||||
|
|
||||||
class Querylet
|
class Querylet
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param string $sql
|
||||||
|
* @param array<string, mixed> $variables
|
||||||
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $sql,
|
public string $sql,
|
||||||
public array $variables = [],
|
public array $variables = [],
|
||||||
|
@ -19,16 +23,6 @@ class Querylet
|
||||||
$this->sql .= $querylet->sql;
|
$this->sql .= $querylet->sql;
|
||||||
$this->variables = array_merge($this->variables, $querylet->variables);
|
$this->variables = array_merge($this->variables, $querylet->variables);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function append_sql(string $sql): void
|
|
||||||
{
|
|
||||||
$this->sql .= $sql;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add_variable($var): void
|
|
||||||
{
|
|
||||||
$this->variables[] = $var;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TagCondition
|
class TagCondition
|
||||||
|
@ -51,9 +45,13 @@ class ImgCondition
|
||||||
|
|
||||||
class Search
|
class Search
|
||||||
{
|
{
|
||||||
|
/** @var list<string> */
|
||||||
public static array $_search_path = [];
|
public static array $_search_path = [];
|
||||||
|
|
||||||
private static function find_images_internal(int $start = 0, ?int $limit = null, array $tags = []): iterable
|
/**
|
||||||
|
* @param list<string> $tags
|
||||||
|
*/
|
||||||
|
private static function find_images_internal(int $start = 0, ?int $limit = null, array $tags = []): \FFSPHP\PDOStatement
|
||||||
{
|
{
|
||||||
global $database, $user;
|
global $database, $user;
|
||||||
|
|
||||||
|
@ -78,7 +76,7 @@ class Search
|
||||||
/**
|
/**
|
||||||
* Search for an array of images
|
* Search for an array of images
|
||||||
*
|
*
|
||||||
* @param string[] $tags
|
* @param list<string> $tags
|
||||||
* @return Image[]
|
* @return Image[]
|
||||||
*/
|
*/
|
||||||
#[Query(name: "posts", type: "[Post!]!", args: ["tags" => "[string!]"])]
|
#[Query(name: "posts", type: "[Post!]!", args: ["tags" => "[string!]"])]
|
||||||
|
@ -95,6 +93,9 @@ class Search
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for an array of images, returning a iterable object of Image
|
* Search for an array of images, returning a iterable object of Image
|
||||||
|
*
|
||||||
|
* @param list<string> $tags
|
||||||
|
* @return \Generator<Image>
|
||||||
*/
|
*/
|
||||||
public static function find_images_iterable(int $start = 0, ?int $limit = null, array $tags = []): \Generator
|
public static function find_images_iterable(int $start = 0, ?int $limit = null, array $tags = []): \Generator
|
||||||
{
|
{
|
||||||
|
@ -186,6 +187,9 @@ class Search
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<int>
|
||||||
|
*/
|
||||||
private static function tag_or_wildcard_to_ids(string $tag): array
|
private static function tag_or_wildcard_to_ids(string $tag): array
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
|
@ -406,7 +410,7 @@ class Search
|
||||||
$img_sql .= " (" . $iq->qlet->sql . ")";
|
$img_sql .= " (" . $iq->qlet->sql . ")";
|
||||||
$img_vars = array_merge($img_vars, $iq->qlet->variables);
|
$img_vars = array_merge($img_vars, $iq->qlet->variables);
|
||||||
}
|
}
|
||||||
$query->append_sql(" AND ");
|
$query->append(new Querylet(" AND "));
|
||||||
$query->append(new Querylet($img_sql, $img_vars));
|
$query->append(new Querylet($img_sql, $img_vars));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -804,6 +804,12 @@ function stringer(mixed $s): string
|
||||||
/**
|
/**
|
||||||
* If a value is in the cache, return it; otherwise, call the callback
|
* If a value is in the cache, return it; otherwise, call the callback
|
||||||
* to generate it and store it in the cache.
|
* to generate it and store it in the cache.
|
||||||
|
*
|
||||||
|
* @template T
|
||||||
|
* @param string $key
|
||||||
|
* @param callable():T $callback
|
||||||
|
* @param int|null $ttl
|
||||||
|
* @return T
|
||||||
*/
|
*/
|
||||||
function cache_get_or_set(string $key, callable $callback, ?int $ttl = null): mixed
|
function cache_get_or_set(string $key, callable $callback, ?int $ttl = null): mixed
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,18 +6,30 @@ namespace Shimmie2;
|
||||||
|
|
||||||
use MicroHTML\HTMLElement;
|
use MicroHTML\HTMLElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed[] ...$args
|
||||||
|
*/
|
||||||
function TAGS(...$args): HTMLElement
|
function TAGS(...$args): HTMLElement
|
||||||
{
|
{
|
||||||
return new HTMLElement("tags", $args);
|
return new HTMLElement("tags", $args);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param mixed[] ...$args
|
||||||
|
*/
|
||||||
function TAG(...$args): HTMLElement
|
function TAG(...$args): HTMLElement
|
||||||
{
|
{
|
||||||
return new HTMLElement("tag", $args);
|
return new HTMLElement("tag", $args);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param mixed[] ...$args
|
||||||
|
*/
|
||||||
function POSTS(...$args): HTMLElement
|
function POSTS(...$args): HTMLElement
|
||||||
{
|
{
|
||||||
return new HTMLElement("posts", $args);
|
return new HTMLElement("posts", $args);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param mixed[] ...$args
|
||||||
|
*/
|
||||||
function POST(...$args): HTMLElement
|
function POST(...$args): HTMLElement
|
||||||
{
|
{
|
||||||
return new HTMLElement("post", $args);
|
return new HTMLElement("post", $args);
|
||||||
|
@ -75,6 +87,7 @@ class DanbooruApi extends Extension
|
||||||
$user = $duser;
|
$user = $duser;
|
||||||
} else {
|
} else {
|
||||||
$user = User::by_id($config->get_int("anon_id", 0));
|
$user = User::by_id($config->get_int("anon_id", 0));
|
||||||
|
assert(!is_null($user));
|
||||||
}
|
}
|
||||||
send_event(new UserLoginEvent($user));
|
send_event(new UserLoginEvent($user));
|
||||||
}
|
}
|
||||||
|
@ -299,6 +312,7 @@ class DanbooruApi extends Extension
|
||||||
} elseif (isset($_REQUEST['source']) || isset($_REQUEST['post']['source'])) { // A url was provided
|
} elseif (isset($_REQUEST['source']) || isset($_REQUEST['post']['source'])) { // A url was provided
|
||||||
$source = isset($_REQUEST['source']) ? $_REQUEST['source'] : $_REQUEST['post']['source'];
|
$source = isset($_REQUEST['source']) ? $_REQUEST['source'] : $_REQUEST['post']['source'];
|
||||||
$file = tempnam(sys_get_temp_dir(), "shimmie_transload");
|
$file = tempnam(sys_get_temp_dir(), "shimmie_transload");
|
||||||
|
assert($file !== false);
|
||||||
$ok = fetch_url($source, $file);
|
$ok = fetch_url($source, $file);
|
||||||
if (!$ok) {
|
if (!$ok) {
|
||||||
$page->set_code(409);
|
$page->set_code(409);
|
||||||
|
@ -317,6 +331,7 @@ class DanbooruApi extends Extension
|
||||||
|
|
||||||
// Was an md5 supplied? Does it match the file hash?
|
// Was an md5 supplied? Does it match the file hash?
|
||||||
$hash = md5_file($file);
|
$hash = md5_file($file);
|
||||||
|
assert($hash !== false);
|
||||||
if (isset($_REQUEST['md5']) && strtolower($_REQUEST['md5']) != $hash) {
|
if (isset($_REQUEST['md5']) && strtolower($_REQUEST['md5']) != $hash) {
|
||||||
$page->set_code(409);
|
$page->set_code(409);
|
||||||
$page->add_http_header("X-Danbooru-Errors: md5 mismatch");
|
$page->add_http_header("X-Danbooru-Errors: md5 mismatch");
|
||||||
|
|
Reference in a new issue