more typing
This commit is contained in:
parent
6bde7457e7
commit
448e270da8
3 changed files with 38 additions and 13 deletions
|
@ -8,6 +8,10 @@ use GQLA\Query;
|
|||
|
||||
class Querylet
|
||||
{
|
||||
/**
|
||||
* @param string $sql
|
||||
* @param array<string, mixed> $variables
|
||||
*/
|
||||
public function __construct(
|
||||
public string $sql,
|
||||
public array $variables = [],
|
||||
|
@ -19,16 +23,6 @@ class Querylet
|
|||
$this->sql .= $querylet->sql;
|
||||
$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
|
||||
|
@ -51,9 +45,13 @@ class ImgCondition
|
|||
|
||||
class Search
|
||||
{
|
||||
/** @var list<string> */
|
||||
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;
|
||||
|
||||
|
@ -78,7 +76,7 @@ class Search
|
|||
/**
|
||||
* Search for an array of images
|
||||
*
|
||||
* @param string[] $tags
|
||||
* @param list<string> $tags
|
||||
* @return Image[]
|
||||
*/
|
||||
#[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
|
||||
*
|
||||
* @param list<string> $tags
|
||||
* @return \Generator<Image>
|
||||
*/
|
||||
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
|
||||
{
|
||||
global $database;
|
||||
|
@ -406,7 +410,7 @@ class Search
|
|||
$img_sql .= " (" . $iq->qlet->sql . ")";
|
||||
$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));
|
||||
}
|
||||
|
||||
|
|
|
@ -804,6 +804,12 @@ function stringer(mixed $s): string
|
|||
/**
|
||||
* If a value is in the cache, return it; otherwise, call the callback
|
||||
* 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
|
||||
{
|
||||
|
|
|
@ -6,18 +6,30 @@ namespace Shimmie2;
|
|||
|
||||
use MicroHTML\HTMLElement;
|
||||
|
||||
/**
|
||||
* @param mixed[] ...$args
|
||||
*/
|
||||
function TAGS(...$args): HTMLElement
|
||||
{
|
||||
return new HTMLElement("tags", $args);
|
||||
}
|
||||
/**
|
||||
* @param mixed[] ...$args
|
||||
*/
|
||||
function TAG(...$args): HTMLElement
|
||||
{
|
||||
return new HTMLElement("tag", $args);
|
||||
}
|
||||
/**
|
||||
* @param mixed[] ...$args
|
||||
*/
|
||||
function POSTS(...$args): HTMLElement
|
||||
{
|
||||
return new HTMLElement("posts", $args);
|
||||
}
|
||||
/**
|
||||
* @param mixed[] ...$args
|
||||
*/
|
||||
function POST(...$args): HTMLElement
|
||||
{
|
||||
return new HTMLElement("post", $args);
|
||||
|
@ -75,6 +87,7 @@ class DanbooruApi extends Extension
|
|||
$user = $duser;
|
||||
} else {
|
||||
$user = User::by_id($config->get_int("anon_id", 0));
|
||||
assert(!is_null($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
|
||||
$source = isset($_REQUEST['source']) ? $_REQUEST['source'] : $_REQUEST['post']['source'];
|
||||
$file = tempnam(sys_get_temp_dir(), "shimmie_transload");
|
||||
assert($file !== false);
|
||||
$ok = fetch_url($source, $file);
|
||||
if (!$ok) {
|
||||
$page->set_code(409);
|
||||
|
@ -317,6 +331,7 @@ class DanbooruApi extends Extension
|
|||
|
||||
// Was an md5 supplied? Does it match the file hash?
|
||||
$hash = md5_file($file);
|
||||
assert($hash !== false);
|
||||
if (isset($_REQUEST['md5']) && strtolower($_REQUEST['md5']) != $hash) {
|
||||
$page->set_code(409);
|
||||
$page->add_http_header("X-Danbooru-Errors: md5 mismatch");
|
||||
|
|
Reference in a new issue