mirror of
https://codeberg.org/vlw/vlw.se.git
synced 2025-09-13 21:13:40 +02:00
Compare commits
No commits in common. "62ddd25f38b7efc6a34893eac57c2e1405a4b647" and "a6c74f5c4f961602864a140d4de96a0bb9224c5c" have entirely different histories.
62ddd25f38
...
a6c74f5c4f
7 changed files with 54 additions and 31 deletions
|
@ -6,8 +6,10 @@
|
||||||
|
|
||||||
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");
|
||||||
|
@ -27,7 +29,11 @@
|
||||||
(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();
|
||||||
|
@ -36,6 +42,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
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,8 +6,10 @@
|
||||||
|
|
||||||
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");
|
||||||
|
@ -17,12 +19,24 @@
|
||||||
|
|
||||||
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,8 +6,10 @@
|
||||||
|
|
||||||
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");
|
||||||
|
@ -33,7 +35,11 @@
|
||||||
|
|
||||||
(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();
|
||||||
|
@ -48,6 +54,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
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,7 +61,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,26 +0,0 @@
|
||||||
<?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,6 +15,7 @@
|
||||||
* 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
|
||||||
|
@ -23,6 +24,12 @@
|
||||||
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
|
||||||
|
@ -30,4 +37,5 @@
|
||||||
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,7 +27,6 @@ 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