mirror of
https://codeberg.org/vlw/vlw.se.git
synced 2025-09-13 21:13:40 +02:00
Compare commits
2 commits
a6c74f5c4f
...
62ddd25f38
Author | SHA1 | Date | |
---|---|---|---|
62ddd25f38 | |||
fef10a8ea8 |
7 changed files with 31 additions and 54 deletions
|
@ -6,10 +6,8 @@
|
||||||
|
|
||||||
use VLW\API\Endpoints;
|
use VLW\API\Endpoints;
|
||||||
use VLW\Database\Database;
|
use VLW\Database\Database;
|
||||||
use const VLW\FORGEJO_UPDATE_CACHE_PARAM;
|
|
||||||
use VLW\Database\Tables\About\LanguagesTable;
|
use VLW\Database\Tables\About\LanguagesTable;
|
||||||
|
|
||||||
require_once Path::root("src/Consts.php");
|
|
||||||
require_once Path::root("src/API/Endpoints.php");
|
require_once Path::root("src/API/Endpoints.php");
|
||||||
require_once Path::root("src/Database/Database.php");
|
require_once Path::root("src/Database/Database.php");
|
||||||
require_once Path::root("src/Database/Tables/About/Languages.php");
|
require_once Path::root("src/Database/Tables/About/Languages.php");
|
||||||
|
@ -29,11 +27,7 @@
|
||||||
(new Rules(LanguagesTable::BYTES->value))
|
(new Rules(LanguagesTable::BYTES->value))
|
||||||
->type(Type::NUMBER)
|
->type(Type::NUMBER)
|
||||||
->min(1)
|
->min(1)
|
||||||
->max(parent::SIZE_UINT32),
|
->max(parent::SIZE_UINT32)
|
||||||
|
|
||||||
(new Rules(FORGEJO_UPDATE_CACHE_PARAM))
|
|
||||||
->type(Type::BOOLEAN)
|
|
||||||
->default(false)
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->ruleset->validate_or_exit();
|
$this->ruleset->validate_or_exit();
|
||||||
|
@ -42,11 +36,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public function main(): Response {
|
public function main(): Response {
|
||||||
// Refresh the language cache if param is set
|
|
||||||
if ($_GET[FORGEJO_UPDATE_CACHE_PARAM]) {
|
|
||||||
(new Call(Endpoints::ABOUT_LANGUAGES->value))->post();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->list(LanguagesTable::NAME, LanguagesTable::values(), [
|
return $this->list(LanguagesTable::NAME, LanguagesTable::values(), [
|
||||||
LanguagesTable::BYTES->value => Order::DESC
|
LanguagesTable::BYTES->value => Order::DESC
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -6,10 +6,8 @@
|
||||||
|
|
||||||
use VLW\API\Endpoints;
|
use VLW\API\Endpoints;
|
||||||
use VLW\Database\Database;
|
use VLW\Database\Database;
|
||||||
use const VLW\COFFEE_STATS_UPDATE_PARAM;
|
|
||||||
use VLW\Database\Tables\Coffee\StatsTable;
|
use VLW\Database\Tables\Coffee\StatsTable;
|
||||||
|
|
||||||
require_once Path::root("src/Consts.php");
|
|
||||||
require_once Path::root("src/API/Endpoints.php");
|
require_once Path::root("src/API/Endpoints.php");
|
||||||
require_once Path::root("src/Database/Database.php");
|
require_once Path::root("src/Database/Database.php");
|
||||||
require_once Path::root("src/Database/Tables/Coffee/Stats.php");
|
require_once Path::root("src/Database/Tables/Coffee/Stats.php");
|
||||||
|
@ -19,24 +17,12 @@
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->ruleset = new Ruleset(strict: true);
|
$this->ruleset = new Ruleset(strict: true);
|
||||||
|
|
||||||
$this->ruleset->GET([
|
|
||||||
(new Rules(COFFEE_STATS_UPDATE_PARAM))
|
|
||||||
->type(Type::BOOLEAN)
|
|
||||||
->default(false)
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->ruleset->validate_or_exit();
|
$this->ruleset->validate_or_exit();
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function main(): Response {
|
public function main(): Response {
|
||||||
// Freshen cache if update flag is set
|
|
||||||
if ($_GET[COFFEE_STATS_UPDATE_PARAM]) {
|
|
||||||
(new Call(Endpoints::COFFEE_STATS->value))->post();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->list(StatsTable::NAME, StatsTable::values());
|
return $this->list(StatsTable::NAME, StatsTable::values());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,10 +6,8 @@
|
||||||
|
|
||||||
use VLW\API\Endpoints;
|
use VLW\API\Endpoints;
|
||||||
use VLW\Database\Database;
|
use VLW\Database\Database;
|
||||||
use const VLW\SEARCH_UPDATE_CACHE_PARM;
|
|
||||||
use VLW\Database\Tables\Search\{SearchTable, SearchCategoryEnum};
|
use VLW\Database\Tables\Search\{SearchTable, SearchCategoryEnum};
|
||||||
|
|
||||||
require_once Path::root("src/Consts.php");
|
|
||||||
require_once Path::root("src/API/Endpoints.php");
|
require_once Path::root("src/API/Endpoints.php");
|
||||||
require_once Path::root("src/Database/Database.php");
|
require_once Path::root("src/Database/Database.php");
|
||||||
require_once Path::root("src/Database/Tables/Search/Search.php");
|
require_once Path::root("src/Database/Tables/Search/Search.php");
|
||||||
|
@ -35,11 +33,7 @@
|
||||||
|
|
||||||
(new Rules(SearchTable::CATEGORY->value))
|
(new Rules(SearchTable::CATEGORY->value))
|
||||||
->type(Type::ENUM, SearchCategoryEnum::names())
|
->type(Type::ENUM, SearchCategoryEnum::names())
|
||||||
->default(null),
|
->default(null)
|
||||||
|
|
||||||
(new Rules(SEARCH_UPDATE_CACHE_PARM))
|
|
||||||
->type(Type::BOOLEAN)
|
|
||||||
->default(false)
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->ruleset->validate_or_exit();
|
$this->ruleset->validate_or_exit();
|
||||||
|
@ -54,11 +48,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public function main(): Response {
|
public function main(): Response {
|
||||||
// Freshen cache if update flag is set
|
|
||||||
if ($_GET[SEARCH_UPDATE_CACHE_PARM]) {
|
|
||||||
(new Call(Endpoints::SEARCH->value))->post();
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $this->db->for(SearchTable::NAME);
|
$result = $this->db->for(SearchTable::NAME);
|
||||||
|
|
||||||
if ($_GET[SearchTable::ID->value]) {
|
if ($_GET[SearchTable::ID->value]) {
|
||||||
|
|
|
@ -61,13 +61,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public function main(): Response {
|
public function main(): Response {
|
||||||
// Truncate existing cache
|
|
||||||
(new Call(Endpoints::SEARCH->value))->delete();
|
|
||||||
|
|
||||||
$this->index_work();
|
$this->index_work();
|
||||||
|
return new Response();
|
||||||
return $result->num_rows > 0
|
|
||||||
? new Response($result->fetch_all(MYSQLI_ASSOC))
|
|
||||||
: new Response([], 404);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
26
endpoints/update/GET.php
Normal file
26
endpoints/update/GET.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Reflect\{Response, Path, Call};
|
||||||
|
use ReflectRules\{Ruleset, Rules, Type};
|
||||||
|
|
||||||
|
use VLW\API\Endpoints;
|
||||||
|
|
||||||
|
require_once Path::root("src/API/Endpoints.php");
|
||||||
|
|
||||||
|
class GET_Update {
|
||||||
|
protected Ruleset $ruleset;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->ruleset = new Ruleset(strict: true);
|
||||||
|
$this->ruleset->validate_or_exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update all runtime database endpoints
|
||||||
|
public function main(): Response {
|
||||||
|
(new Call(Endpoints::SEARCH->value))->post();
|
||||||
|
(new Call(Endpoints::COFFEE_STATS->value))->post();
|
||||||
|
(new Call(Endpoints::ABOUT_LANGUAGES->value))->post();
|
||||||
|
|
||||||
|
return new Response();
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,7 +15,6 @@
|
||||||
* Constants for the search API endpoint
|
* Constants for the search API endpoint
|
||||||
*/
|
*/
|
||||||
const SEARCH_QUERY_MAX_LENGTH = 2048;
|
const SEARCH_QUERY_MAX_LENGTH = 2048;
|
||||||
const SEARCH_UPDATE_CACHE_PARM = "update";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* # Timeline
|
* # Timeline
|
||||||
|
@ -24,12 +23,6 @@
|
||||||
const TIMELINE_PREVIEW_LIMIT_PARAM = "limit";
|
const TIMELINE_PREVIEW_LIMIT_PARAM = "limit";
|
||||||
const TIMELINE_PREVIEW_LIMIT_COUNT = 5;
|
const TIMELINE_PREVIEW_LIMIT_COUNT = 5;
|
||||||
|
|
||||||
/**
|
|
||||||
* # Coffee
|
|
||||||
* Constants related to the coffee endpoints
|
|
||||||
*/
|
|
||||||
const COFFEE_STATS_UPDATE_PARAM = "update";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* # Forgejo
|
* # Forgejo
|
||||||
* Constants related to the fetching and caching of real-time prog. language use on Forgejo
|
* Constants related to the fetching and caching of real-time prog. language use on Forgejo
|
||||||
|
@ -37,5 +30,4 @@
|
||||||
const FORGEJO_HREF = "https://git.vlw.se/explore/repos?q=&sort=recentupdate&language=";
|
const FORGEJO_HREF = "https://git.vlw.se/explore/repos?q=&sort=recentupdate&language=";
|
||||||
const FORGEJO_ENDPOINT_USER = "/api/v1/users/%s";
|
const FORGEJO_ENDPOINT_USER = "/api/v1/users/%s";
|
||||||
const FORGEJO_ENDPOINT_SEARCH = "/api/v1/repos/search?uid=%s";
|
const FORGEJO_ENDPOINT_SEARCH = "/api/v1/repos/search?uid=%s";
|
||||||
const FORGEJO_SI_BYTE_MULTIPLE = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
const FORGEJO_SI_BYTE_MULTIPLE = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||||
const FORGEJO_UPDATE_CACHE_PARAM = "update";
|
|
|
@ -27,6 +27,7 @@ INSERT INTO `endpoints` (`id`, `active`) VALUES
|
||||||
('notes', 1),
|
('notes', 1),
|
||||||
('playground/coffee', 1),
|
('playground/coffee', 1),
|
||||||
('search', 1),
|
('search', 1),
|
||||||
|
('update', 1),
|
||||||
('work', 1),
|
('work', 1),
|
||||||
('work/actions', 1),
|
('work/actions', 1),
|
||||||
('work/tags', 1),
|
('work/tags', 1),
|
||||||
|
|
Loading…
Add table
Reference in a new issue