Compare commits
1 commit
7313b9b0cd
...
d55a110ffb
Author | SHA1 | Date | |
---|---|---|---|
d55a110ffb |
|
@ -1,17 +1,4 @@
|
|||
date_time_zone = "Europe/Stockholm"
|
||||
|
||||
[api_database]
|
||||
host = ""
|
||||
user = ""
|
||||
pass = ""
|
||||
db = ""
|
||||
|
||||
[api_forgejo]
|
||||
base_url = ""
|
||||
cache_file = ""
|
||||
scan_profiles = ""
|
||||
|
||||
[api_client]
|
||||
[api]
|
||||
base_url = "https://api.vlw.one/"
|
||||
api_key = ""
|
||||
verify_peer = 0
|
8
.gitignore
vendored
|
@ -1,14 +1,8 @@
|
|||
# Public assets #
|
||||
#################
|
||||
public/robots.txt
|
||||
public/.well-known
|
||||
|
||||
assets/js/modules/npm
|
||||
assets/media/content
|
||||
|
||||
# Bootstrapping #
|
||||
#################
|
||||
vendor
|
||||
node_modules
|
||||
.env.ini
|
||||
|
||||
# OS generated files #
|
||||
|
|
31
README.md
|
@ -1,38 +1,32 @@
|
|||
# vlw.se
|
||||
This is the source code behind [vlw.se](https://vlw.se) which has been written from the ground up by me. This website is built on top of my [Vegvisir web framework](https://vegvisir.vlw.se) and my [Reflect API framework](https://reflect.vlw.se).
|
||||
This is the source code behind [vlw.se](https://vlw.se) which has been written from the ground up by me. This website is built on top of my [Vegvisir web framework](https://github.com/victorwesterlund/vegvisir) and my [Reflect API framework](https://github.com/victorwesterlund/reflect).
|
||||
|
||||
# Installation
|
||||
If you for whatever reason want to get this website up and running for yourself this is how that is done.
|
||||
|
||||
## This website requires the following prerequisites
|
||||
- [PHP 8.0+](https://www.php.net/)
|
||||
- [MariaDB 14+](https://mariadb.org/)
|
||||
- [The NPM package manager](https://www.npmjs.com/)
|
||||
- [The Reflect API framework](https://reflect.vlw.se)
|
||||
- [The Vegvisir web framework](https://vegvisir.vlw.se)
|
||||
- [The composer package manager](https://getcomposer.org/)
|
||||
This website is built for PHP 8.0+ and MariaDB 14+ (for the API database).
|
||||
|
||||
**Confimed supported framework versions:**
|
||||
Vegvisir|Reflect
|
||||
--|--
|
||||
✅ [`3.1.0`](https://codeberg.org/vegvisir/vegvisir/releases/tag/3.1.0)|✅ [`2.7.2`](https://codeberg.org/reflect/reflect/releases/tag/2.7.2)
|
||||
✅ [`2.4.3`](https://github.com/VictorWesterlund/vegvisir/releases/tag/2.4.3)|✅ [`2.6.3`](https://github.com/VictorWesterlund/reflect/releases/tag/2.6.3)
|
||||
|
||||
## Website (Vegvisir)
|
||||
1. **Download this repo**
|
||||
|
||||
Git clone or download this repo to any local folder
|
||||
```
|
||||
git clone https://codeberg.org/vlw/vlw.se
|
||||
git clone https://github.com/VictorWesterlund/vlw.se
|
||||
```
|
||||
2. **Download and install Vegvisir**
|
||||
|
||||
Follow the installation instructions for [Vegvisir](https://vegvisir.vlw.se/docs/installation) and point the `root_path` variable to your local vlw.se folder.
|
||||
Follow the installation instructions for [Vegvisir](https://github.com/victorwesterlund/vegvisir) and point the `site_path` variable to the local vlw.se folder.
|
||||
|
||||
3. **Run the install script**
|
||||
3. **Install dependencies**
|
||||
|
||||
This bash script will install dependencies and make npm modules public.
|
||||
Install dependencies with composer.
|
||||
```
|
||||
./install.sh
|
||||
composer install --optimize-autoloader
|
||||
```
|
||||
|
||||
Et voila! You probably want to install the API-side too but the website itself should now be accessible from your configured Vegvisir host.
|
||||
|
@ -46,16 +40,16 @@ The API (and database) is where most content is stored and served from on this w
|
|||
|
||||
Otherwise... Git clone or download this repo to any local folder
|
||||
```
|
||||
git clone https://codeberg.org/vlw/vlw.se
|
||||
git clone https://github.com/VictorWesterlund/vlw.se
|
||||
```
|
||||
|
||||
2. **Download and install Reflect**
|
||||
|
||||
Follow the installation instructions for [Reflect](https://reflect.vlw.se/docs/installation) and point the `endpoints` variable to the `/api` subdirectory in the local vlw.se folder.
|
||||
Follow the installation instructions for [Reflect](https://github.com/victorwesterlund/vegvisir) and point the `endpoints` variable to the `/api` subdirectory in the local vlw.se folder.
|
||||
|
||||
3. **Install dependencies**
|
||||
|
||||
`cd` into the api folder and install dependencies with composer.
|
||||
Install dependencies with composer.
|
||||
```
|
||||
composer install --optimize-autoloader
|
||||
```
|
||||
|
@ -68,6 +62,9 @@ The API (and database) is where most content is stored and served from on this w
|
|||
|
||||
Make a copy of `/api/.env.example.ini` and change the `[vlwdb]` variables with your MariaDB credentials.
|
||||
|
||||
You also have to generate a [GitHub access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) if you wish to use the `releases` endpoint.
|
||||
[Read more about this endpoint here](#)
|
||||
|
||||
6. **Set environment variables for website**
|
||||
|
||||
It's reasonable to assume if you've installed the website from this repo that you'd also want to use the API with it. Start my making a copy of `/.env.example.ini` (root directory) and change the `[api]` variables to point to your API hostname.
|
||||
|
|
|
@ -1,19 +1,11 @@
|
|||
[connect]
|
||||
database_host = ""
|
||||
database_user = ""
|
||||
database_pass = ""
|
||||
[vlwdb]
|
||||
mariadb_host = ""
|
||||
mariadb_user = ""
|
||||
mariadb_pass = ""
|
||||
mariadb_db = ""
|
||||
|
||||
[databases]
|
||||
vlw = ""
|
||||
battlestation = ""
|
||||
|
||||
; Forgejo instance config
|
||||
[forgejo]
|
||||
base_url = ""
|
||||
|
||||
; Forgejo language chart endpoints config
|
||||
[about_languages]
|
||||
; CSV of Forgejo profiles to include public source repositories from
|
||||
scan_profiles = ""
|
||||
; Path to a JSON file to store cached language endpoint responses
|
||||
cache_file = ""
|
||||
[github]
|
||||
api_key = ""
|
||||
# Use-Agent string sent to GitHub API
|
||||
# They recommend setting it to your GitHub username or app name
|
||||
user_agent = ""
|
|
@ -1,8 +1,14 @@
|
|||
{
|
||||
"require": {
|
||||
"local/api.endpoints": "1.0.0-dev",
|
||||
"reflect/plugin-rules": "^1.5",
|
||||
"victorwesterlund/xenum": "dev-master",
|
||||
"vlw/mysql": "dev-master"
|
||||
"victorwesterlund/xenum": "^1.1"
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
"minimum-stability": "dev",
|
||||
"repositories": [
|
||||
{
|
||||
"type": "path",
|
||||
"url": "src/packages/Endpoints"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
81
api/composer.lock
generated
|
@ -4,15 +4,46 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "f3f2b3cb3bd789eee6af4a93f4a6e0f9",
|
||||
"content-hash": "9da96ba90ef20d885034442b30dce0a3",
|
||||
"packages": [
|
||||
{
|
||||
"name": "local/api.endpoints",
|
||||
"version": "1.0.0-dev",
|
||||
"dist": {
|
||||
"type": "path",
|
||||
"url": "src/packages/Endpoints",
|
||||
"reference": "89b7b9a4cc504abddb4aeec8e05a95c9d9087575"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"VLW\\API\\": "src/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Victor Westerlund",
|
||||
"email": "victor@vlw.se"
|
||||
}
|
||||
],
|
||||
"description": "Endpoint pathmappings for VLW API",
|
||||
"transport-options": {
|
||||
"relative": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "reflect/plugin-rules",
|
||||
"version": "1.5.1",
|
||||
"version": "1.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://codeberg.org/reflect/reflect-rules-plugin",
|
||||
"reference": "df150f0d860dbc2311e5e2fcb2fac36ee52db56b"
|
||||
"url": "https://github.com/VictorWesterlund/reflect-rules-plugin.git",
|
||||
"reference": "9c837fd1944133edfed70a63ce8b32bf67f0d94b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/VictorWesterlund/reflect-rules-plugin/zipball/9c837fd1944133edfed70a63ce8b32bf67f0d94b",
|
||||
"reference": "9c837fd1944133edfed70a63ce8b32bf67f0d94b",
|
||||
"shasum": ""
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
|
@ -31,11 +62,15 @@
|
|||
}
|
||||
],
|
||||
"description": "Add request search paramter and request body constraints to an API built with Reflect",
|
||||
"time": "2024-11-20T10:39:33+00:00"
|
||||
"support": {
|
||||
"issues": "https://github.com/VictorWesterlund/reflect-rules-plugin/issues",
|
||||
"source": "https://github.com/VictorWesterlund/reflect-rules-plugin/tree/1.5.0"
|
||||
},
|
||||
"time": "2024-01-17T11:07:44+00:00"
|
||||
},
|
||||
{
|
||||
"name": "victorwesterlund/xenum",
|
||||
"version": "dev-master",
|
||||
"version": "1.1.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/VictorWesterlund/php-xenum.git",
|
||||
|
@ -47,7 +82,6 @@
|
|||
"reference": "8972f06f42abd1f382807a67e937d5564bb89699",
|
||||
"shasum": ""
|
||||
},
|
||||
"default-branch": true,
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@ -70,46 +104,17 @@
|
|||
"source": "https://github.com/VictorWesterlund/php-xenum/tree/1.1.1"
|
||||
},
|
||||
"time": "2023-11-20T10:10:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "vlw/mysql",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://codeberg.org/vlw/php-mysql",
|
||||
"reference": "619f43b3bfab9eb034dca3e54c7466055240c861"
|
||||
},
|
||||
"default-branch": true,
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"vlw\\MySQL\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"GPL-3.0-or-later"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Victor Westerlund",
|
||||
"email": "victor@vlw.se"
|
||||
}
|
||||
],
|
||||
"description": "Abstraction library for common MySQL/MariaDB DML operations with php-mysqli",
|
||||
"time": "2024-09-25T13:28:15+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "dev",
|
||||
"stability-flags": {
|
||||
"victorwesterlund/xenum": 20,
|
||||
"vlw/mysql": 20
|
||||
"local/api.endpoints": 20
|
||||
},
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.3.0"
|
||||
"plugin-api-version": "2.0.0"
|
||||
}
|
||||
|
|
39
api/endpoints/coffee/GET.php
Executable file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Coffee\CoffeeModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/Coffee.php");
|
||||
|
||||
class GET_Coffee extends VLWdb {
|
||||
const LIST_LIMIT = 20;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Get the last LIST_LIMIT coffees from the database
|
||||
$resp = $this->db->for(CoffeeModel::TABLE)
|
||||
->order([CoffeeModel::DATE_TIMESTAMP_CREATED->value => "DESC"])
|
||||
->limit(self::LIST_LIMIT)
|
||||
->select([
|
||||
CoffeeModel::ID->value,
|
||||
CoffeeModel::DATE_TIMESTAMP_CREATED->value
|
||||
]);
|
||||
|
||||
return parent::is_mysqli_result($resp)
|
||||
? new Response($resp->fetch_all(MYSQLI_ASSOC))
|
||||
: $this->resp_database_error();
|
||||
}
|
||||
}
|
36
api/endpoints/coffee/POST.php
Executable file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Coffee\CoffeeModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/Coffee.php");
|
||||
|
||||
class POST_Coffee extends VLWdb {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to record coffee! Ugh please take a note somewhere else", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Generate UUID for entity
|
||||
$id = parent::gen_uuid4();
|
||||
|
||||
// Attempt to create new entity
|
||||
$insert = $this->db->for(CoffeeModel::TABLE)
|
||||
->insert([
|
||||
CoffeeModel::ID->value => $id,
|
||||
CoffeeModel::DATE_TIMESTAMP_CREATED->value => time(),
|
||||
]);
|
||||
|
||||
// Return 201 Created and entity id if successful
|
||||
return $insert ? new Response($id, 201) : $this->resp_database_error();
|
||||
}
|
||||
}
|
95
api/endpoints/media/GET.php
Executable file
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Media\MediaModel;
|
||||
|
||||
use victorwesterlund\xEnum;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/Media.php");
|
||||
|
||||
enum MediaDispositionEnum: string {
|
||||
use xEnum;
|
||||
|
||||
case METADATA = "metadata";
|
||||
case INLINE = "inline";
|
||||
case DOWNLOAD = "download";
|
||||
}
|
||||
|
||||
class GET_Media extends VLWdb {
|
||||
const GET_DISPOSITION_KEY = "disposition";
|
||||
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(MediaModel::ID->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(self::GET_DISPOSITION_KEY))
|
||||
->type(Type::ENUM, MediaDispositionEnum::values())
|
||||
->default(MediaDispositionEnum::METADATA->value)
|
||||
]);
|
||||
}
|
||||
|
||||
// # Helper methods
|
||||
|
||||
private function fetch_srcset(string $id): array {
|
||||
$resp = $this->db->for(WorkTagsModel::TABLE)
|
||||
->where([WorkTagsModel::ANCHOR->value => $id])
|
||||
->select(WorkTagsModel::NAME->value);
|
||||
|
||||
return parent::is_mysqli_result($resp) ? $resp->fetch_all(MYSQLI_ASSOC) : [];
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
$resp = $this->db->for(MediaModel::TABLE)
|
||||
->where([MediaModel::ID->value => $_GET[MediaModel::ID->value]])
|
||||
->select([
|
||||
MediaModel::ID->value,
|
||||
MediaModel::NAME->value,
|
||||
MediaModel::TYPE->value,
|
||||
MediaModel::MIME->value,
|
||||
MediaModel::EXTENSION->value,
|
||||
MediaModel::SRCSET->value,
|
||||
MediaModel::DATE_TIMESTAMP_CREATED->value,
|
||||
]);
|
||||
|
||||
// Bail out if something went wrong retrieving rows from the database
|
||||
if (!parent::is_mysqli_result($resp)) {
|
||||
return $this->resp_database_error();
|
||||
}
|
||||
|
||||
$media = $resp->fetch_assoc();
|
||||
$test = true;
|
||||
}
|
||||
}
|
117
api/endpoints/media/POST.php
Executable file
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use Reflect\Method;
|
||||
use function Reflect\Call;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Media\MediaModel;
|
||||
use VLW\API\Databases\VLWdb\Models\Media\MediaTypeEnum;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/Media.php");
|
||||
|
||||
class POST_Media extends VLWdb {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules(MediaModel::ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
->default(parent::gen_uuid4()),
|
||||
|
||||
(new Rules(MediaModel::NAME->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
->default(null),
|
||||
|
||||
(new Rules(MediaModel::TYPE->value))
|
||||
->type(Type::ENUM, MediaTypeEnum::values())
|
||||
->default(null),
|
||||
|
||||
(new Rules(MediaModel::EXTENSION->value))
|
||||
->type(Type::STRING)
|
||||
->min(3)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
->default(null),
|
||||
|
||||
(new Rules(MediaModel::MIME->value))
|
||||
->type(Type::STRING)
|
||||
->min(3)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
->default(null),
|
||||
|
||||
(new Rules(MediaModel::SRCSET->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
->default(null)
|
||||
]);
|
||||
}
|
||||
|
||||
// # Helper methods
|
||||
|
||||
// Returns true if an srcset exists for provided key
|
||||
private static function media_srcset_exists(): bool {
|
||||
// No srcet get parameter has been set
|
||||
if (empty($_POST[MediaModel::SRCSET->value])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the provided srcset exists by calling the srcset endpoint
|
||||
return Call("media/srcset?id={$_POST[MediaModel::SRCSET->value]}", Method::GET)->ok;
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
// Bail out if an srcset doesn't exist
|
||||
if (!self::media_srcset_exists()) {
|
||||
return new Response("No media srcset exists with id '{$_POST[MediaModel::SRCSET->value]}'", 404);
|
||||
}
|
||||
|
||||
$insert = $this->db->for(MediaModel::TABLE)
|
||||
->insert([
|
||||
MediaModel::ID->value => $_POST[MediaModel::ID->value],
|
||||
MediaModel::NAME->value => $_POST[MediaModel::NAME->value],
|
||||
MediaModel::MIME->value => $_POST[MediaModel::MIME->value],
|
||||
// Strip dots from extension string if set
|
||||
MediaModel::EXTENSION->value => $_POST[MediaModel::EXTENSION->value]
|
||||
? str_replace(".", "", $_POST[MediaModel::EXTENSION->value])
|
||||
: null,
|
||||
MediaModel::SRCSET->value => $_POST[MediaModel::SRCSET->value],
|
||||
MediaModel::DATE_TIMESTAMP_CREATED->value => time()
|
||||
]);
|
||||
|
||||
// Return media id if insert was successful
|
||||
return $insert
|
||||
? new Response($_POST[MediaModel::ID->value], 201)
|
||||
: $this->resp_database_error();
|
||||
}
|
||||
}
|
106
api/endpoints/media/srcset/GET.php
Executable file
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Media\MediaModel;
|
||||
use VLW\API\Databases\VLWdb\Models\MediaSrcset\MediaSrcsetModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/Media.php");
|
||||
require_once Path::root("src/databases/models/MediaSrcset.php");
|
||||
|
||||
class GET_MediaSrcset extends VLWdb {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(MediaSrcsetModel::ID->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
}
|
||||
|
||||
// # Helper methods
|
||||
|
||||
// Get metadata for the requested srcset
|
||||
private function get_srcset(): array|false {
|
||||
$srcset = $this->db->for(MediaSrcsetModel::TABLE)
|
||||
->where([MediaSrcsetModel::ID->value => $_GET[MediaSrcsetModel::ID->value]])
|
||||
->select([MediaSrcsetModel::ANCHOR_DEFAULT->value]);
|
||||
|
||||
// Something went wrong retrieving rows from the database
|
||||
if (!parent::is_mysqli_result($srcset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return assoc array of srcset data if it exists
|
||||
return $srcset->num_rows === 1 ? $srcset->fetch_assoc() : false;
|
||||
}
|
||||
|
||||
// Get all media entities that are part of the requested srcset
|
||||
private function get_srcset_media(): mysqli_result|false {
|
||||
$media = $this->db->for(MediaModel::TABLE)
|
||||
->where([MediaModel::SRCSET->value => $_GET[MediaSrcsetModel::ID->value]])
|
||||
->select([
|
||||
MediaModel::ID->value,
|
||||
MediaModel::TYPE->value,
|
||||
MediaModel::MIME->value,
|
||||
MediaModel::EXTENSION->value
|
||||
]);
|
||||
|
||||
return parent::is_mysqli_result($media) ? $media : false;
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
// Get srcset data
|
||||
$srcset = $this->get_srcset();
|
||||
if (!$srcset) {
|
||||
return new Response("No media srcset exist with id '{$_GET[MediaSrcsetModel::ID->value]}'", 404);
|
||||
}
|
||||
|
||||
$media = $this->get_srcset_media();
|
||||
if (!$media) {
|
||||
return new Response("Failed to fetch srcset media", 500);
|
||||
}
|
||||
|
||||
$media_entities = $media->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
// This is the id of the media entity that is considered the default or "fallback"
|
||||
$srcet_default_media_id = $srcset[MediaSrcsetModel::ANCHOR_DEFAULT->value];
|
||||
|
||||
// Return assoc array of all media entities that are in this srcset
|
||||
return new Response([
|
||||
// Return default media entity separately from the rest of the srcset as an assoc array
|
||||
"default" => array_filter($media_entities, fn(array $entity) => $entity[MediaModel::ID->value] === $srcet_default_media_id)[0],
|
||||
// Return all media that isn't default as array of assoc arrays
|
||||
"srcset" => array_filter($media_entities, fn(array $entity) => $entity[MediaModel::ID->value] !== $srcet_default_media_id)
|
||||
]);
|
||||
}
|
||||
}
|
55
api/endpoints/media/srcset/POST.php
Executable file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
|
||||
use Reflect\Method;
|
||||
use function Reflect\Call;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\MediaSrcset\MediaSrcsetModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/Media.php");
|
||||
require_once Path::root("src/databases/models/MediaSrcset.php");
|
||||
|
||||
class POST_MediaSrcset extends VLWdb {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Generate a random UUID for this srcset
|
||||
$id = parent::gen_uuid4();
|
||||
|
||||
// Ensure an srcset with the generated id doesn't exist, although it shouldn't realistically ever happen
|
||||
$srcset_existing = Call("media/srcset?id={$id}", Method::GET);
|
||||
if ($srcset_existing->code !== 404) {
|
||||
// Wow a UUID4 collision... buy a lottery ticket
|
||||
if ($srcset_existing->code === 200) {
|
||||
return $this->main();
|
||||
}
|
||||
|
||||
// Failed to get srcset
|
||||
return new Response("Something went wrong when checking if the srcset exists", 500);
|
||||
}
|
||||
|
||||
// Create new srcset entity
|
||||
$insert = $this->db->for(MediaSrcsetModel::TABLE)
|
||||
->insert([
|
||||
MediaSrcsetModel::ID->value => $id
|
||||
]);
|
||||
|
||||
// Return created srcset id if successful
|
||||
return $insert
|
||||
? new Response($id, 201)
|
||||
: $this->resp_database_error();
|
||||
}
|
||||
}
|
79
api/endpoints/messages/POST.php
Executable file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use Reflect\Method;
|
||||
use function Reflect\Call;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Messages\MessagesModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/Messages.php");
|
||||
|
||||
class POST_Messages extends VLWdb {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules(MessagesModel::EMAIL->value))
|
||||
->type(Type::STRING)
|
||||
->max(255)
|
||||
->default(null),
|
||||
|
||||
(new Rules(MessagesModel::MESSAGE->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_TEXT_MAX_LENGTH)
|
||||
]);
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
//return new Response(["hello" => "maybe"], 500);
|
||||
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
// Generate UUID for entity
|
||||
$id = parent::gen_uuid4();
|
||||
|
||||
// Attempt to create new entity
|
||||
$insert = $this->db->for(MessagesModel::TABLE)
|
||||
->insert([
|
||||
MessagesModel::ID->value => $id,
|
||||
MessagesModel::EMAIL->value => $_POST["email"],
|
||||
MessagesModel::MESSAGE->value => $_POST["message"],
|
||||
MessagesModel::DATE_TIMESTAMP_CREATED->value => time(),
|
||||
]);
|
||||
|
||||
// Bail out if insert failed
|
||||
if (!$insert) {
|
||||
return $this->resp_database_error();
|
||||
}
|
||||
|
||||
// Return 201 Created and entity id
|
||||
return new Response($id, 201);
|
||||
}
|
||||
}
|
223
api/endpoints/releases/POST.php
Executable file
|
@ -0,0 +1,223 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use Reflect\Method;
|
||||
use function Reflect\Call;
|
||||
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkModel;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkTagsModel;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkTagsNameEnum;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkActionsModel;
|
||||
|
||||
require_once Path::root("src/databases/models/Work.php");
|
||||
require_once Path::root("src/databases/models/WorkTags.php");
|
||||
require_once Path::root("src/databases/models/WorkActions.php");
|
||||
|
||||
// "Virtual" database model for the POST request body since we're not writing to a db directly
|
||||
enum ReleasesPostModel: string {
|
||||
case GITHUB_USER = "user";
|
||||
case GITHUB_REPO = "repo";
|
||||
case GITHUB_TAG = "tag";
|
||||
}
|
||||
|
||||
class POST_Releases {
|
||||
// Base URL of the GitHub API (no tailing slash)
|
||||
const GITHUB_API = "https://api.github.com";
|
||||
|
||||
const REGEX_HANDLE = "/@[\w]+/";
|
||||
const REGEX_URL = "/\b(?:https?):\/\/\S+\b/";
|
||||
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
protected CurlHandle $curl;
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules(ReleasesPostModel::GITHUB_USER->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1),
|
||||
|
||||
(new Rules(ReleasesPostModel::GITHUB_REPO->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1),
|
||||
|
||||
(new Rules(ReleasesPostModel::GITHUB_TAG->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
]);
|
||||
|
||||
$this->curl = curl_init();
|
||||
|
||||
curl_setopt($this->curl, CURLOPT_USERAGENT, $_ENV["github"]["user_agent"]);
|
||||
curl_setopt($this->curl, CURLOPT_HEADER, true);
|
||||
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($this->curl, CURLOPT_HTTPHEADER, [
|
||||
"Accept" => "application/vnd.github+json",
|
||||
"Authorization" => "token {$_ENV["github"]["api_key"]}",
|
||||
"X-GitHub-Api-Version" => "2022-11-28"
|
||||
]);
|
||||
}
|
||||
|
||||
// # GitHub
|
||||
|
||||
// Generate HTML from a GitHub "auto-generate" release body
|
||||
protected static function gh_auto_release_md_to_html(string $md): string {
|
||||
$output = "";
|
||||
|
||||
// Parse each line of markdown
|
||||
$lines = explode(PHP_EOL, $md);
|
||||
|
||||
foreach ($lines as $i => $line) {
|
||||
// Ignore header line from releases
|
||||
if ($i < 1) continue;
|
||||
|
||||
// Replace all URLs with HTMLAnchor tags, they will be PRs
|
||||
$links = [];
|
||||
preg_match_all(self::REGEX_URL, $line, $links, PREG_UNMATCHED_AS_NULL);
|
||||
foreach ($links as $i => $link) {
|
||||
if (empty($link)) continue;
|
||||
|
||||
// Last crumb from link pathname will be the PR id
|
||||
$pr_id = explode("/", $link[$i]);
|
||||
$pr_id = end($pr_id);
|
||||
|
||||
$line = str_replace($link, "<a href='{$link[$i]}'>{$pr_id}</a>", $line);
|
||||
}
|
||||
|
||||
// Replace all at-handles with links to GitHub user profiles
|
||||
$handles = [];
|
||||
preg_match_all(self::REGEX_HANDLE, $line, $handles, PREG_UNMATCHED_AS_NULL);
|
||||
foreach ($handles as $i => $handle) {
|
||||
if (empty($handle)) continue;
|
||||
|
||||
// GitHub user URL without the "@"
|
||||
$url = "https://github.com/" . substr($handle[$i], 1);
|
||||
|
||||
$line = str_replace($handle, "<a href='{$url}'>{$handle[$i]}</a>", $line);
|
||||
}
|
||||
|
||||
$output .= "<p>{$line}</p>";
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
// Return fully qualified URL to GitHub API releases endpoint
|
||||
private static function get_url(): string {
|
||||
return implode("/", [
|
||||
self::GITHUB_API,
|
||||
"repos",
|
||||
$_POST[ReleasesPostModel::GITHUB_USER->value],
|
||||
$_POST[ReleasesPostModel::GITHUB_REPO->value],
|
||||
"releases",
|
||||
"tags",
|
||||
$_POST[ReleasesPostModel::GITHUB_TAG->value],
|
||||
]);
|
||||
}
|
||||
|
||||
// Fetch release information from GitHub API
|
||||
private function fetch_release_data(): array {
|
||||
$url = self::get_url();
|
||||
curl_setopt($this->curl, CURLOPT_URL, self::get_url());
|
||||
|
||||
$resp = curl_exec($this->curl);
|
||||
|
||||
$header_size = curl_getinfo($this->curl, CURLINFO_HEADER_SIZE);
|
||||
$header = substr($resp, 0, $header_size);
|
||||
$body = substr($resp, $header_size);
|
||||
|
||||
return json_decode($body, true);
|
||||
}
|
||||
|
||||
// # Sup
|
||||
|
||||
private function create_link_to_release_page(string $id, string $href): Response {
|
||||
return Call("work/actions?id={$id}", Method::POST, [
|
||||
WorkActionsModel::DISPLAY_TEXT->value => "Release details",
|
||||
WorkActionsModel::HREF->value => $href,
|
||||
WorkActionsModel::EXTERNAL->value => true
|
||||
]);
|
||||
}
|
||||
|
||||
// Create a tag for entity
|
||||
private function create_tag(string $id, WorkTagsNameEnum $tag): Response {
|
||||
return Call("work/tags?id={$id}", Method::POST, [
|
||||
// Set "RELEASE" tag on new entity
|
||||
WorkTagsModel::NAME->value => $tag->value
|
||||
]);
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
$data = $this->fetch_release_data();
|
||||
if (!$data) {
|
||||
return new Response("Failed to fetch release data", 500);
|
||||
}
|
||||
|
||||
|
||||
// Transform repo name to lowercase for summary title
|
||||
$title = strtolower($_POST["repo"]);
|
||||
|
||||
// Use repo name and tag name as heading for summary
|
||||
$summary = "<h3>Release {$title}@{$data["name"]}</h3>";
|
||||
// Append HTML-ified release notes from GitHub to summary
|
||||
$summary .= self::gh_auto_release_md_to_html($data["body"]);
|
||||
|
||||
$date_published = new \DateTime($data["published_at"], new \DateTimeZone("UTC"));
|
||||
|
||||
// Create work entity
|
||||
$work_entity = Call("work", Method::POST, [
|
||||
WorkModel::SUMMARY->value => $summary,
|
||||
// Convert time created to Unix timestamp for work endpoint
|
||||
WorkModel::DATE_TIMESTAMP_CREATED->value => $date_published->format("U"),
|
||||
]);
|
||||
|
||||
// Bail out if creating the work entity failed
|
||||
if (!$work_entity->ok) {
|
||||
return new Response("Failed to create work entity for release", 500);
|
||||
}
|
||||
|
||||
$work_entity_id = $work_entity->output();
|
||||
|
||||
// Create entity tags for release
|
||||
$tags = [
|
||||
WorkTagsNameEnum::VLW,
|
||||
WorkTagsNameEnum::RELEASE
|
||||
];
|
||||
foreach ($tags as $tag) {
|
||||
// Create entity tag for release or exit if failed to create
|
||||
if (!$this->create_tag($work_entity_id, $tag)->ok) {
|
||||
return new Response("Failed to create {$tag->name} tag for release entity", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Create link to release page on GitHub
|
||||
if (!$this->create_link_to_release_page($work_entity_id, $data["html_url"])) {
|
||||
return new Response("Failed to create link to release page on GitHub", 500);
|
||||
}
|
||||
|
||||
return new Response($work_entity_id, 201);
|
||||
}
|
||||
}
|
140
api/endpoints/search/GET.php
Executable file
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Call;
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use VLW\API\Endpoints;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkModel;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkActionsModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/Work.php");
|
||||
require_once Path::root("src/databases/models/WorkActions.php");
|
||||
|
||||
class GET_Search extends VLWdb {
|
||||
const GET_QUERY = "q";
|
||||
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(self::GET_QUERY))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(2)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
}
|
||||
|
||||
// Return an SQL string from array for use in prepared statements
|
||||
private static function array_to_wildcard_sql(array $columns): string {
|
||||
$sql = array_map(fn(string $column): string => "{$column} LIKE CONCAT('%', ?, '%')", $columns);
|
||||
|
||||
return implode(" OR ", $sql);
|
||||
}
|
||||
|
||||
// Return chained AND statements from array for use in prepared statements
|
||||
private static function array_to_and_statement(array $keys): string {
|
||||
$sql = array_map(fn(string $k): string => "{$k} = ?", $keys);
|
||||
|
||||
return implode(" AND ", $sql);
|
||||
}
|
||||
|
||||
// Wildcard search columns in table with query string from query string
|
||||
// This has to be implemented manually until "libmysqldriver/MySQL" supports wildcard SELECT
|
||||
private function search(string $table, array $columns, array $conditions = null): array {
|
||||
// Create CSV from columns array
|
||||
$columns_concat = implode(",", $columns);
|
||||
|
||||
// Create SQL LIKE wildcard statement for each column.
|
||||
$where = self::array_to_wildcard_sql($columns);
|
||||
|
||||
// Create array of values from query string for each colum
|
||||
$values = array_fill(0, count($columns), $_GET[self::GET_QUERY]);
|
||||
|
||||
if ($conditions) {
|
||||
$conditions_sql = self::array_to_and_statement(array_keys($conditions));
|
||||
|
||||
// Wrap positive where statements and prepare new group of conditions
|
||||
// WHERE (<search_terms>) AND (<conditions>)
|
||||
$where = "({$where}) AND ({$conditions_sql})";
|
||||
|
||||
// Append values from conditions statements to prepared statement
|
||||
array_push($values, ...array_values($conditions));
|
||||
}
|
||||
|
||||
// Order the rows by the array index of $colums received
|
||||
$rows = $this->db->exec("SELECT {$columns_concat} FROM {$table} WHERE {$where} ORDER BY {$columns_concat}", $values);
|
||||
// Return results as assoc or empty array
|
||||
return parent::is_mysqli_result($rows) ? $rows->fetch_all(MYSQLI_ASSOC) : [];
|
||||
}
|
||||
|
||||
// Search work table
|
||||
private function search_work(): array {
|
||||
$search = [
|
||||
WorkModel::TITLE->value,
|
||||
WorkModel::SUMMARY->value,
|
||||
WorkModel::DATE_TIMESTAMP_CREATED->value,
|
||||
WorkModel::ID->value
|
||||
];
|
||||
|
||||
$conditions = [
|
||||
WorkModel::IS_LISTABLE->value => true
|
||||
];
|
||||
|
||||
$results = $this->search(WorkModel::TABLE, $search, $conditions);
|
||||
|
||||
foreach ($results as &$result) {
|
||||
$result["actions"] = (new Call(Endpoints::WORK_ACTIONS->value))
|
||||
->params([WorkActionsModel::ANCHOR->value => $result[WorkModel::ID->value]])
|
||||
->get()->output();
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
// Get search results for each category
|
||||
$categories = [
|
||||
WorkModel::TABLE => $this->search_work()
|
||||
];
|
||||
|
||||
// Count total number of results from all categories
|
||||
$total_num_results = 0;
|
||||
foreach (array_values($categories) as $results) {
|
||||
$total_num_results += count($results);
|
||||
}
|
||||
|
||||
return new Response([
|
||||
"query" => $_GET[self::GET_QUERY],
|
||||
"results" => $categories,
|
||||
"total_num_results" => $total_num_results
|
||||
]);
|
||||
}
|
||||
}
|
60
api/endpoints/work/DELETE.php
Executable file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/Work.php");
|
||||
|
||||
class DELETE_Work extends VLWdb {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules("id"))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to delete work data, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
// Attempt to update the entity
|
||||
$update = $this->db->for(WorkModel::TABLE)
|
||||
->where([WorkModel::ID->value => $_GET["id"]])
|
||||
->update([
|
||||
WorkModel::IS_LISTABLE->value => false,
|
||||
WorkModel::IS_READABLE->value => false
|
||||
]);
|
||||
|
||||
return $update ? new Response($_GET["id"]) : $this->resp_database_error();
|
||||
}
|
||||
}
|
136
api/endpoints/work/GET.php
Executable file
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Call;
|
||||
use Reflect\Path;
|
||||
use Reflect\Method;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use VLW\API\Endpoints;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkModel;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkTagsModel;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkActionsModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/Work.php");
|
||||
require_once Path::root("src/databases/models/WorkTags.php");
|
||||
require_once Path::root("src/databases/models/WorkActions.php");
|
||||
|
||||
class GET_Work extends VLWdb {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules("id"))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
->default(null)
|
||||
]);
|
||||
}
|
||||
|
||||
// # Helper methods
|
||||
|
||||
private function fetch_row_tags(string $id): array {
|
||||
$resp = $this->db->for(WorkTagsModel::TABLE)
|
||||
->where([WorkTagsModel::ANCHOR->value => $id])
|
||||
->select(WorkTagsModel::NAME->value);
|
||||
|
||||
return parent::is_mysqli_result($resp) ? $resp->fetch_all(MYSQLI_ASSOC) : [];
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
private function resp_item_details(string $id): Response {
|
||||
$resp = $this->db->for(WorkModel::TABLE)
|
||||
->where([
|
||||
WorkModel::ID->value => $id,
|
||||
WorkModel::IS_READABLE->value => true
|
||||
])
|
||||
->limit(1)
|
||||
->select([
|
||||
WorkModel::ID->value,
|
||||
WorkModel::TITLE->value,
|
||||
WorkModel::SUMMARY->value,
|
||||
WorkModel::COVER_SRCSET->value,
|
||||
WorkModel::DATE_YEAR->value,
|
||||
WorkModel::DATE_MONTH->value,
|
||||
WorkModel::DATE_DAY->value,
|
||||
WorkModel::DATE_TIMESTAMP_MODIFIED->value,
|
||||
WorkModel::DATE_TIMESTAMP_CREATED->value
|
||||
]);
|
||||
|
||||
// Bail out if something went wrong retrieving rows from the database
|
||||
if (!parent::is_mysqli_result($resp)) {
|
||||
return $this->resp_database_error();
|
||||
}
|
||||
|
||||
return $resp->num_rows === 1
|
||||
? new Response($resp->fetch_assoc())
|
||||
: new Response("No entity with id '{$id}' was found", 404);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
// Return details about a specific item by id
|
||||
if (!empty($_GET["id"])) {
|
||||
return $this->resp_item_details($_GET["id"]);
|
||||
}
|
||||
|
||||
$resp = $this->db->for(WorkModel::TABLE)
|
||||
->where([WorkModel::IS_LISTABLE->value => true])
|
||||
->order([WorkModel::DATE_TIMESTAMP_CREATED->value => "DESC"])
|
||||
->select([
|
||||
WorkModel::ID->value,
|
||||
WorkModel::TITLE->value,
|
||||
WorkModel::SUMMARY->value,
|
||||
WorkModel::COVER_SRCSET->value,
|
||||
WorkModel::DATE_YEAR->value,
|
||||
WorkModel::DATE_MONTH->value,
|
||||
WorkModel::DATE_DAY->value,
|
||||
WorkModel::DATE_TIMESTAMP_MODIFIED->value,
|
||||
WorkModel::DATE_TIMESTAMP_CREATED->value
|
||||
]);
|
||||
|
||||
// Bail out if something went wrong retrieving rows from the database
|
||||
if (!parent::is_mysqli_result($resp)) {
|
||||
return $this->resp_database_error();
|
||||
}
|
||||
|
||||
// Resolve foreign keys
|
||||
$rows = [];
|
||||
while ($row = $resp->fetch_assoc()) {
|
||||
$row["tags"] = $this->fetch_row_tags($row["id"]);
|
||||
|
||||
// Fetch actions for work entity by id from endpoint
|
||||
$row["actions"] = (new Call(Endpoints::WORK_ACTIONS->value))
|
||||
->params([WorkActionsModel::ANCHOR->value => $row[WorkModel::ID->value]])
|
||||
->get()->output();
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
return new Response($rows);
|
||||
}
|
||||
}
|
201
api/endpoints/work/PATCH.php
Executable file
|
@ -0,0 +1,201 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use Reflect\Method;
|
||||
use function Reflect\Call;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkModel;
|
||||
use VLW\API\Databases\VLWdb\Models\WorkPermalinks\WorkPermalinksModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/Work.php");
|
||||
require_once Path::root("src/databases/models/WorkPermalinks.php");
|
||||
|
||||
class PATCH_Work extends VLWdb {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
protected Response $current_entity;
|
||||
protected array $updated_entity;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(WorkModel::ID->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules(WorkModel::TITLE->value))
|
||||
->type(Type::STRING)
|
||||
->min(3)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkModel::SUMMARY->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_TEXT_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkModel::IS_LISTABLE->value))
|
||||
->type(Type::BOOLEAN),
|
||||
|
||||
(new Rules(WorkModel::IS_READABLE->value))
|
||||
->type(Type::BOOLEAN),
|
||||
|
||||
(new Rules(WorkModel::DATE_TIMESTAMP_CREATED->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(0)
|
||||
->max(parent::MYSQL_INT_MAX_LENGHT)
|
||||
]);
|
||||
|
||||
$this->get_existing_entity();
|
||||
|
||||
// Copy all provided post data into a new array
|
||||
$this->updated_entity = $_POST;
|
||||
|
||||
// Set date modified timestamp
|
||||
$this->updated_entity[WorkModel::DATE_TIMESTAMP_MODIFIED->value] = time();
|
||||
}
|
||||
|
||||
// Generate a slug URL from string
|
||||
private static function gen_slug(string $input): string {
|
||||
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $input)));
|
||||
}
|
||||
|
||||
// # Helper methods
|
||||
|
||||
private function get_existing_entity(): Response {
|
||||
// Check if an entity already exists with slugified title from GET endpoint
|
||||
$this->current_entity = Call("work?id={$_GET["id"]}", Method::GET);
|
||||
|
||||
// Response is not 404 (Not found) so we can't create the entity
|
||||
if ($this->current_entity->code !== 200) {
|
||||
// Response is not a valid entity, something went wrong
|
||||
if ($this->current_entity->code !== 404) {
|
||||
return $this->resp_database_error();
|
||||
}
|
||||
|
||||
// Return 402 Conflict
|
||||
return new Response("No entity with id '{$_GET["id"]}' was found", 404);
|
||||
}
|
||||
|
||||
return $this->current_entity;
|
||||
}
|
||||
|
||||
// Create new permalink for entity slug
|
||||
private function create_permalink(string $slug): bool {
|
||||
$create = Call("work/permalinks", Method::POST, [
|
||||
WorkPermalinksModel::SLUG->value => $slug,
|
||||
WorkPermalinksModel::ANCHOR->value => $slug
|
||||
]);
|
||||
|
||||
return $create->ok;
|
||||
}
|
||||
|
||||
// ## Updated entity
|
||||
|
||||
private function change_slug(): bool {
|
||||
if (!array_key_exists(WorkModel::ID->value, $this->updated_entity)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Generate new permalink for entity id
|
||||
return $this->create_permalink($this->updated_entity[WorkModel::ID->value]);
|
||||
}
|
||||
|
||||
private function timestamp_to_dates(): void {
|
||||
if (!array_key_exists(WorkModel::DATE_TIMESTAMP_CREATED->value, $this->updated_entity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get timestamp from post data
|
||||
$timestamp = $this->updated_entity[WorkModel::DATE_TIMESTAMP_CREATED->value];
|
||||
|
||||
// Update fractured dates from timestamp
|
||||
$this->updated_entity[WorkModel::DATE_YEAR->value] = date("Y", $timestamp);
|
||||
$this->updated_entity[WorkModel::DATE_MONTH ->value] = date("n", $timestamp);
|
||||
$this->updated_entity[WorkModel::DATE_DAY->value] = date("j", $timestamp);
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
// Return a 422 Unprocessable Entity if there is nothing to change
|
||||
private function resp_no_changes(): Response {
|
||||
return new Response("No columns to update", 422);
|
||||
}
|
||||
|
||||
// Rollback changes and return error response
|
||||
private function resp_permalink_error_rollback(): Response {
|
||||
$update = $this->db->for(WorkModel::TABLE)
|
||||
->where([WorkModel::ID->value => $_GET["id"]])
|
||||
->update($this->current_entity->output());
|
||||
|
||||
return $update
|
||||
? new Response("Failed to create new permalink for updated entity. Changes have been rolled back", 500)
|
||||
: new Reponse("Failed to create new permalink for updated entity. Changes failed to rollback, this is bad.", 500);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
// Empty payload, nothing to do
|
||||
if (empty($_POST)) {
|
||||
return $this->resp_no_changes();
|
||||
}
|
||||
|
||||
// Generate new slug for entity if title is updated
|
||||
if (array_key_exists(WorkModel::TITLE->value, $_POST)) {
|
||||
// Generate URL slug from title text or UUID if undefined
|
||||
$slug = self::gen_slug($_POST["title"]);
|
||||
|
||||
// Save generated slug from title if it's different from existing slug
|
||||
if ($slug !== $this->current_entity->output()[WorkModel::ID->value]) {
|
||||
$this->updated_entity[WorkModel::ID->value] = $slug;
|
||||
}
|
||||
}
|
||||
|
||||
// Update fractured dates from timestamp
|
||||
$this->timestamp_to_dates();
|
||||
|
||||
// Attempt to update the entity
|
||||
$update = $this->db->for(WorkModel::TABLE)
|
||||
->where([WorkModel::ID->value => $_GET["id"]])
|
||||
->update($this->updated_entity);
|
||||
|
||||
// Bail out if update failed
|
||||
if (!$update) {
|
||||
return $this->resp_database_error();
|
||||
}
|
||||
|
||||
// Create new slug for entity if title was changed
|
||||
if (!$this->change_slug()) {
|
||||
return $this->resp_permalink_error_rollback();
|
||||
}
|
||||
|
||||
// Return 200 OK and new or existing entity slug as body
|
||||
return new Response($this->current_entity->output()[WorkModel::ID->value]);
|
||||
}
|
||||
}
|
133
api/endpoints/work/POST.php
Executable file
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use Reflect\Method;
|
||||
use function Reflect\Call;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkModel;
|
||||
use VLW\API\Databases\VLWdb\Models\WorkPermalinks\WorkPermalinksModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/Work.php");
|
||||
require_once Path::root("src/databases/models/WorkPermalinks.php");
|
||||
|
||||
class POST_Work extends VLWdb {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules(WorkModel::TITLE->value))
|
||||
->type(Type::STRING)
|
||||
->min(3)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
->default(null),
|
||||
|
||||
(new Rules(WorkModel::SUMMARY->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_TEXT_MAX_LENGTH)
|
||||
->default(null),
|
||||
|
||||
(new Rules(WorkModel::DATE_TIMESTAMP_CREATED->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_INT_MAX_LENGHT)
|
||||
->default(null)
|
||||
]);
|
||||
}
|
||||
|
||||
// Generate a slug URL from string
|
||||
private static function gen_slug(string $input): string {
|
||||
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $input)));
|
||||
}
|
||||
|
||||
// Create permalink for entity slug
|
||||
private function create_permalink(string $slug): bool {
|
||||
$create = Call("work/permalinks", Method::POST, [
|
||||
WorkPermalinksModel::SLUG->value => $slug,
|
||||
WorkPermalinksModel::ANCHOR->value => $slug
|
||||
]);
|
||||
|
||||
return $create->ok;
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
// Generate URL slug from title text or UUID if undefined
|
||||
$slug = !empty($_POST["title"]) ? self::gen_slug($_POST["title"]) : parent::gen_uuid4();
|
||||
|
||||
// Check if an entity already exists with slugified title from GET endpoint
|
||||
$existing_entity = Call("work?id={$slug}", Method::GET);
|
||||
// Response is not 404 (Not found) so we can't create the entity
|
||||
if ($existing_entity->code !== 404) {
|
||||
// Response is not a valid entity, something went wrong
|
||||
if ($existing_entity->code !== 200) {
|
||||
return $this->resp_database_error();
|
||||
}
|
||||
|
||||
// Return 402 Conflict
|
||||
return new Response("Entity with id '{$slug}' already exists", 402);
|
||||
}
|
||||
|
||||
// Get created timestamp from payload or use current time if not specified
|
||||
$created_timestamp = $_POST[WorkModel::DATE_TIMESTAMP_CREATED->value]
|
||||
? $_POST[WorkModel::DATE_TIMESTAMP_CREATED->value]
|
||||
: time();
|
||||
|
||||
// Attempt to create new entity
|
||||
$insert = $this->db->for(WorkModel::TABLE)
|
||||
->insert([
|
||||
WorkModel::ID->value => $slug,
|
||||
WorkModel::TITLE->value => $_POST["title"],
|
||||
WorkModel::SUMMARY->value => $_POST["summary"],
|
||||
WorkModel::IS_LISTABLE->value => true,
|
||||
WorkModel::IS_READABLE->value => true,
|
||||
WorkModel::DATE_YEAR->value => date("Y", $created_timestamp),
|
||||
WorkModel::DATE_MONTH ->value => date("n", $created_timestamp),
|
||||
WorkModel::DATE_DAY->value => date("j", $created_timestamp),
|
||||
WorkModel::DATE_TIMESTAMP_MODIFIED->value => null,
|
||||
WorkModel::DATE_TIMESTAMP_CREATED->value => $created_timestamp,
|
||||
]);
|
||||
|
||||
// Bail out if insert failed
|
||||
if (!$insert) {
|
||||
return $this->resp_database_error();
|
||||
}
|
||||
|
||||
// Create permalink for new entity
|
||||
if (!$this->create_permalink($slug)) {
|
||||
// Rollback created entity if permalink creation failed
|
||||
Call("work", Method::DELETE, [WorkModel::ID->value => $slug]);
|
||||
|
||||
return new Response("Failed to create permalink", 500);
|
||||
}
|
||||
|
||||
// Return 201 Created and entity slug as body
|
||||
return new Response($slug, 201);
|
||||
}
|
||||
}
|
73
api/endpoints/work/actions/DELETE.php
Executable file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use Reflect\Method;
|
||||
use function Reflect\Call;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkActionsModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/WorkActions.php");
|
||||
|
||||
class DELETE_WorkActions extends VLWdb {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules("id"))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
// Ensure the action exists by id
|
||||
$existing_action = $this->db->for(WorkActionsModel::TABLE)
|
||||
->where([
|
||||
WorkActionsModel::ID->value => $_POST["id"]
|
||||
])
|
||||
->select(null);
|
||||
|
||||
// Return idempotent deletion if the action does not exist
|
||||
if ($existing_action->num_rows === 0) {
|
||||
return new Response($_POST["id"]);
|
||||
}
|
||||
|
||||
// Attempt to delete action by id
|
||||
$delete = $this->db->for(WorkActionsModel::TABLE)
|
||||
->delete([
|
||||
WorkActionsModel::ID->value => $_POST["id"]
|
||||
]);
|
||||
|
||||
// Return 201 Created and entity id as body if insert was successful
|
||||
return $delete === true ? new Response($_POST["id"], 201) : $this->resp_database_error();
|
||||
}
|
||||
}
|
67
api/endpoints/work/actions/GET.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkActionsModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/WorkActions.php");
|
||||
|
||||
class GET_WorkActions extends VLWdb {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(WorkActionsModel::ANCHOR->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
$resp = $this->db->for(WorkActionsModel::TABLE)
|
||||
->where([WorkActionsModel::ANCHOR->value => $_GET[WorkActionsModel::ANCHOR->value]])
|
||||
->select([
|
||||
WorkActionsModel::DISPLAY_TEXT->value,
|
||||
WorkActionsModel::HREF->value,
|
||||
WorkActionsModel::CLASS_LIST->value,
|
||||
WorkActionsModel::EXTERNAL->value
|
||||
]);
|
||||
|
||||
// Bail out if something went wrong retrieving rows from the database
|
||||
if (!parent::is_mysqli_result($resp)) {
|
||||
return $this->resp_database_error();
|
||||
}
|
||||
|
||||
return $resp->num_rows > 0
|
||||
? new Response($resp->fetch_all(MYSQLI_ASSOC))
|
||||
: new Response([]);
|
||||
}
|
||||
}
|
102
api/endpoints/work/actions/POST.php
Executable file
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use Reflect\Method;
|
||||
use function Reflect\Call;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkActionsModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/WorkActions.php");
|
||||
|
||||
class POST_WorkActions extends VLWdb {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules("id"))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules(WorkActionsModel::DISPLAY_TEXT->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkActionsModel::HREF->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->type(Type::NULL)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkActionsModel::CLASS_LIST->value))
|
||||
->type(Type::ARRAY)
|
||||
->min(1)
|
||||
->max(4)
|
||||
->default([]),
|
||||
|
||||
(new Rules(WorkActionsModel::EXTERNAL->value))
|
||||
->type(Type::BOOLEAN)
|
||||
->default(false)
|
||||
]);
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
// Ensure an entity with the provided id exists
|
||||
$entity = Call("work?id={$_GET["id"]}", Method::GET);
|
||||
if ($entity->code !== 200) {
|
||||
// Response from endpoint is not 404, something went wrong
|
||||
if ($entity->code !== 404) {
|
||||
return $this->resp_database_error();
|
||||
}
|
||||
|
||||
return new Response("No entity with id '{$_GET["id"]}' was found", 404);
|
||||
}
|
||||
|
||||
// Attempt to create action for entity
|
||||
$insert = $this->db->for(WorkActionsModel::TABLE)
|
||||
->insert([
|
||||
WorkActionsModel::ID->value => parent::gen_uuid4(),
|
||||
WorkActionsModel::ANCHOR->value => $_GET["id"],
|
||||
WorkActionsModel::DISPLAY_TEXT->value => $_POST[WorkActionsModel::DISPLAY_TEXT->value],
|
||||
WorkActionsModel::HREF->value => $_POST[WorkActionsModel::HREF->value],
|
||||
WorkActionsModel::CLASS_LIST->value => implode(",", $_POST[WorkActionsModel::CLASS_LIST->value]),
|
||||
WorkActionsModel::EXTERNAL->value => $_POST[WorkActionsModel::EXTERNAL->value],
|
||||
]);
|
||||
|
||||
// Return 201 Created and entity id as body if insert was successful
|
||||
return $insert === true ? new Response($_GET["id"], 201) : $this->resp_database_error();
|
||||
}
|
||||
}
|
60
api/endpoints/work/permalinks/GET.php
Executable file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\WorkPermalinks\WorkPermalinksModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/WorkPermalinks.php");
|
||||
|
||||
class GET_WorkPermalinks extends VLWdb {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules("id"))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to resolve permalink, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
// Get all anchors that match the requested slug
|
||||
$resolve = $this->db->for(WorkPermalinksModel::TABLE)
|
||||
->where([WorkPermalinksModel::SLUG->value => $_GET["id"]])
|
||||
->select(WorkPermalinksModel::ANCHOR->value);
|
||||
|
||||
// Return array of all matched work table ids. Or empty array if none found
|
||||
return parent::is_mysqli_result($resolve)
|
||||
? new Response(array_column($resolve->fetch_all(MYSQLI_ASSOC), WorkPermalinksModel::ANCHOR->value))
|
||||
: $this->resp_database_error();
|
||||
}
|
||||
}
|
83
api/endpoints/work/permalinks/POST.php
Executable file
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use Reflect\Method;
|
||||
use function Reflect\Call;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\WorkPermalinks\WorkPermalinksModel;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/WorkPermalinks.php");
|
||||
|
||||
class POST_WorkPermalinks extends VLWdb {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules("slug"))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules("anchor"))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to resolve permalink, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
// Check if an entity exists with slug
|
||||
$existing_entity = Call("work?id={$_POST["slug"]}", Method::GET);
|
||||
// Response is not 404 (Not found) so we can't create the entity
|
||||
if ($existing_entity->code !== 200) {
|
||||
// Response is not a valid entity, something went wrong
|
||||
if ($existing_entity->code !== 404) {
|
||||
return $this->resp_database_error();
|
||||
}
|
||||
|
||||
// Return 402 Conflict
|
||||
return new Response("No work entity with id '{$_POST["slug"]}' was found to permalink", 404);
|
||||
}
|
||||
|
||||
// Attempt to create new entity
|
||||
$insert = $this->db->for(WorkPermalinksModel::TABLE)
|
||||
->insert([
|
||||
WorkPermalinksModel::SLUG->value => $_POST["slug"],
|
||||
WorkPermalinksModel::ANCHOR->value => $_POST["anchor"],
|
||||
WorkPermalinksModel::DATE_TIMESTAMP_CREATED->value => time(),
|
||||
]);
|
||||
|
||||
// Return 201 Created and entity slug as body if insert was successful
|
||||
return $insert === true ? new Response($_POST["slug"], 201) : $this->resp_database_error();
|
||||
}
|
||||
}
|
80
api/endpoints/work/tags/DELETE.php
Executable file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use Reflect\Method;
|
||||
use function Reflect\Call;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkTagsModel;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkTagsNameEnum;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/WorkTags.php");
|
||||
|
||||
class DELETE_WorkTags extends VLWdb {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules("id"))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkTagsModel::NAME->value))
|
||||
->required()
|
||||
->type(Type::ENUM, WorkTagsNameEnum::names())
|
||||
]);
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
// Ensure the tag exists for entity id
|
||||
$existing_tag = $this->db->for(WorkTagsModel::TABLE)
|
||||
->where([
|
||||
WorkTagsModel::ANCHOR->value => $_POST["id"],
|
||||
WorkTagsModel::NAME->value => $_POST["name"]
|
||||
])
|
||||
->select(null);
|
||||
|
||||
// Return idempotent deletion if the tag does not exist
|
||||
if ($existing_tag->num_rows === 0) {
|
||||
return new Response($_POST["id"]);
|
||||
}
|
||||
|
||||
// Attempt to delete tag for entity
|
||||
$delete = $this->db->for(WorkTagsModel::TABLE)
|
||||
->delete([
|
||||
WorkTagsModel::ANCHOR->value => $_POST["id"],
|
||||
WorkTagsModel::NAME->value => $_POST["name"]
|
||||
]);
|
||||
|
||||
// Return 201 Created and entity id as body if insert was successful
|
||||
return $delete === true ? new Response($_POST["id"], 201) : $this->resp_database_error();
|
||||
}
|
||||
}
|
93
api/endpoints/work/tags/POST.php
Executable file
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Path;
|
||||
use Reflect\Response;
|
||||
use ReflectRules\Type;
|
||||
use ReflectRules\Rules;
|
||||
use ReflectRules\Ruleset;
|
||||
|
||||
use Reflect\Method;
|
||||
use function Reflect\Call;
|
||||
|
||||
use VLW\API\Databases\VLWdb\VLWdb;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkTagsModel;
|
||||
use VLW\API\Databases\VLWdb\Models\Work\WorkTagsNameEnum;
|
||||
|
||||
require_once Path::root("src/databases/VLWdb.php");
|
||||
require_once Path::root("src/databases/models/WorkTags.php");
|
||||
|
||||
class POST_WorkTags extends VLWdb {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules("id"))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules(WorkTagsModel::NAME->value))
|
||||
->required()
|
||||
->type(Type::ENUM, WorkTagsNameEnum::names())
|
||||
]);
|
||||
}
|
||||
|
||||
// # Responses
|
||||
|
||||
// Return 422 Unprocessable Content error if request validation failed
|
||||
private function resp_rules_invalid(): Response {
|
||||
return new Response($this->ruleset->get_errors(), 422);
|
||||
}
|
||||
|
||||
// Return a 503 Service Unavailable error if something went wrong with the database call
|
||||
private function resp_database_error(): Response {
|
||||
return new Response("Failed to get work data, please try again later", 503);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if request validation failed
|
||||
if (!$this->ruleset->is_valid()) {
|
||||
return $this->resp_rules_invalid();
|
||||
}
|
||||
|
||||
// Ensure an entity with the provided id exists
|
||||
$entity = Call("work?id={$_GET["id"]}", Method::GET);
|
||||
if ($entity->code !== 200) {
|
||||
// Response from endpoint is not 404, something went wrong
|
||||
if ($entity->code !== 404) {
|
||||
return $this->resp_database_error();
|
||||
}
|
||||
|
||||
return new Response("No entity with id '{$_GET["id"]}' was found", 404);
|
||||
}
|
||||
|
||||
// Ensure the tag does not already exist for entity
|
||||
$existing_tag = $this->db->for(WorkTagsModel::TABLE)
|
||||
->where([
|
||||
WorkTagsModel::ANCHOR->value => $_GET["id"],
|
||||
WorkTagsModel::NAME->value => $_POST["name"]
|
||||
])
|
||||
->select(null);
|
||||
|
||||
// Bail out if this tag already exists
|
||||
if ($existing_tag->num_rows !== 0) {
|
||||
return new Response("Tag '{$_POST["name"]}' is already set on entity id '{$_GET["id"]}'", 402);
|
||||
}
|
||||
|
||||
// Attempt to create tag for entity
|
||||
$insert = $this->db->for(WorkTagsModel::TABLE)
|
||||
->insert([
|
||||
WorkTagsModel::ANCHOR->value => $_GET["id"],
|
||||
WorkTagsModel::NAME->value => $_POST["name"]
|
||||
]);
|
||||
|
||||
// Return 201 Created and entity id as body if insert was successful
|
||||
return $insert === true ? new Response($_GET["id"], 201) : $this->resp_database_error();
|
||||
}
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
# Install dependencies
|
||||
composer install --optimize-autoloader
|
52
api/src/databases/VLWdb.php
Executable file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace VLW\API\Databases\VLWdb;
|
||||
|
||||
use libmysqldriver\MySQL;
|
||||
|
||||
class VLWdb {
|
||||
const UUID_LENGTH = 36;
|
||||
|
||||
const MYSQL_TEXT_MAX_LENGTH = 65538;
|
||||
const MYSQL_VARCHAR_MAX_LENGTH = 255;
|
||||
const MYSQL_INT_MAX_LENGHT = 2147483647;
|
||||
|
||||
protected MySQL $db;
|
||||
|
||||
public function __construct() {
|
||||
// Create new MariaDB connection
|
||||
$this->db = new MySQL(
|
||||
$_ENV["vlwdb"]["mariadb_host"],
|
||||
$_ENV["vlwdb"]["mariadb_user"],
|
||||
$_ENV["vlwdb"]["mariadb_pass"],
|
||||
$_ENV["vlwdb"]["mariadb_db"],
|
||||
);
|
||||
}
|
||||
|
||||
// Generate and return UUID4 string
|
||||
public static function gen_uuid4(): string {
|
||||
return sprintf("%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
|
||||
// 32 bits for "time_low"
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||||
|
||||
// 16 bits for "time_mid"
|
||||
mt_rand(0, 0xffff),
|
||||
|
||||
// 16 bits for "time_hi_and_version",
|
||||
// four most significant bits holds version number 4
|
||||
mt_rand(0, 0x0fff) | 0x4000,
|
||||
|
||||
// 16 bits, 8 bits for "clk_seq_hi_res",
|
||||
// 8 bits for "clk_seq_low",
|
||||
// two most significant bits holds zero and one for variant DCE1.1
|
||||
mt_rand(0, 0x3fff) | 0x8000,
|
||||
|
||||
// 48 bits for "node"
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
||||
);
|
||||
}
|
||||
|
||||
public static function is_mysqli_result(\mysqli_result|bool $resp): bool {
|
||||
return $resp instanceof \mysqli_result;
|
||||
}
|
||||
}
|
10
api/src/databases/models/Coffee.php
Executable file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace VLW\API\Databases\VLWdb\Models\Coffee;
|
||||
|
||||
enum CoffeeModel: string {
|
||||
const TABLE = "coffee";
|
||||
|
||||
case ID = "id";
|
||||
case DATE_TIMESTAMP_CREATED = "date_timestamp_created";
|
||||
}
|
24
api/src/databases/models/Media.php
Executable file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace VLW\API\Databases\VLWdb\Models\Media;
|
||||
|
||||
use victorwesterlund\xEnum;
|
||||
|
||||
enum MediaTypeEnum: string {
|
||||
use xEnum;
|
||||
|
||||
case BLOB = "BLOB";
|
||||
case IMAGE = "IMAGE";
|
||||
}
|
||||
|
||||
enum MediaModel: string {
|
||||
const TABLE = "media";
|
||||
|
||||
case ID = "id";
|
||||
case NAME = "name";
|
||||
case TYPE = "type";
|
||||
case MIME = "mime";
|
||||
case EXTENSION = "extension";
|
||||
case SRCSET = "srcset";
|
||||
case DATE_TIMESTAMP_CREATED = "date_timestamp_created";
|
||||
}
|
10
api/src/databases/models/MediaSrcset.php
Executable file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace VLW\API\Databases\VLWdb\Models\MediaSrcset;
|
||||
|
||||
enum MediaSrcsetModel: string {
|
||||
const TABLE = "media_srcset";
|
||||
|
||||
case ID = "id";
|
||||
case ANCHOR_DEFAULT = "anchor_default";
|
||||
}
|
15
api/src/databases/models/Messages.php
Executable file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace VLW\API\Databases\VLWdb\Models\Messages;
|
||||
|
||||
enum MessagesModel: string {
|
||||
const TABLE = "messages";
|
||||
|
||||
case ID = "id";
|
||||
case EMAIL = "email";
|
||||
case MESSAGE = "message";
|
||||
case IS_READ = "is_read";
|
||||
case IS_SPAM = "is_spam";
|
||||
case IS_SAVED = "is_saved";
|
||||
case DATE_TIMESTAMP_CREATED = "date_timestamp_created";
|
||||
}
|
19
api/src/databases/models/Work.php
Executable file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace VLW\API\Databases\VLWdb\Models\Work;
|
||||
|
||||
enum WorkModel: string {
|
||||
const TABLE = "work";
|
||||
|
||||
case ID = "id";
|
||||
case TITLE = "title";
|
||||
case SUMMARY = "summary";
|
||||
case COVER_SRCSET = "cover_srcset";
|
||||
case IS_LISTABLE = "is_listable";
|
||||
case IS_READABLE = "is_readable";
|
||||
case DATE_YEAR = "date_year";
|
||||
case DATE_MONTH = "date_month";
|
||||
case DATE_DAY = "date_day";
|
||||
case DATE_TIMESTAMP_MODIFIED = "date_timestamp_modified";
|
||||
case DATE_TIMESTAMP_CREATED = "date_timestamp_created";
|
||||
}
|
14
api/src/databases/models/WorkActions.php
Executable file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace VLW\API\Databases\VLWdb\Models\Work;
|
||||
|
||||
enum WorkActionsModel: string {
|
||||
const TABLE = "work_actions";
|
||||
|
||||
case ID = "id";
|
||||
case ANCHOR = "anchor";
|
||||
case DISPLAY_TEXT = "display_text";
|
||||
case HREF = "href";
|
||||
case CLASS_LIST = "class_list";
|
||||
case EXTERNAL = "external";
|
||||
}
|
10
api/src/databases/models/WorkMedia.php
Executable file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace VLW\API\Databases\VLWdb\Models\Work;
|
||||
|
||||
enum WorkMediaModel: string {
|
||||
const TABLE = "work_media";
|
||||
|
||||
case ANCHOR = "anchor";
|
||||
case MEDIA = "media";
|
||||
}
|
6
src/Database/Tables/Work/Permalinks.php → api/src/databases/models/WorkPermalinks.php
Normal file → Executable file
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace VLW\Database\Tables\Work;
|
||||
namespace VLW\API\Databases\VLWdb\Models\WorkPermalinks;
|
||||
|
||||
enum PermalinksTable: string {
|
||||
const NAME = "work_permalinks";
|
||||
enum WorkPermalinksModel: string {
|
||||
const TABLE = "work_permalinks";
|
||||
|
||||
case SLUG = "slug";
|
||||
case ANCHOR = "anchor";
|
20
api/src/databases/models/WorkTags.php
Executable file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace VLW\API\Databases\VLWdb\Models\Work;
|
||||
|
||||
use victorwesterlund\xEnum;
|
||||
|
||||
enum WorkTagsNameEnum: string {
|
||||
use xEnum;
|
||||
|
||||
case VLW = "VLW";
|
||||
case RELEASE = "RELEASE";
|
||||
case WEBSITE = "WEBSITE";
|
||||
}
|
||||
|
||||
enum WorkTagsModel: string {
|
||||
const TABLE = "work_tags";
|
||||
|
||||
case ANCHOR = "anchor";
|
||||
case NAME = "name";
|
||||
}
|
17
api/src/packages/Endpoints/composer.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "local/api.endpoints",
|
||||
"description": "Endpoint pathmappings for VLW API",
|
||||
"type": "library",
|
||||
"version": "1.0.0-dev",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Victor Westerlund",
|
||||
"email": "victor@vlw.se"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"VLW\\API\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
11
api/src/packages/Endpoints/src/Endpoints.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace VLW\API;
|
||||
|
||||
enum Endpoints: string {
|
||||
case WORK = "/work";
|
||||
case SEARCH = "/search";
|
||||
case MESSAGES = "/messages";
|
||||
case WORK_TAGS = "/work/tags";
|
||||
case WORK_ACTIONS = "/work/actions";
|
||||
}
|
327
assets/css/document.css
Executable file
|
@ -0,0 +1,327 @@
|
|||
:root {
|
||||
--primer-color-accent: 255, 255, 0;
|
||||
--color-accent: yellow;
|
||||
--hue-accent: 0deg;
|
||||
|
||||
--padding: 20px;
|
||||
--running-size: 80px;
|
||||
}
|
||||
|
||||
/* # Cornerstones */
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
box-sizing: border-box;
|
||||
font-family: "Roboto Mono", sans-serif;
|
||||
color: inherit;
|
||||
font-size: inherit;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
body {
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
grid-template-rows: var(--running-size) 1fr;
|
||||
overscroll-behavior: none;
|
||||
background-color: black;
|
||||
color: white;
|
||||
overflow-x: hidden;
|
||||
min-height: 100svh;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
body.search-dialog-open {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
a {
|
||||
display: contents;
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* # Components */
|
||||
|
||||
:is(h1, h2, h3, p, li) > a {
|
||||
--underline-tickness: 3px;
|
||||
|
||||
display: initial;
|
||||
text-decoration: underline;
|
||||
text-decoration-thickness: var(--underline-tickness);
|
||||
text-underline-offset: var(--underline-tickness);
|
||||
text-decoration-color: var(--color-accent);
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 30px;
|
||||
color: var(--color-accent);
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
/* ## Buttons */
|
||||
|
||||
button {
|
||||
padding: calc(var(--padding) / 2) var(--padding);
|
||||
color: white;
|
||||
border: solid 2px white;
|
||||
border-radius: 6px;
|
||||
background-color: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button.solid {
|
||||
color: black;
|
||||
border-color: var(--color-accent);
|
||||
background-color: var(--color-accent);
|
||||
}
|
||||
|
||||
a > button::after {
|
||||
content: " ➜";
|
||||
}
|
||||
|
||||
a[target="_blank"] > button::after,
|
||||
:is(h1, h2, h3, p, li) > a[target="_blank"]::after {
|
||||
content: " ↑";
|
||||
color: var(--color-accent);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
a > button.solid:not(:hover)::after {
|
||||
color: black;
|
||||
}
|
||||
|
||||
/* ## Header */
|
||||
|
||||
header {
|
||||
--border-style: solid 1px rgba(255, 255, 255, .2);
|
||||
|
||||
position: sticky;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: var(--running-size);
|
||||
border-bottom: var(--border-style);
|
||||
display: grid;
|
||||
align-items: stretch;
|
||||
justify-items: end;
|
||||
grid-template-columns: 1fr var(--running-size);
|
||||
grid-template-rows: var(--running-size);
|
||||
background-color: rgba(0, 0, 0, .8);
|
||||
z-index: 100;
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
backdrop-filter: blur(20px);
|
||||
}
|
||||
|
||||
header nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: var(--padding);
|
||||
}
|
||||
|
||||
header .logo {
|
||||
width: calc(var(--running-size) - 1px);
|
||||
height: calc(var(--running-size) - 1px);
|
||||
display: grid;
|
||||
align-items: center;
|
||||
justify-items: center;
|
||||
border-left: var(--border-style);
|
||||
}
|
||||
|
||||
header .logo path.stroke {
|
||||
fill: var(--color-accent);
|
||||
}
|
||||
|
||||
header searchbox {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ## Main */
|
||||
|
||||
main {
|
||||
transition: 400ms transform;
|
||||
position: relative;
|
||||
padding: calc(var(--padding) * 1.5);
|
||||
width: 100%;
|
||||
max-width: 1000px;
|
||||
}
|
||||
|
||||
main > * {
|
||||
transition: 100ms opacity;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
main.loading > * {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
/* ## Search */
|
||||
|
||||
/* ### Box */
|
||||
|
||||
searchbox {
|
||||
--icon-size: 25px;
|
||||
|
||||
display: grid;
|
||||
width: 100%;
|
||||
border-left: var(--border-style);
|
||||
grid-template-columns: var(--icon-size) 1fr;
|
||||
align-items: center;
|
||||
padding: var(--padding);
|
||||
gap: var(--padding);
|
||||
fill: var(--color-accent);
|
||||
font-size: 13px;
|
||||
color: rgba(255, 255, 255, .5);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
searchbox > svg {
|
||||
width: var(--icon-size);
|
||||
}
|
||||
|
||||
/* ### Dialog */
|
||||
|
||||
body.search-dialog-open main {
|
||||
transform: scale(.94);
|
||||
}
|
||||
|
||||
dialog.search {
|
||||
transition: 200ms height cubic-bezier(.41,0,.34,.99);
|
||||
margin: auto;
|
||||
width: 100%;
|
||||
max-width: 1000px;
|
||||
height: calc(var(--running-size) + (var(--padding) * 5));
|
||||
max-height: 1000px;
|
||||
border-color: transparent;
|
||||
background-color: transparent;
|
||||
overflow: visible;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
dialog.search.active {
|
||||
height: 70vh;
|
||||
}
|
||||
|
||||
dialog.search search {
|
||||
transition: 400ms transform, 200ms opacity;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: grid;
|
||||
grid-template-rows: var(--running-size) 1fr;
|
||||
gap: calc(var(--padding) * 2);
|
||||
transform: scale(1.1);
|
||||
overflow: hidden;
|
||||
background-color: rgba(255, 255, 255, .05);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
backdrop-filter: brightness(.3) blur(20px);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 10px 30px 10px black;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
body.search-dialog-open dialog.search search {
|
||||
transform: scale(1);
|
||||
padding: calc(var(--padding) * 1.5);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
search input {
|
||||
transition: 200ms background-color, 200ms box-shadow, 200ms color;
|
||||
border-radius: 6px;
|
||||
border: none;
|
||||
outline: none;
|
||||
color: black;
|
||||
font-size: 16px;
|
||||
padding: var(--padding) calc(var(--padding) * 1.5);
|
||||
background-color: rgba(255, 255, 255, .05);
|
||||
box-shadow: 0 5px 70px 10px rgba(0, 0, 0, .3);
|
||||
color: white;
|
||||
}
|
||||
|
||||
search input:focus {
|
||||
background-color: rgba(255, 255, 255, .9);
|
||||
box-shadow: 0 10px 30px 10px black;
|
||||
color: black;
|
||||
}
|
||||
|
||||
/* ### Search results */
|
||||
|
||||
dialog.search search search-results {
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
dialog.search search search-results > svg {
|
||||
margin: auto;
|
||||
width: 150px;
|
||||
fill: rgba(255, 255, 255, .05);
|
||||
}
|
||||
|
||||
/* # Feature queries */
|
||||
|
||||
@media (hover: hover) {
|
||||
:is(h1, h2, h3, p, li) > a:hover {
|
||||
text-underline-offset: 1px;
|
||||
text-decoration-thickness: calc(var(--underline-tickness) * 2);
|
||||
color: var(--color-accent);
|
||||
}
|
||||
|
||||
/* # Components */
|
||||
|
||||
button {
|
||||
transition: 200ms background-color, 200ms border-color, 200ms color;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
border-color: rgba(255, 255, 255, .2);
|
||||
background-color: rgba(255, 255, 255, .1);
|
||||
}
|
||||
|
||||
button.solid:hover {
|
||||
color: var(--color-accent);
|
||||
border-color: rgba(var(--primer-color-accent), .2);
|
||||
background-color: rgba(var(--primer-color-accent), .2);
|
||||
box-shadow: 0 -10px 20px 10px rgba(var(--primer-color-accent), .05);
|
||||
}
|
||||
|
||||
/* ## Header */
|
||||
|
||||
header .logo:hover path.solid {
|
||||
fill: var(--color-accent);
|
||||
}
|
||||
|
||||
searchbox {
|
||||
transition: 200ms background-color;
|
||||
}
|
||||
|
||||
searchbox:hover {
|
||||
background-color: rgba(255, 255, 255, .07);
|
||||
}
|
||||
}
|
||||
|
||||
/* # Size queries */
|
||||
|
||||
@media (min-width: 700px) {
|
||||
header {
|
||||
grid-template-columns: 1fr 250px var(--running-size);
|
||||
}
|
||||
|
||||
header nav {
|
||||
justify-self: start;
|
||||
margin: 0 calc(var(--padding) / 2);
|
||||
}
|
||||
|
||||
/* # Menu */
|
||||
|
||||
/* < Move the search box to the header */
|
||||
header searchbox {
|
||||
display: grid;
|
||||
}
|
||||
}
|
16
assets/css/fonts.css
Executable file
|
@ -0,0 +1,16 @@
|
|||
@font-face {
|
||||
font-family: "Roboto Mono";
|
||||
ascent-override: 100%;
|
||||
font-weight: 400;
|
||||
size-adjust: 105%;
|
||||
font-stretch: 97.5% 112.5%;
|
||||
src: local("Roboto Mono Regular"), url("/assets/fonts/roboto-mono-regular.woff2") format("woff2");
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Roboto Mono";
|
||||
ascent-override: 100%;
|
||||
size-adjust: 95%;
|
||||
font-weight: 800;
|
||||
src: local("Roboto Mono Bold"), url("/assets/fonts/roboto-mono-bold.woff2") format("woff2");
|
||||
}
|
90
assets/css/pages/about.css
Executable file
|
@ -0,0 +1,90 @@
|
|||
/* # Overrides */
|
||||
|
||||
:root {
|
||||
--primer-color-accent: 148, 255, 21;
|
||||
--color-accent: rgb(var(--primer-color-accent));
|
||||
}
|
||||
|
||||
main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--padding);
|
||||
}
|
||||
|
||||
/* # Sections */
|
||||
|
||||
/* ## Divider */
|
||||
|
||||
main > hr {
|
||||
border-color: rgba(255, 255, 255, .1);
|
||||
}
|
||||
|
||||
/* ## About */
|
||||
|
||||
section.about {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: calc(var(--padding) / 2);
|
||||
}
|
||||
|
||||
section.about p:first-of-type:first-letter {
|
||||
font-size: 1.8rem;
|
||||
font-weight: bold;
|
||||
margin-right: .1rem;
|
||||
color: var(--color-accent);
|
||||
}
|
||||
|
||||
section.about span.interests {
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
color: var(--color-accent);
|
||||
animation: interests-hue 5s infinite linear;
|
||||
}
|
||||
|
||||
/* ## Version */
|
||||
|
||||
section.version {
|
||||
color: rgba(255, 255, 255, .2);
|
||||
}
|
||||
|
||||
/* # Interests */
|
||||
|
||||
div.interests {
|
||||
transition: 300ms opacity;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-weight: bold;
|
||||
pointer-events: none;
|
||||
font-size: 50px;
|
||||
color: var(--color-accent);
|
||||
overflow: hidden;
|
||||
opacity: 0;
|
||||
z-index: 200;
|
||||
}
|
||||
|
||||
div.interests.active {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
div.interests p {
|
||||
--text-shadow-blur: 30px;
|
||||
|
||||
transition: 300ms transform;
|
||||
position: absolute;
|
||||
text-shadow:
|
||||
0 0 var(--text-shadow-blur) black,
|
||||
0 0 var(--text-shadow-blur) black,
|
||||
0 0 var(--text-shadow-blur) black,
|
||||
0 0 var(--text-shadow-blur) black,
|
||||
0 0 var(--text-shadow-blur) black;
|
||||
}
|
||||
|
||||
@keyframes interests-hue {
|
||||
to {
|
||||
-webkit-filter: hue-rotate(360deg);
|
||||
filter: hue-rotate(360deg);
|
||||
}
|
||||
}
|
38
public/assets/css/pages/contact.css → assets/css/pages/contact.css
Normal file → Executable file
|
@ -5,33 +5,19 @@
|
|||
--color-accent: rgb(var(--primer-color-accent));
|
||||
}
|
||||
|
||||
vv-shell {
|
||||
main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: var(--padding);
|
||||
}
|
||||
|
||||
.fingerprint {
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* # Sections */
|
||||
|
||||
vv-shell > svg {
|
||||
main > svg {
|
||||
margin: var(--padding) 0;
|
||||
}
|
||||
|
||||
/* ## Modifiers */
|
||||
|
||||
section.center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
section.fade {
|
||||
opacity: .3;
|
||||
}
|
||||
|
||||
/* ## Social */
|
||||
|
||||
section.social {
|
||||
|
@ -71,18 +57,15 @@ section.social social:hover {
|
|||
fill: var(--color-accent);
|
||||
}
|
||||
|
||||
section.social social p.hovering {
|
||||
section.social social.hovering p {
|
||||
display: initial;
|
||||
}
|
||||
|
||||
/* ## PGP key */
|
||||
/* ## OpenPGP key */
|
||||
|
||||
section.pgp {
|
||||
max-width: 800px;
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--padding);
|
||||
text-align: center;
|
||||
background-color: rgba(var(--primer-color-accent), .15);
|
||||
padding: calc(var(--padding) * 1.5);
|
||||
|
@ -98,20 +81,16 @@ section.pgp > svg {
|
|||
}
|
||||
|
||||
section.pgp > p {
|
||||
padding: 0 var(--padding);
|
||||
margin-bottom: var(--padding);
|
||||
padding: var(--padding);
|
||||
}
|
||||
|
||||
section.pgp .buttons {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-top: var(--padding);
|
||||
gap: var(--padding);
|
||||
}
|
||||
|
||||
section.pgp .buttons .download svg.chevron {
|
||||
transform: unset;
|
||||
}
|
||||
|
||||
/* ## Contact form */
|
||||
|
||||
section.form :is(input, textarea) {
|
||||
|
@ -179,7 +158,6 @@ section.form-message h3 {
|
|||
}
|
||||
|
||||
section.form-message pre {
|
||||
white-space: pre-wrap;
|
||||
padding: var(--padding);
|
||||
background-color: rgba(0, 0, 0, .15);
|
||||
}
|
||||
|
@ -193,10 +171,6 @@ section.form-message.sent {
|
|||
background-color: var(--color-accent);
|
||||
}
|
||||
|
||||
section.form-message.sent + section.form {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* # Size queries */
|
||||
|
||||
@media (min-width: 460px) {
|
2
public/assets/css/pages/error.css → assets/css/pages/error.css
Normal file → Executable file
|
@ -6,7 +6,7 @@ header {
|
|||
backdrop-filter: unset;
|
||||
}
|
||||
|
||||
vv-shell {
|
||||
main {
|
||||
max-width: unset;
|
||||
display: grid;
|
||||
justify-items: center;
|
32
public/assets/css/pages/index.css → assets/css/pages/index.css
Normal file → Executable file
|
@ -1,21 +1,15 @@
|
|||
/* # Overrides */
|
||||
|
||||
body[vv-top-page="/"]::before {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
/* # vv-shell styles */
|
||||
/* # Main styles */
|
||||
|
||||
/* ## Picture */
|
||||
|
||||
vv-shell {
|
||||
main {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-direction: column-reverse;
|
||||
}
|
||||
|
||||
vv-shell img {
|
||||
main img {
|
||||
margin: auto;
|
||||
width: 25vh;
|
||||
pointer-events: none;
|
||||
|
@ -152,33 +146,25 @@ splash::after {
|
|||
|
||||
.menu menu li:hover {
|
||||
opacity: 1;
|
||||
font-weight: 100;
|
||||
text-shadow: 0 0 10px rgba(var(--primer-color-accent), .4);
|
||||
}
|
||||
|
||||
button.email:hover {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
/* enable font-weight hover animation */
|
||||
@media not (prefers-reduced-motion: reduce) {
|
||||
.menu menu li {
|
||||
transition: 200ms opacity, 200ms color, 300ms font-weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* # Size quries */
|
||||
|
||||
@media (min-width: 900px) {
|
||||
vv-shell {
|
||||
main {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
justify-items: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
vv-shell img {
|
||||
main img {
|
||||
width: 35vh;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: transparent;
|
||||
}
|
||||
}
|
28
public/assets/css/pages/search.css → assets/css/pages/search.css
Normal file → Executable file
|
@ -12,7 +12,7 @@
|
|||
|
||||
section.search {
|
||||
width: 100%;
|
||||
display: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: var(--padding);
|
||||
|
@ -21,10 +21,6 @@ section.search {
|
|||
margin-bottom: calc(var(--padding) * 2);
|
||||
}
|
||||
|
||||
vv-shell[vv-page="/search"] > section.search {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
section.search form {
|
||||
display: contents;
|
||||
}
|
||||
|
@ -35,11 +31,6 @@ section.search search {
|
|||
|
||||
section.search input {
|
||||
width: 100%;
|
||||
border: none;
|
||||
color: black;
|
||||
outline: none;
|
||||
padding: var(--padding);
|
||||
background-color: var(--color-accent);
|
||||
}
|
||||
|
||||
section.search button[type="submit"] {
|
||||
|
@ -51,6 +42,10 @@ section.search > svg {
|
|||
width: 100%;
|
||||
}
|
||||
|
||||
body:not([vv-page="/search"]) section.search {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* # Search results */
|
||||
|
||||
section.results .result {
|
||||
|
@ -59,6 +54,19 @@ section.results .result {
|
|||
gap: calc(var(--padding) / 2);
|
||||
}
|
||||
|
||||
/* ---- */
|
||||
|
||||
main > svg,
|
||||
dialog.search search search-results > svg {
|
||||
margin: auto;
|
||||
width: 150px;
|
||||
fill: rgba(255, 255, 255, .05);
|
||||
}
|
||||
|
||||
dialog.search search search-results .empty {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* ## Titles */
|
||||
|
||||
section.title a h2 {
|
43
public/assets/css/pages/work/timeline.css → assets/css/pages/work.css
Normal file → Executable file
|
@ -5,7 +5,7 @@
|
|||
--color-accent: rgb(var(--primer-color-accent));
|
||||
}
|
||||
|
||||
vv-shell {
|
||||
main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--padding);
|
||||
|
@ -28,7 +28,6 @@ section.git {
|
|||
}
|
||||
|
||||
section.git svg {
|
||||
fill: white;
|
||||
width: 60px;
|
||||
}
|
||||
|
||||
|
@ -123,6 +122,12 @@ section.timeline .items .item .actions {
|
|||
margin-top: 7px;
|
||||
}
|
||||
|
||||
/* ## Note */
|
||||
|
||||
section.note {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* # Size queries */
|
||||
|
||||
@media (min-width: 460px) {
|
||||
|
@ -131,6 +136,23 @@ section.timeline .items .item .actions {
|
|||
}
|
||||
}
|
||||
|
||||
@media (min-width: 900px) {
|
||||
section.git {
|
||||
display: grid;
|
||||
grid-template-columns: 70px 1fr 400px;
|
||||
align-items: center;
|
||||
gap: calc(var(--padding) * 1.5);
|
||||
}
|
||||
|
||||
section.git svg {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
section.git .buttons {
|
||||
justify-content: end;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 500px) {
|
||||
section.timeline {
|
||||
padding: unset;
|
||||
|
@ -168,21 +190,4 @@ section.timeline .items .item .actions {
|
|||
section.timeline .year:first-of-type .month:first-of-type .day:first-of-type .items .item:first-of-type {
|
||||
margin-top: var(--padding);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 900px) {
|
||||
section.git {
|
||||
display: grid;
|
||||
grid-template-columns: 70px 1fr 400px;
|
||||
align-items: center;
|
||||
gap: calc(var(--padding) * 1.5);
|
||||
}
|
||||
|
||||
section.git svg {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
section.git .buttons {
|
||||
justify-content: end;
|
||||
}
|
||||
}
|
BIN
assets/fonts/roboto-mono-bold.woff2
Executable file
BIN
assets/fonts/roboto-mono-regular.woff2
Executable file
72
assets/js/document.js
Executable file
|
@ -0,0 +1,72 @@
|
|||
new vv.Interactions("document");
|
||||
|
||||
const mainElement = document.querySelector(vv._env.MAIN);
|
||||
|
||||
// Crossfade pages on navigation
|
||||
// Or maybe I shouldn't... hmmm
|
||||
mainElement.addEventListener(vv.Navigation.events.LOADING, () => {
|
||||
mainElement.classList.add("loading");
|
||||
|
||||
// Clean up modified transform-origin if set after search dialog animation
|
||||
mainElement.style.removeProperty("transform-origin");
|
||||
});
|
||||
|
||||
mainElement.addEventListener(vv.Navigation.events.LOADED, () => {
|
||||
[...document.querySelectorAll("dialog")].forEach(element => element.close())
|
||||
|
||||
// Wait 200ms for the page fade-in animation to finish
|
||||
setTimeout(() => mainElement.classList.remove("loading"), 200);
|
||||
});
|
||||
|
||||
// Search dialog open/close logic
|
||||
{
|
||||
const CLASNAME_DIALOG_OPEN = "search-dialog-open";
|
||||
// Offset in pixels from scroll position when scaling the main element
|
||||
const TRANSFORM_ORIGIN_Y_PADDING = 350;
|
||||
|
||||
const dialog = document.querySelector("dialog.search");
|
||||
|
||||
// "Polyfill" for HTMLDialogELement open and close events
|
||||
(new MutationObserver((mutations) => {
|
||||
// There is only one search dialog elemenet
|
||||
const target = mutations[0].target;
|
||||
|
||||
// Set or unset dialog open class on body depending on dialog visibility
|
||||
target.hasAttribute("open")
|
||||
? target.dispatchEvent(new Event("open"))
|
||||
: target.dispatchEvent(new Event("close"));
|
||||
|
||||
}).observe(dialog, { attributes: true }));
|
||||
|
||||
dialog.addEventListener("open", () => {
|
||||
// Scale main element from the current scroll position
|
||||
mainElement.style.setProperty("transform-origin", `50% calc(${window.scrollY}px + ${TRANSFORM_ORIGIN_Y_PADDING}px)`);
|
||||
|
||||
document.body.classList.add(CLASNAME_DIALOG_OPEN);
|
||||
});
|
||||
dialog.addEventListener("close", () => document.body.classList.remove(CLASNAME_DIALOG_OPEN));
|
||||
|
||||
// Close search dialog if dialog is clicked outside inner content
|
||||
dialog.addEventListener("click", (event) => event.target === dialog ? dialog.close() : null);
|
||||
|
||||
// Open search dialog when searchbox is clicked
|
||||
document.querySelector("searchbox").addEventListener("click", () => dialog.showModal());
|
||||
}
|
||||
|
||||
// Search logic
|
||||
{
|
||||
const searchResultsElement = document.querySelector("search-results");
|
||||
const search = (query) => {
|
||||
new vv.Navigation(`/search?q=${query}`, {
|
||||
carrySearchParams: true
|
||||
}).navigate(searchResultsElement);
|
||||
};
|
||||
|
||||
// Run search on keyup
|
||||
document.querySelector("search input").addEventListener("keyup", (event) => search(event.target.value));
|
||||
|
||||
// Trigger expand search box animation
|
||||
document.querySelector("search input").addEventListener("keydown", () => {
|
||||
searchResultsElement.closest("dialog").classList.add("active");
|
||||
}, { once: true });
|
||||
}
|
0
public/assets/js/modules/glitch/Generator.mjs → assets/js/modules/glitch/Generator.mjs
Normal file → Executable file
0
public/assets/js/modules/glitch/Glitch.mjs → assets/js/modules/glitch/Glitch.mjs
Normal file → Executable file
0
public/assets/js/modules/glitch/GlitchWorker.js → assets/js/modules/glitch/GlitchWorker.js
Normal file → Executable file
43
public/assets/js/pages/about.js → assets/js/pages/about.js
Normal file → Executable file
|
@ -1,4 +1,4 @@
|
|||
import { Hoverpop } from "/assets/js/modules/Hoverpop.mjs";
|
||||
new vv.Interactions("about");
|
||||
|
||||
const randomIntFromInterval = (min, max) => {
|
||||
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||
|
@ -6,35 +6,26 @@ const randomIntFromInterval = (min, max) => {
|
|||
|
||||
// Interest explosion effect from origin position
|
||||
const explodeInterests = (originX, originY) => {
|
||||
// Elements can not translate more than negative- and positive from this number
|
||||
const TRANS_LIMIT = 300;
|
||||
|
||||
const wrapper = document.querySelector("div.interests");
|
||||
wrapper.classList.add("active");
|
||||
|
||||
// Elements can not expand further than positive or negative of these values
|
||||
const transLimitX = window.innerWidth / 4;
|
||||
const transLimitY = window.innerHeight / 3;
|
||||
|
||||
[...wrapper.querySelectorAll("p")].forEach(element => {
|
||||
const size = element.getBoundingClientRect();
|
||||
|
||||
// Generate random HUE wheel rotation degrees
|
||||
/*
|
||||
Generate random visuals for current element
|
||||
*/
|
||||
const hue = randomIntFromInterval(0, 360);
|
||||
// Generate random element transform rotation
|
||||
const rotate = randomIntFromInterval(-5, 5);
|
||||
|
||||
// Generate random offsets in each direction clamped to translation limit
|
||||
let transX = randomIntFromInterval(transLimitX * -1, transLimitX);
|
||||
let transY = randomIntFromInterval(transLimitY * -1, transLimitY);
|
||||
|
||||
// Clamp translation to screen left and right X size
|
||||
transX = Math.max(0 - originX, Math.min((window.innerWidth - originX) - size.width, transX));
|
||||
// Clamp translation to top and bottom Y size
|
||||
transY = Math.max(0 - originY, Math.min((window.innerHeight - originY) - size.height, transY));
|
||||
const transX = randomIntFromInterval(TRANS_LIMIT * -1, TRANS_LIMIT);
|
||||
const transY = randomIntFromInterval(TRANS_LIMIT * -1, TRANS_LIMIT);
|
||||
|
||||
// Set initial position
|
||||
element.style.setProperty("top", `${originY}px`);
|
||||
element.style.setProperty("left", `${originX}px`);
|
||||
|
||||
// Set HUE rotation
|
||||
// Set random HUE rotation
|
||||
element.style.setProperty("-webkit-filter", `hue-rotate(${hue}deg)`);
|
||||
element.style.setProperty("filter", `hue-rotate(${hue}deg)`);
|
||||
|
||||
|
@ -48,8 +39,10 @@ const implodeInterests = () => {
|
|||
const wrapper = document.querySelector("div.interests");
|
||||
wrapper.classList.remove("active");
|
||||
|
||||
// Reset to initial position
|
||||
[...wrapper.querySelectorAll("p")].forEach(element => element.style.setProperty("transform", "translate(0, 0)"));
|
||||
[...wrapper.querySelectorAll("p")].forEach(element => {
|
||||
// Reset to initial position
|
||||
element.style.setProperty("transform", "translate(0, 0)");
|
||||
});
|
||||
};
|
||||
|
||||
// Bind triggers for interests explosion and implotion
|
||||
|
@ -62,11 +55,11 @@ const implodeInterests = () => {
|
|||
// Get absolute position of the trigger element
|
||||
const size = interestsElement.getBoundingClientRect();
|
||||
|
||||
explodeInterests(size.x, size.y);
|
||||
const x = size.x - 80;
|
||||
const y = size.y - 10;
|
||||
|
||||
explodeInterests(x, y);
|
||||
});
|
||||
|
||||
interestsElement.addEventListener(canHover ? "mouseleave" : "touchend", () => implodeInterests());
|
||||
}
|
||||
|
||||
// Languages stacking bar chart hoverpop
|
||||
new Hoverpop(document.querySelectorAll("stacked-bar-chart chart-segment"));
|
29
public/assets/js/pages/contact.js → assets/js/pages/contact.js
Normal file → Executable file
|
@ -1,5 +1,3 @@
|
|||
import { Hoverpop } from "/assets/js/modules/Hoverpop.mjs";
|
||||
|
||||
class ContactForm {
|
||||
static STORAGE_KEY = "contact_form_message";
|
||||
|
||||
|
@ -12,6 +10,8 @@ class ContactForm {
|
|||
[...document.querySelectorAll("form :is(input, textarea)")].forEach(element => {
|
||||
element.addEventListener("keyup", () => this.saveMessage());
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Get saved message as JSON from SessionStorage
|
||||
|
@ -36,7 +36,6 @@ class ContactForm {
|
|||
return ContactForm.removeSavedMessage();
|
||||
}
|
||||
|
||||
// Set value of each input field in DOM by name attribute
|
||||
for (const [name, value] of Object.entries(message)) {
|
||||
this.form.querySelector(`[name="${name}"]`).value = value;
|
||||
}
|
||||
|
@ -62,7 +61,27 @@ class ContactForm {
|
|||
form ? (new ContactForm(form)) : ContactForm.removeSavedMessage();
|
||||
}
|
||||
|
||||
// Social links hoverpop
|
||||
// Social links hover
|
||||
{
|
||||
new Hoverpop(document.querySelectorAll("social"));
|
||||
const socialElementHover = (target) => {
|
||||
const element = target.querySelector("p");
|
||||
|
||||
target.classList.add("hovering");
|
||||
target.addEventListener("mousemove", (event) => {
|
||||
const x = event.layerX - (element.clientWidth / 2);
|
||||
const y = event.layerY + element.clientHeight;
|
||||
|
||||
element.style.setProperty("transform", `translate(${x}px, ${y}px)`);
|
||||
});
|
||||
};
|
||||
|
||||
const elements = [...document.querySelectorAll("social")];
|
||||
|
||||
elements.forEach(element => {
|
||||
element.addEventListener("mouseenter", () => socialElementHover(element));
|
||||
|
||||
element.addEventListener("mouseleave", () => {
|
||||
elements.forEach(element => element.classList.remove("hovering"));
|
||||
});
|
||||
});
|
||||
}
|
0
public/assets/js/pages/error.js → assets/js/pages/error.js
Normal file → Executable file
108
assets/js/pages/index.js
Executable file
|
@ -0,0 +1,108 @@
|
|||
const EMAIL_CPY_ANIM_DUR_MSECONDS = 1000;
|
||||
|
||||
// Run email copied splash animation
|
||||
const emailCopiedAnimation = () => {
|
||||
const CONFETTI_COUNT = 40;
|
||||
const CONFETTI_SCALE_PIXELS = 300;
|
||||
|
||||
const randomIntFromInterval = (min, max) => {
|
||||
return Math.floor(Math.random() * (max - min + 1) + min)
|
||||
}
|
||||
|
||||
// Create new splash element
|
||||
const splashElement = document.createElement("splash");
|
||||
splashElement.innerText = "copied!";
|
||||
|
||||
// Set inline display to none to hide this element on pages where the splash element has no override styles defined.
|
||||
splashElement.style.display = "none";
|
||||
|
||||
// Array of box-shadow strings as "confetti"
|
||||
const confetti = [];
|
||||
|
||||
// Generate random confetti
|
||||
for (let i = 0; i < CONFETTI_COUNT; i++) {
|
||||
// Random confetti position
|
||||
const x = randomIntFromInterval(CONFETTI_SCALE_PIXELS * -1, CONFETTI_SCALE_PIXELS);
|
||||
const y = randomIntFromInterval(CONFETTI_SCALE_PIXELS * -1, CONFETTI_SCALE_PIXELS);
|
||||
|
||||
// Random confetti RGB color
|
||||
const rgb = [
|
||||
randomIntFromInterval(0, 255),
|
||||
randomIntFromInterval(0, 255),
|
||||
randomIntFromInterval(0, 255)
|
||||
];
|
||||
|
||||
// Interpolate random values and append to outer confetti array
|
||||
confetti.push(`${x}px ${y}px 0 rgb(${rgb.join(",")})`);
|
||||
}
|
||||
|
||||
// Set CSS variable on splash element that in turn will be used by pseudo-element
|
||||
splashElement.style.setProperty("--confetti", confetti.join(","));
|
||||
|
||||
// Start animation by appending the created element to the document body
|
||||
document.body.appendChild(splashElement);
|
||||
|
||||
// Run hide animation
|
||||
setTimeout(() => {
|
||||
splashElement.classList.add("hide");
|
||||
|
||||
// Selfdestruct element when hide animation finishes
|
||||
setTimeout(() => splashElement.remove(), 400);
|
||||
}, EMAIL_CPY_ANIM_DUR_MSECONDS + 100);
|
||||
}
|
||||
|
||||
new vv.Interactions("index", {
|
||||
// Copy email address to clipboard
|
||||
copyEmail: async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText("victor@vlw.se");
|
||||
|
||||
// Run "email copied" animation!
|
||||
emailCopiedAnimation();
|
||||
|
||||
// NOTE: I don't know, spamming the button is kinda fun
|
||||
// Prevent interactions with the copy email elements while the animation is running
|
||||
/*[...document.querySelectorAll("[vv-call='copyEmail']")].forEach(element => {
|
||||
//element.classList.add("lock");
|
||||
|
||||
setTimeout(() => element.classList.remove("lock"), EMAIL_CPY_ANIM_DUR_MSECONDS);
|
||||
});*/
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
},
|
||||
// Open the fullscreen menu
|
||||
openMenu: () => document.querySelector("menu").classList.add("active"),
|
||||
// Close the fullscreen menu
|
||||
closeMenu: () => document.querySelector("menu").classList.remove("active")
|
||||
});
|
||||
|
||||
// Change site accent color on hover of menu items
|
||||
if (window.matchMedia("(hover: hover)")) {
|
||||
// Update root CSS variables
|
||||
const updateColor = (rgb = null, hue = 0) => {
|
||||
if (!rgb) {
|
||||
document.documentElement.style.removeProperty("--hue-accent");
|
||||
document.documentElement.style.removeProperty("--primer-color-accent");
|
||||
document.documentElement.style.removeProperty("--color-accent");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
document.documentElement.style.setProperty("--hue-accent", `${hue}deg`);
|
||||
|
||||
document.documentElement.style.setProperty("--primer-color-accent", `${rgb}`);
|
||||
// Compiled color variable must to be updated to receive the new RGB values
|
||||
document.documentElement.style.setProperty("--color-accent", "rgb(var(--primer-color-accent)");
|
||||
};
|
||||
|
||||
[...document.querySelectorAll("menu li")].forEach(element => {
|
||||
// Change site accent color to RGB and HUE rotation defined in element dataset
|
||||
element.addEventListener("mouseenter", (event) => updateColor(event.target.dataset.rgb, event.target.dataset.hue));
|
||||
// Reset initial accent color and hues
|
||||
element.addEventListener("mouseleave", () => updateColor());
|
||||
});
|
||||
|
||||
// Reset color on navigation
|
||||
document.querySelector(vv._env.MAIN).addEventListener(vv.Navigation.events.LOADED, () => updateColor(), { once: true });
|
||||
}
|
25
assets/js/pages/search.js
Executable file
|
@ -0,0 +1,25 @@
|
|||
// Don't open the search dialog overlay if search page is open stand-alone
|
||||
{
|
||||
const searchBox = document.querySelector("body:not(.search-dialog-open) searchbox");
|
||||
|
||||
// Page is stand-alone
|
||||
if (searchBox) {
|
||||
// Shift focus to the on-page search box instead of opening search dialog on click
|
||||
const shiftSearchboxFocus = () => {
|
||||
// Override normal "open search dialog" behavior
|
||||
document.querySelector("dialog.search").close();
|
||||
|
||||
// Shift focus to the on-page search input instead
|
||||
}
|
||||
|
||||
// Bind event listener to searchbox element
|
||||
document.querySelector("body:not(.search-dialog-open) searchbox").addEventListener("click", shiftSearchboxFocus, true);
|
||||
|
||||
// Remove event listener from searchbox element on page navigation
|
||||
mainElement.addEventListener(vv.Navigation.events.LOADING, () => {
|
||||
searchBox.removeEventListener("click", shiftSearchboxFocus);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
new vv.Interactions("search");
|
1
assets/js/pages/work.js
Executable file
|
@ -0,0 +1 @@
|
|||
new vv.Interactions("work");
|
0
public/assets/media/gazing.jpg → assets/media/gazing.jpg
Normal file → Executable file
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
0
public/assets/media/glitch_b64/1.txt → assets/media/glitch_b64/1.txt
Normal file → Executable file
0
public/assets/media/glitch_b64/2.txt → assets/media/glitch_b64/2.txt
Normal file → Executable file
0
public/assets/media/glitch_b64/3.txt → assets/media/glitch_b64/3.txt
Normal file → Executable file
0
public/assets/media/glitch_b64/4.txt → assets/media/glitch_b64/4.txt
Normal file → Executable file
0
public/assets/media/icons/close.svg → assets/media/icons/close.svg
Normal file → Executable file
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
0
public/assets/media/icons/email.svg → assets/media/icons/email.svg
Normal file → Executable file
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
1
assets/media/icons/github.svg
Executable file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 98 98"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" fill="#fff"/></svg>
|
After Width: | Height: | Size: 957 B |
0
public/assets/media/icons/libera.svg → assets/media/icons/libera.svg
Normal file → Executable file
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
1
assets/media/icons/mastodon.svg
Executable file
After Width: | Height: | Size: 6.8 KiB |
0
public/assets/media/icons/pin.svg → assets/media/icons/pin.svg
Normal file → Executable file
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
0
public/assets/media/icons/search.svg → assets/media/icons/search.svg
Normal file → Executable file
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
0
public/assets/media/line.svg → assets/media/line.svg
Normal file → Executable file
Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 238 B |
1
assets/media/vw.svg
Executable file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="36" height="22"><g fill="none"><path class="solid" d="M12 22 0 0h24Z"/><path class="stroke" d="M12 17.823 20.63 2H3.37L12 17.823M12 22 0 0h24L12 22Z"/><g opacity=".5"><path class="solid" d="M24 22 12 0h24Z"/><path class="stroke" d="M24 17.823 32.63 2H15.37L24 17.823M24 22 12 0h24L24 22Z"/></g></g></svg>
|
After Width: | Height: | Size: 351 B |
|
@ -1,9 +1,17 @@
|
|||
{
|
||||
"require": {
|
||||
"reflect/client": "dev-master",
|
||||
"reflect/plugin-rules": "dev-master",
|
||||
"vlw/mysql": "dev-master",
|
||||
"vlw/xenum": "dev-master"
|
||||
"local/api.client": "1.0.0-dev",
|
||||
"local/api.endpoints": "1.0.0-dev"
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
"minimum-stability": "dev",
|
||||
"repositories": [
|
||||
{
|
||||
"type": "path",
|
||||
"url": "src/packages/API"
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"url": "api/src/packages/Endpoints"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
149
composer.lock
generated
|
@ -4,11 +4,64 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "cb70f9f3f538a72aa8bcf906fdc906bf",
|
||||
"content-hash": "73a61bf0308871f9dc9ad050aedfe13e",
|
||||
"packages": [
|
||||
{
|
||||
"name": "local/api.client",
|
||||
"version": "1.0.0-dev",
|
||||
"dist": {
|
||||
"type": "path",
|
||||
"url": "src/packages/API",
|
||||
"reference": "020275feb0e0017fa91ae0b33213bc54f35cac75"
|
||||
},
|
||||
"require": {
|
||||
"reflect/client": "^3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"VLW\\API\\": "src/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Victor Westerlund",
|
||||
"email": "victor@vlw.se"
|
||||
}
|
||||
],
|
||||
"description": "Wrapper for vlw.se API",
|
||||
"transport-options": {
|
||||
"relative": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "local/api.endpoints",
|
||||
"version": "1.0.0-dev",
|
||||
"dist": {
|
||||
"type": "path",
|
||||
"url": "api/src/packages/Endpoints",
|
||||
"reference": "89b7b9a4cc504abddb4aeec8e05a95c9d9087575"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"VLW\\API\\": "src/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Victor Westerlund",
|
||||
"email": "victor@vlw.se"
|
||||
}
|
||||
],
|
||||
"description": "Endpoint pathmappings for VLW API",
|
||||
"transport-options": {
|
||||
"relative": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "reflect/client",
|
||||
"version": "dev-master",
|
||||
"version": "3.0.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/VictorWesterlund/reflect-client-php.git",
|
||||
|
@ -20,7 +73,6 @@
|
|||
"reference": "89a8c041044c8c60cefafc4716d5d61b96c43e06",
|
||||
"shasum": ""
|
||||
},
|
||||
"default-branch": true,
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@ -43,103 +95,18 @@
|
|||
"source": "https://github.com/VictorWesterlund/reflect-client-php/tree/3.0.6"
|
||||
},
|
||||
"time": "2024-04-06T14:55:04+00:00"
|
||||
},
|
||||
{
|
||||
"name": "reflect/plugin-rules",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://codeberg.org/reflect/rules-plugin",
|
||||
"reference": "aa7d969350f50d00d7dce01b948276946fcc0e81"
|
||||
},
|
||||
"default-branch": true,
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"ReflectRules\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"GPL-3.0-only"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Victor Westerlund",
|
||||
"email": "victor.vesterlund@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "Add request search paramter and request body constraints to an API built with Reflect",
|
||||
"time": "2024-11-28T17:05:16+00:00"
|
||||
},
|
||||
{
|
||||
"name": "vlw/mysql",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://codeberg.org/vlw/php-mysql",
|
||||
"reference": "64c7bae3cf6124dcb64c9e8ef93425be3602e82a"
|
||||
},
|
||||
"default-branch": true,
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"vlw\\MySQL\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"GPL-3.0-or-later"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Victor Westerlund",
|
||||
"email": "victor@vlw.se"
|
||||
}
|
||||
],
|
||||
"description": "Abstraction library for common MySQL/MariaDB DML operations with php-mysqli",
|
||||
"time": "2025-01-16T13:53:30+00:00"
|
||||
},
|
||||
{
|
||||
"name": "vlw/xenum",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://codeberg.org/vlw/php-xenum",
|
||||
"reference": "1c997a5574656b88a62f5ee160ee5a6439932a2f"
|
||||
},
|
||||
"default-branch": true,
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"vlw\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"GPL-3.0-only"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Victor Westerlund",
|
||||
"email": "victor@vlw.se"
|
||||
}
|
||||
],
|
||||
"description": "PHP eXtended Enums. The missing quality-of-life features from PHP 8+ Enums",
|
||||
"time": "2024-12-02T10:36:32+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "dev",
|
||||
"stability-flags": {
|
||||
"reflect/client": 20,
|
||||
"reflect/plugin-rules": 20,
|
||||
"vlw/mysql": 20
|
||||
"local/api.client": 20,
|
||||
"local/api.endpoints": 20
|
||||
},
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.3.0"
|
||||
"plugin-api-version": "2.0.0"
|
||||
}
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Call;
|
||||
use Reflect\{Response, Path};
|
||||
|
||||
const MSG_OK = "Cache file deleted";
|
||||
const MSG_FAIL = "Cache file does not exist or can't be deleted";
|
||||
|
||||
class DELETE_AboutLanguages {
|
||||
public function __construct() {}
|
||||
|
||||
// Delete languages cache file if it exists
|
||||
public function main(): Response {
|
||||
// Bail out if cache is not used
|
||||
if (empty($_ENV["forgejo_languages"]["cache_file"])) {
|
||||
return new Response(MSG_OK);
|
||||
}
|
||||
|
||||
return unlink($_ENV["forgejo_languages"]["cache_file"]) ? new Response(MSG_OK) : new Response(MSG_FAIL, 404);
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Call;
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\API\Endpoints;
|
||||
|
||||
require_once Path::root("src/Endpoints.php");
|
||||
|
||||
const PARM_FORCE_RECACHE = "force_recache";
|
||||
|
||||
class GET_AboutLanguages {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(PARM_FORCE_RECACHE))
|
||||
->type(Type::BOOLEAN)
|
||||
->default(false)
|
||||
]);
|
||||
|
||||
$this->ruleset->validate_or_exit();
|
||||
}
|
||||
|
||||
private static function cache_exists(): bool {
|
||||
return file_exists($_ENV["forgejo_languages"]["cache_file"]);
|
||||
}
|
||||
|
||||
private static function load_cache(): array {
|
||||
return json_decode(file_get_contents($_ENV["forgejo_languages"]["cache_file"]), true);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Delete cache file if force flag is set
|
||||
if ($_GET[PARM_FORCE_RECACHE]) {
|
||||
(new Call(Endpoints::ABOUT_LANGUAGES->value))->delete();
|
||||
}
|
||||
|
||||
return self::cache_exists()
|
||||
// Return languages from cache
|
||||
? new Response(self::load_cache())
|
||||
// Fetch and return languages (and generate cache file if enabled)
|
||||
: new Response((new Call(Endpoints::ABOUT_LANGUAGES->value))->post());
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Call;
|
||||
use Reflect\{Response, Path};
|
||||
|
||||
const ERRNO_CACHE_FAILED = 0;
|
||||
|
||||
const FORGEJO_ENDPOINT_USER = "/api/v1/users/%s";
|
||||
const FORGEJO_ENDPOINT_SEARCH = "/api/v1/repos/search?uid=%s";
|
||||
|
||||
class POST_AboutLanguages {
|
||||
private array $errors = [];
|
||||
// Tally of all languages used in all configured repositories
|
||||
private array $languages = [];
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
// Fetch JSON from URL
|
||||
private static function fetch_json(string $url): array {
|
||||
return json_decode(file_get_contents($url), true);
|
||||
}
|
||||
|
||||
// Fetch JSON from a Forgejo endpoint
|
||||
private static function fetch_endpoint(string $endpoint): array {
|
||||
$url = $_ENV["forgejo"]["base_url"] . $endpoint;
|
||||
return self::fetch_json($url);
|
||||
}
|
||||
|
||||
// Write $this->languages to a JSON file
|
||||
private function cache_languages(): int|bool {
|
||||
$cache_filename = $_ENV["forgejo_languages"]["cache_file"];
|
||||
|
||||
// Bail out if cache file is not configured
|
||||
if (empty($cache_filename)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return file_put_contents($cache_filename, json_encode($this->languages));
|
||||
}
|
||||
|
||||
// Fetch and add languages to total from a fully-qualified Forgejo URL
|
||||
private function add_repository_languages(string $url): void {
|
||||
foreach(self::fetch_json($url) as $language => $bytes) {
|
||||
// Create key for language if it doesn't exist
|
||||
if (!array_key_exists($language, $this->languages)) {
|
||||
$this->languages[$language] = 0;
|
||||
}
|
||||
|
||||
// Add bytes to language in total
|
||||
$this->languages[$language] += $bytes;
|
||||
}
|
||||
}
|
||||
|
||||
// Tally languages from public repositories for user id
|
||||
private function add_public_repositores(int $uid): bool {
|
||||
$resp = self::fetch_endpoint(sprintf(FORGEJO_ENDPOINT_SEARCH, $uid));
|
||||
|
||||
// Bail out if request failed or if response indicated a problem
|
||||
if (!$resp or $resp["ok"] === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add langauges for each public repository
|
||||
foreach ($resp["data"] as $repo) {
|
||||
$this->add_repository_languages($repo["languages_url"]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Add languages from all public repositories for profiles in config
|
||||
private function add_repositories_from_config_profiles(): void {
|
||||
foreach(explode(",", $_ENV["forgejo_languages"]["scan_profiles"]) as $profile) {
|
||||
// Resolve user data from username
|
||||
$user = self::fetch_endpoint(sprintf(FORGEJO_ENDPOINT_USER, $profile));
|
||||
|
||||
if (!$this->add_public_repositores($user["id"])) {
|
||||
$this->errors[] = $profile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
$this->add_repositories_from_config_profiles();
|
||||
|
||||
// Sort langauges bytes tally by largest in descending order
|
||||
arsort($this->languages);
|
||||
|
||||
// Save languages to cache
|
||||
if (!$this->cache_languages()) {
|
||||
$this->errors[] = ERRNO_CACHE_FAILED;
|
||||
}
|
||||
|
||||
return new Response($this->languages);
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Battlestation\Config\ConfigModel;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Config/Config.php");
|
||||
|
||||
class GET_Battlestation extends Database {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
private array $query;
|
||||
private array $results = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(ConfigModel::REF_MB_ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(parent::UUID_LENGTH)
|
||||
->max(parent::UUID_LENGTH),
|
||||
|
||||
(new Rules(ConfigModel::FRIENDLY_NAME->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
|
||||
parent::__construct(Databases::BATTLESTATION, $this->ruleset);
|
||||
|
||||
// Use a copy of search parameters
|
||||
$this->query = $_GET;
|
||||
}
|
||||
|
||||
private function get_config(): array {
|
||||
return $this->results = $this->db
|
||||
->for(ConfigModel::NAME)
|
||||
->where($this->query)
|
||||
->order([ConfigModel::DATE_BUILT->value => "DESC"])
|
||||
->select(ConfigModel::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Set properties as "searchable"
|
||||
parent::make_wildcard_search(ConfigModel::FRIENDLY_NAME->value, $this->query);
|
||||
|
||||
$this->get_config();
|
||||
|
||||
// Return 404 Not Found if response array is empty
|
||||
return new Response($this->results, $this->results ? 200 : 404);
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Battlestation\ChassisTable;
|
||||
use VLW\Database\Tables\Battlestation\Config\ChassisMbTable;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Chassis.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Config/ChassisMb.php");
|
||||
|
||||
class GET_BattlestationChassis extends Database {
|
||||
private const REL_MOTHERBOARDS = "motherboards";
|
||||
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
private array $query;
|
||||
private array $results = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(ChassisTable::ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(parent::UUID_LENGTH)
|
||||
->max(parent::UUID_LENGTH),
|
||||
|
||||
(new Rules(ChassisTable::VENDOR_NAME->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(ChassisTable::VENDOR_MODEL->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(ChassisTable::STORAGE_TWOINCHFIVE->value))
|
||||
->type(Type::NUMBER)
|
||||
->type(Type::NULL)
|
||||
->min(0)
|
||||
->max(parent::MYSQL_TINYINT_MAX_LENGTH),
|
||||
|
||||
(new Rules(ChassisTable::STORAGE_THREEINCHFIVE->value))
|
||||
->type(Type::NUMBER)
|
||||
->type(Type::NULL)
|
||||
->min(0)
|
||||
->max(parent::MYSQL_TINYINT_MAX_LENGTH),
|
||||
|
||||
(new Rules(ChassisTable::IS_RETIRED->value))
|
||||
->type(Type::BOOLEAN)
|
||||
]);
|
||||
|
||||
parent::__construct(Databases::BATTLESTATION, $this->ruleset);
|
||||
|
||||
// Use a copy of search parameters
|
||||
$this->query = $_GET;
|
||||
}
|
||||
|
||||
private function get_motherboards(): void {
|
||||
foreach ($this->results as &$result) {
|
||||
// Get motherboard id from relationship by chassis id
|
||||
$result[self::REL_MOTHERBOARDS] = $this->db
|
||||
->for(ChassisMbTable::NAME)
|
||||
->where([ChassisMbTable::REF_CHASSIS_ID->value => $result[ChassisTable::ID->value]])
|
||||
->select(ChassisMbTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_chassis(): array {
|
||||
return $this->results = $this->db
|
||||
->for(ChassisTable::NAME)
|
||||
->where($this->query)
|
||||
->order([ChassisTable::DATE_AQUIRED->value => "DESC"])
|
||||
->select(ChassisTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Set properties as "searchable"
|
||||
parent::make_wildcard_search(ChassisTable::VENDOR_NAME->value, $this->query);
|
||||
parent::make_wildcard_search(ChassisTable::VENDOR_MODEL->value, $this->query);
|
||||
|
||||
// Get hardware
|
||||
$this->get_chassis();
|
||||
|
||||
// Resolve hardware relationships
|
||||
$this->get_motherboards();
|
||||
|
||||
// Return 404 Not Found if response array is empty
|
||||
return new Response($this->results, $this->results ? 200 : 404);
|
||||
}
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Battlestation\{
|
||||
CoolerModel
|
||||
};
|
||||
use VLW\Database\Tables\Battlestation\Config\MbCpuCoolerModel;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Coolers.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Config/MbCpuCooler.php");
|
||||
|
||||
class GET_BattlestationCoolers extends Database {
|
||||
private const REL_MOTHERBOARDS = "motherboards";
|
||||
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
private array $query;
|
||||
private array $results = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(CoolerModel::ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(parent::UUID_LENGTH)
|
||||
->max(parent::UUID_LENGTH),
|
||||
|
||||
(new Rules(CoolerModel::TYPE_LIQUID->value))
|
||||
->type(Type::BOOLEAN),
|
||||
|
||||
(new Rules(CoolerModel::SIZE_FAN->value))
|
||||
->type(Type::NULL)
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_INTR_MAX_LENGTH),
|
||||
|
||||
(new Rules(CoolerModel::SIZE_RADIATOR->value))
|
||||
->type(Type::NULL)
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_INTR_MAX_LENGTH),
|
||||
|
||||
(new Rules(CoolerModel::VENDOR_NAME->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(CoolerModel::VENDOR_MODEL->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(CoolerModel::IS_RETIRED->value))
|
||||
->type(Type::BOOLEAN)
|
||||
]);
|
||||
|
||||
parent::__construct(Databases::BATTLESTATION, $this->ruleset);
|
||||
|
||||
// Use a copy of search parameters
|
||||
$this->query = $_GET;
|
||||
}
|
||||
|
||||
private function get_motherboards(): void {
|
||||
foreach ($this->results as &$result) {
|
||||
// Get motherboard id from relationship by chassis id
|
||||
$result[self::REL_MOTHERBOARDS] = $this->db
|
||||
->for(MbCoolerModel::NAME)
|
||||
->where([MbCoolerModel::REF_COOLER_ID->value => $result[CoolerModel::ID->value]])
|
||||
->select(MbCoolerModel::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_coolers(): array {
|
||||
return $this->results = $this->db
|
||||
->for(CoolerModel::NAME)
|
||||
->where($this->query)
|
||||
->order([CoolerModel::DATE_AQUIRED->value => "DESC"])
|
||||
->select(CoolerModel::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Set properties as "searchable"
|
||||
parent::make_wildcard_search(CoolerModel::VENDOR_NAME->value, $this->query);
|
||||
parent::make_wildcard_search(CoolerModel::VENDOR_MODEL->value, $this->query);
|
||||
|
||||
// Get hardware
|
||||
$this->get_coolers();
|
||||
|
||||
// Resolve hardware relationships
|
||||
$this->get_motherboards();
|
||||
|
||||
// Return 404 Not Found if response array is empty
|
||||
return new Response($this->results, $this->results ? 200 : 404);
|
||||
}
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Battlestation\{
|
||||
CpuTable,
|
||||
ClassEnum
|
||||
};
|
||||
use VLW\Database\Tables\Battlestation\Config\MbCpuCoolerModel;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Cpu.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Config/MbCpuCooler.php");
|
||||
|
||||
class GET_BattlestationCpu extends Database {
|
||||
private const REL_MOTHERBOARDS = "motherboards";
|
||||
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
private array $query;
|
||||
private array $results = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(CpuTable::ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(parent::UUID_LENGTH)
|
||||
->max(parent::UUID_LENGTH),
|
||||
|
||||
(new Rules(CpuTable::CLOCK_BASE->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1),
|
||||
|
||||
(new Rules(CpuTable::CLOCK_TURBO->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1),
|
||||
|
||||
(new Rules(CpuTable::CORE_COUNT_PERFORMANCE->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_TINYINT_MAX_LENGTH),
|
||||
|
||||
(new Rules(CpuTable::CORE_COUNT_EFFICIENCY->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_TINYINT_MAX_LENGTH),
|
||||
|
||||
(new Rules(CpuTable::CORE_THREADS->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_TINYINT_MAX_LENGTH),
|
||||
|
||||
(new Rules(CpuTable::VENDOR_NAME->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(CpuTable::VENDOR_MODEL->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(CpuTable::IS_RETIRED->value))
|
||||
->type(Type::BOOLEAN)
|
||||
]);
|
||||
|
||||
parent::__construct(Databases::BATTLESTATION, $this->ruleset);
|
||||
|
||||
// Use a copy of search parameters
|
||||
$this->query = $_GET;
|
||||
}
|
||||
|
||||
private function get_motherboards(): void {
|
||||
foreach ($this->results as &$result) {
|
||||
// Get motherboard id from relationship by chassis id
|
||||
$result[self::REL_MOTHERBOARDS] = $this->db
|
||||
->for(MbCpuCoolerModel::NAME)
|
||||
->where([MbCpuCoolerModel::REF_CPU_ID->value => $result[CpuTable::ID->value]])
|
||||
->select(MbCpuCoolerModel::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_cpu(): array {
|
||||
return $this->results = $this->db
|
||||
->for(CpuTable::NAME)
|
||||
->where($this->query)
|
||||
->order([CpuTable::DATE_AQUIRED->value => "DESC"])
|
||||
->select(CpuTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Set properties as "searchable"
|
||||
parent::make_wildcard_search(CpuTable::VENDOR_NAME->value, $this->query);
|
||||
parent::make_wildcard_search(CpuTable::VENDOR_MODEL->value, $this->query);
|
||||
|
||||
// Get hardware
|
||||
$this->get_cpu();
|
||||
|
||||
// Resolve hardware relationships
|
||||
$this->get_motherboards();
|
||||
|
||||
// Return 404 Not Found if response array is empty
|
||||
return new Response($this->results, $this->results ? 200 : 404);
|
||||
}
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Battlestation\{
|
||||
DramTable,
|
||||
DramFormfactorEnum,
|
||||
DramTechnologyEnum
|
||||
};
|
||||
use VLW\Database\Tables\Battlestation\Config\MbDramTable;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Dram.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Config/MbDram.php");
|
||||
|
||||
class GET_BattlestationDram extends Database {
|
||||
private const REL_MOTHERBOARDS = "motherboards";
|
||||
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
private array $query;
|
||||
private array $results = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(DramTable::ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(parent::UUID_LENGTH)
|
||||
->max(parent::UUID_LENGTH),
|
||||
|
||||
(new Rules(DramTable::CAPACITY->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1),
|
||||
|
||||
(new Rules(DramTable::SPEED->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1),
|
||||
|
||||
(new Rules(DramTable::FORMFACTOR->value))
|
||||
->type(Type::ENUM, DramFormfactorEnum::names()),
|
||||
|
||||
(new Rules(DramTable::TECHNOLOGY->value))
|
||||
->type(Type::ENUM, DramTechnologyEnum::names()),
|
||||
|
||||
(new Rules(DramTable::ECC->value))
|
||||
->type(Type::BOOLEAN),
|
||||
|
||||
(new Rules(DramTable::BUFFERED->value))
|
||||
->type(Type::BOOLEAN),
|
||||
|
||||
(new Rules(DramTable::VENDOR_NAME->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(DramTable::VENDOR_MODEL->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(DramTable::IS_RETIRED->value))
|
||||
->type(Type::BOOLEAN)
|
||||
]);
|
||||
|
||||
parent::__construct(Databases::BATTLESTATION, $this->ruleset);
|
||||
|
||||
// Use a copy of search parameters
|
||||
$this->query = $_GET;
|
||||
}
|
||||
|
||||
private function get_motherboards(): void {
|
||||
foreach ($this->results as &$result) {
|
||||
// Get motherboard id from relationship by chassis id
|
||||
$result[self::REL_MOTHERBOARDS] = $this->db
|
||||
->for(MbDramTable::NAME)
|
||||
->where([MbDramTable::REF_DRAM_ID->value => $result[DramTable::ID->value]])
|
||||
->select(MbDramTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_dram(): array {
|
||||
return $this->results = $this->db
|
||||
->for(DramTable::NAME)
|
||||
->where($this->query)
|
||||
->order([DramTable::DATE_AQUIRED->value => "DESC"])
|
||||
->select(DramTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Set properties as "searchable"
|
||||
parent::make_wildcard_search(DramTable::VENDOR_NAME->value, $this->query);
|
||||
parent::make_wildcard_search(DramTable::VENDOR_MODEL->value, $this->query);
|
||||
|
||||
// Get hardware
|
||||
$this->get_dram();
|
||||
|
||||
// Resolve hardware relationships
|
||||
$this->get_motherboards();
|
||||
|
||||
// Return 404 Not Found if response array is empty
|
||||
return new Response($this->results, $this->results ? 200 : 404);
|
||||
}
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Battlestation\GpuTable;
|
||||
use VLW\Database\Tables\Battlestation\Config\MbGpuTable;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Gpu.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Config/MbGpu.php");
|
||||
|
||||
class GET_BattlestationGpu extends Database {
|
||||
private const REL_MOTHERBOARDS = "motherboards";
|
||||
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
private array $query;
|
||||
private array $results = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(GpuTable::ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(parent::UUID_LENGTH)
|
||||
->max(parent::UUID_LENGTH),
|
||||
|
||||
(new Rules(GpuTable::MEMORY->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1),
|
||||
|
||||
(new Rules(GpuTable::VENDOR_NAME->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(GpuTable::VENDOR_MODEL->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(GpuTable::VENDOR_CHIP_NAME->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(GpuTable::VENDOR_CHIP_MODEL->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(GpuTable::IS_RETIRED->value))
|
||||
->type(Type::BOOLEAN)
|
||||
]);
|
||||
|
||||
parent::__construct(Databases::BATTLESTATION, $this->ruleset);
|
||||
|
||||
// Use a copy of search parameters
|
||||
$this->query = $_GET;
|
||||
}
|
||||
|
||||
private function get_motherboards(): void {
|
||||
foreach ($this->results as &$result) {
|
||||
// Get motherboard id from relationship by chassis id
|
||||
$result[self::REL_MOTHERBOARDS] = $this->db
|
||||
->for(MbGpuTable::NAME)
|
||||
->where([MbGpuTable::REF_GPU_ID->value => $result[GpuTable::ID->value]])
|
||||
->select(MbGpuTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_gpu(): array {
|
||||
return $this->results = $this->db
|
||||
->for(GpuTable::NAME)
|
||||
->where($this->query)
|
||||
->order([GpuTable::DATE_AQUIRED->value => "DESC"])
|
||||
->select(GpuTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Set properties as "searchable"
|
||||
parent::make_wildcard_search(GpuTable::VENDOR_NAME->value, $this->query);
|
||||
parent::make_wildcard_search(GpuTable::VENDOR_MODEL->value, $this->query);
|
||||
parent::make_wildcard_search(GpuTable::VENDOR_CHIP_NAME->value, $this->query);
|
||||
parent::make_wildcard_search(GpuTable::VENDOR_CHIP_MODEL->value, $this->query);
|
||||
|
||||
// Get hardware
|
||||
$this->get_gpu();
|
||||
|
||||
// Resolve hardware relationships
|
||||
$this->get_motherboards();
|
||||
|
||||
// Return 404 Not Found if response array is empty
|
||||
return new Response($this->results, $this->results ? 200 : 404);
|
||||
}
|
||||
}
|
|
@ -1,188 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Battlestation\{
|
||||
MbTable,
|
||||
MbFormfactorEnum
|
||||
};
|
||||
use VLW\Database\Tables\Battlestation\Config\{
|
||||
MbGpuTable,
|
||||
MbPsuTable,
|
||||
MbDramTable,
|
||||
MbStorageTable,
|
||||
ChassisMbTable,
|
||||
MbCpuCoolerModel
|
||||
};
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Mb.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Config/MbPsu.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Config/MbGpu.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Config/MbDram.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Config/MbStorage.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Config/ChassisMb.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Config/MbCpuCooler.php");
|
||||
|
||||
class GET_BattlestationMb extends Database {
|
||||
private const REL_CPU = "cpus";
|
||||
private const REL_PSU = "psus";
|
||||
private const REL_GPU = "gpus";
|
||||
private const REL_DRAM = "dram";
|
||||
private const REL_STORAGE = "storage";
|
||||
private const REL_CHASSIS = "chassis";
|
||||
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
private array $query;
|
||||
private array $results = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(MbTable::ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(parent::UUID_LENGTH)
|
||||
->max(parent::UUID_LENGTH),
|
||||
|
||||
(new Rules(MbTable::FORMFACTOR->value))
|
||||
->type(Type::ENUM, MbFormfactorEnum::names()),
|
||||
|
||||
(new Rules(MbTable::VENDOR_NAME->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(MbTable::VENDOR_MODEL->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(MbTable::NETWORK_ETHERNET->value))
|
||||
->type(Type::NULL)
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(MbTable::NETWORK_WLAN->value))
|
||||
->type(Type::NULL)
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(MbTable::NETWORK_BLUETOOTH->value))
|
||||
->type(Type::NULL)
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(MbTable::IS_RETIRED->value))
|
||||
->type(Type::BOOLEAN)
|
||||
]);
|
||||
|
||||
parent::__construct(Databases::BATTLESTATION, $this->ruleset);
|
||||
|
||||
// Use a copy of search parameters
|
||||
$this->query = $_GET;
|
||||
}
|
||||
|
||||
private function get_chassis(): void {
|
||||
foreach ($this->results as &$result) {
|
||||
// Get motherboard id from relationship by chassis id
|
||||
$result[self::REL_CHASSIS] = $this->db
|
||||
->for(ChassisMbTable::NAME)
|
||||
->where([ChassisMbTable::REF_MB_ID->value => $result[MbTable::ID->value]])
|
||||
->select(ChassisMbTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_psu(): void {
|
||||
foreach ($this->results as &$result) {
|
||||
// Get motherboard id from relationship by chassis id
|
||||
$result[self::REL_PSU] = $this->db
|
||||
->for(MbPsuTable::NAME)
|
||||
->where([MbPsuTable::REF_MB_ID->value => $result[MbTable::ID->value]])
|
||||
->select(MbPsuTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_cpu(): void {
|
||||
foreach ($this->results as &$result) {
|
||||
// Get motherboard id from relationship by chassis id
|
||||
$result[self::REL_CPU] = $this->db
|
||||
->for(MbCpuCoolerModel::NAME)
|
||||
->where([MbCpuCoolerModel::REF_MB_ID->value => $result[MbTable::ID->value]])
|
||||
->select(MbCpuCoolerModel::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_gpu(): void {
|
||||
foreach ($this->results as &$result) {
|
||||
// Get motherboard id from relationship by chassis id
|
||||
$result[self::REL_GPU] = $this->db
|
||||
->for(MbGpuTable::NAME)
|
||||
->where([MbGpuTable::REF_MB_ID->value => $result[MbTable::ID->value]])
|
||||
->select(MbGpuTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_dram(): void {
|
||||
foreach ($this->results as &$result) {
|
||||
// Get motherboard id from relationship by chassis id
|
||||
$result[self::REL_DRAM] = $this->db
|
||||
->for(MbDramTable::NAME)
|
||||
->where([MbDramTable::REF_MB_ID->value => $result[MbTable::ID->value]])
|
||||
->select(MbDramTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_storage(): void {
|
||||
foreach ($this->results as &$result) {
|
||||
// Get motherboard id from relationship by chassis id
|
||||
$result[self::REL_STORAGE] = $this->db
|
||||
->for(MbStorageTable::NAME)
|
||||
->where([MbStorageTable::REF_MB_ID->value => $result[MbTable::ID->value]])
|
||||
->select(MbStorageTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
|
||||
private function get_motherboards(): array {
|
||||
return $this->results = $this->db
|
||||
->for(MbTable::NAME)
|
||||
->where($this->query)
|
||||
->order([MbTable::DATE_AQUIRED->value => "DESC"])
|
||||
->select(MbTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Set properties as "searchable"
|
||||
parent::make_wildcard_search(MbTable::VENDOR_NAME->value, $this->query);
|
||||
parent::make_wildcard_search(MbTable::VENDOR_MODEL->value, $this->query);
|
||||
|
||||
// Get hardware
|
||||
$this->get_motherboards();
|
||||
|
||||
// Resolve hardware relationships
|
||||
$this->get_chassis();
|
||||
$this->get_cpu();
|
||||
$this->get_psu();
|
||||
$this->get_gpu();
|
||||
$this->get_dram();
|
||||
$this->get_storage();
|
||||
|
||||
// Return 404 Not Found if response array is empty
|
||||
return new Response($this->results, $this->results ? 200 : 404);
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Battlestation\{
|
||||
PsuTable,
|
||||
EightyplusRatingEnum
|
||||
};
|
||||
use VLW\Database\Tables\Battlestation\Config\MbPsuTable;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Psu.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Config/MbPsu.php");
|
||||
|
||||
class GET_BattlestationPsu extends Database {
|
||||
private const REL_MOTHERBOARDS = "motherboards";
|
||||
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
private array $query;
|
||||
private array $results = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(PsuTable::ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(parent::UUID_LENGTH)
|
||||
->max(parent::UUID_LENGTH),
|
||||
|
||||
(new Rules(PsuTable::POWER->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_INT_MAX_LENGTH),
|
||||
|
||||
(new Rules(PsuTable::EIGHTYPLUS_RATING->value))
|
||||
->type(Type::ENUM, EightyplusRatingEnum::names()),
|
||||
|
||||
(new Rules(PsuTable::VENDOR_NAME->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(PsuTable::VENDOR_MODEL->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(PsuTable::IS_RETIRED->value))
|
||||
->type(Type::BOOLEAN)
|
||||
]);
|
||||
|
||||
parent::__construct(Databases::BATTLESTATION, $this->ruleset);
|
||||
|
||||
// Use a copy of search parameters
|
||||
$this->query = $_GET;
|
||||
}
|
||||
|
||||
private function get_motherboards(): void {
|
||||
foreach ($this->results as &$result) {
|
||||
// Get motherboard id from relationship by chassis id
|
||||
$result[self::REL_MOTHERBOARDS] = $this->db
|
||||
->for(MbPsuTable::NAME)
|
||||
->where([MbPsuTable::REF_PSU_ID->value => $result[PsuTable::ID->value]])
|
||||
->select(MbPsuTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_psu(): array {
|
||||
return $this->results = $this->db
|
||||
->for(PsuTable::NAME)
|
||||
->where($this->query)
|
||||
->order([PsuTable::DATE_AQUIRED->value => "DESC"])
|
||||
->select(PsuTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Set properties as "searchable"
|
||||
parent::make_wildcard_search(PsuTable::VENDOR_NAME->value, $this->query);
|
||||
parent::make_wildcard_search(PsuTable::VENDOR_MODEL->value, $this->query);
|
||||
|
||||
// Get hardware
|
||||
$this->get_psu();
|
||||
|
||||
// Resolve hardware relationships
|
||||
$this->get_motherboards();
|
||||
|
||||
// Return 404 Not Found if response array is empty
|
||||
return new Response($this->results, $this->results ? 200 : 404);
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Battlestation\{
|
||||
StorageTable,
|
||||
StorageDiskTypeEnum,
|
||||
StorageDiskInterfaceEnum,
|
||||
StorageDiskFormfactorEnum
|
||||
};
|
||||
use VLW\Database\Tables\Battlestation\Config\MbStorageTable;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Storage.php");
|
||||
require_once Path::root("src/Database/Models/Battlestation/Config/MbStorage.php");
|
||||
|
||||
class GET_BattlestationStorage extends Database {
|
||||
private const REL_MOTHERBOARDS = "motherboards";
|
||||
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
private array $query;
|
||||
private array $results = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(StorageTable::ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(parent::UUID_LENGTH)
|
||||
->max(parent::UUID_LENGTH),
|
||||
|
||||
(new Rules(StorageTable::DISK_TYPE->value))
|
||||
->type(Type::ENUM, StorageDiskTypeEnum::names()),
|
||||
|
||||
(new Rules(StorageTable::DISK_SIZE->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_INT_MAX_LENGTH),
|
||||
|
||||
(new Rules(StorageTable::DISK_INTERFACE->value))
|
||||
->type(Type::ENUM, StorageDiskInterfaceEnum::names()),
|
||||
|
||||
(new Rules(StorageTable::DISK_FORMFACTOR->value))
|
||||
->type(Type::ENUM, StorageDiskFormfactorEnum::names()),
|
||||
|
||||
(new Rules(StorageTable::VENDOR_NAME->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(StorageTable::VENDOR_MODEL->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(StorageTable::IS_RETIRED->value))
|
||||
->type(Type::BOOLEAN)
|
||||
]);
|
||||
|
||||
parent::__construct(Databases::BATTLESTATION, $this->ruleset);
|
||||
|
||||
// Use a copy of search parameters
|
||||
$this->query = $_GET;
|
||||
}
|
||||
|
||||
private function get_motherboards(): void {
|
||||
foreach ($this->results as &$result) {
|
||||
// Get motherboard id from relationship by chassis id
|
||||
$result[self::REL_MOTHERBOARDS] = $this->db
|
||||
->for(MbStorageTable::NAME)
|
||||
->where([MbStorageTable::REF_STORAGE_ID->value => $result[StorageTable::ID->value]])
|
||||
->select(MbStorageTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_storage(): array {
|
||||
return $this->results = $this->db
|
||||
->for(StorageTable::NAME)
|
||||
->where($this->query)
|
||||
->order([StorageTable::DATE_AQUIRED->value => "DESC"])
|
||||
->select(StorageTable::values())
|
||||
->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Set properties as "searchable"
|
||||
parent::make_wildcard_search(StorageTable::VENDOR_NAME->value, $this->query);
|
||||
parent::make_wildcard_search(StorageTable::VENDOR_MODEL->value, $this->query);
|
||||
|
||||
// Get hardware
|
||||
$this->get_storage();
|
||||
|
||||
// Resolve hardware relationships
|
||||
$this->get_motherboards();
|
||||
|
||||
// Return 404 Not Found if response array is empty
|
||||
return new Response($this->results, $this->results ? 200 : 404);
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Messages\MessagesTable;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Messages/Messages.php");
|
||||
|
||||
class POST_Messages extends Database {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules(MessagesTable::EMAIL->value))
|
||||
->type(Type::STRING)
|
||||
->max(255)
|
||||
->default(null),
|
||||
|
||||
(new Rules(MessagesTable::MESSAGE->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_TEXT_MAX_LENGTH)
|
||||
]);
|
||||
|
||||
$ruleset->validate_or_exit();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Use copy of request body as entity
|
||||
$entity = $_POST;
|
||||
|
||||
$entity[MessagesTable::ID->value] = parent::gen_uuid4();
|
||||
$entity[MessagesTable::DATE_CREATED->value] = time();
|
||||
|
||||
return $this->db->for(MessagesTable::NAME)->insert($entity) === true
|
||||
? new Response($entity[MessagesTable::ID->value], 201)
|
||||
: new Response("Failed to create message", 500);
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Call;
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\API\Endpoints;
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Work\WorkTable;
|
||||
|
||||
require_once Path::root("src/Endpoints.php");
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Work/Work.php");
|
||||
|
||||
class GET_Search extends Database {
|
||||
const GET_QUERY = "q";
|
||||
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(self::GET_QUERY))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
|
||||
$ruleset->validate_or_exit();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
private function search_work(): Response {
|
||||
return (new Call(Endpoints::WORK->value))->params([
|
||||
WorkTable::TITLE->value => $_GET[self::GET_QUERY],
|
||||
WorkTable::SUMMARY->value => $_GET[self::GET_QUERY]
|
||||
])->get();
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
$results = [
|
||||
Endpoints::WORK->value => $this->search_work()->output()
|
||||
];
|
||||
|
||||
// Calculate the total number of results from all searched endpoints
|
||||
$num_results = array_sum(array_map(fn(array $result): int => count($result), array_values($results)));
|
||||
|
||||
// Return 404 if no search results
|
||||
return new Response($results, $num_results > 0 ? 200 : 404);
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use const VLW\API\RESP_DELETE_OK;
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Work\WorkTable;
|
||||
|
||||
require_once Path::root("src/Endpoints.php");
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Work.php");
|
||||
|
||||
class DELETE_Work extends Database {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules(WorkTable::ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkTable::TITLE->value))
|
||||
->type(Type::STRING)
|
||||
->min(3)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkTable::SUMMARY->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_TEXT_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkTable::IS_LISTED->value))
|
||||
->type(Type::BOOLEAN),
|
||||
|
||||
(new Rules(WorkTable::DATE_MODIFIED->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_INT_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkTable::DATE_CREATED->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_INT_MAX_LENGTH)
|
||||
]);
|
||||
|
||||
$ruleset->validate_or_exit();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
return $this->db->for(FieldsEnumsModel::NAME)->delete($_POST) === true
|
||||
? new Response(RESP_DELETE_OK)
|
||||
: new Response("Failed to delete work entity", 500);
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Work\WorkTable;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Work/Work.php");
|
||||
|
||||
class GET_Work extends Database {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(WorkTable::ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkTable::TITLE->value))
|
||||
->type(Type::STRING)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkTable::SUMMARY->value))
|
||||
->type(Type::STRING)
|
||||
->max(parent::MYSQL_TEXT_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkTable::IS_LISTED->value))
|
||||
->type(Type::BOOLEAN)
|
||||
->default(true),
|
||||
|
||||
(new Rules(WorkTable::DATE_MODIFIED->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_INT_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkTable::DATE_CREATED->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_INT_MAX_LENGTH)
|
||||
]);
|
||||
|
||||
$ruleset->validate_or_exit();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
return $this->list(WorkTable::NAME, WorkTable::values());
|
||||
}
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Call;
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\API\Endpoints;
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Work\{
|
||||
WorkTable,
|
||||
PermalinksTable
|
||||
};
|
||||
|
||||
require_once Path::root("src/Endpoints.php");
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Work/Work.php");
|
||||
require_once Path::root("src/Database/Models/Work/WorkPermalinks.php");
|
||||
|
||||
class PATCH_Work extends Database {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(WorkTable::ID->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules(WorkTable::TITLE->value))
|
||||
->type(Type::STRING)
|
||||
->min(3)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkTable::SUMMARY->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_TEXT_MAX_LENGTH),
|
||||
|
||||
(new Rules(WorkTable::IS_LISTED->value))
|
||||
->type(Type::BOOLEAN),
|
||||
|
||||
(new Rules(WorkTable::DATE_MODIFIED->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_INT_MAX_LENGTH)
|
||||
->default(time()),
|
||||
|
||||
(new Rules(WorkTable::DATE_CREATED->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_INT_MAX_LENGTH)
|
||||
]);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
// Generate a slug URL from string
|
||||
private static function gen_slug(string $input): string {
|
||||
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $input)));
|
||||
}
|
||||
|
||||
// Compute and return modeled year, month, and day from Unix timestamp in request body
|
||||
private static function gen_date_created(): array {
|
||||
return [
|
||||
WorkTable::DATE_YEAR->value => date("Y", $_POST[WorkTable::DATE_CREATED->value]),
|
||||
WorkTable::DATE_MONTH ->value => date("n", $_POST[WorkTable::DATE_CREATED->value]),
|
||||
WorkTable::DATE_DAY->value => date("j", $_POST[WorkTable::DATE_CREATED->value])
|
||||
];
|
||||
}
|
||||
|
||||
private function get_entity_by_id(string $id): Response {
|
||||
return (new Call(Endpoints::WORK->value))->params([
|
||||
WorkTable::ID->value => $id
|
||||
])->get();
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Use copy of request body as entity
|
||||
$entity = $_POST;
|
||||
|
||||
// Generate a new slug id from title if changed
|
||||
if ($_POST[WorkTable::TITLE->value]) {
|
||||
$slug = $_POST[WorkTable::TITLE->value];
|
||||
|
||||
// Bail out if the slug generated from the new tite already exist
|
||||
if ($this->get_entity_by_id($slug)) {
|
||||
return new Response("An entity with this title already exist", 409);
|
||||
}
|
||||
|
||||
// Add the new slug to update entity
|
||||
$entity[WorkTable::ID] = $slug;
|
||||
}
|
||||
|
||||
// Generate new work date fields from timestamp
|
||||
if ($_POST[WorkTable::DATE_CREATED->value]) {
|
||||
array_merge($entity, self::gen_date_created());
|
||||
}
|
||||
|
||||
// Update entity by existing id
|
||||
return $this->db->for(WorkTable::NAME)->where([WorkTable::ID->value => $_GET[WorkTable::ID->value]])->update($entity) === true
|
||||
? new Response($_GET[WorkTable::ID->value])
|
||||
: new Response("Failed to update entity", 500);
|
||||
}
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Call;
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\API\Endpoints;
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Work\{
|
||||
WorkTable,
|
||||
PermalinksTable
|
||||
};
|
||||
|
||||
require_once Path::root("src/Endpoints.php");
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Work/Work.php");
|
||||
require_once Path::root("src/Database/Models/Work/WorkPermalinks.php");
|
||||
|
||||
class POST_Work extends Database {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules(WorkTable::TITLE->value))
|
||||
->type(Type::STRING)
|
||||
->min(3)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
->default(null),
|
||||
|
||||
(new Rules(WorkTable::SUMMARY->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_TEXT_MAX_LENGTH)
|
||||
->default(null),
|
||||
|
||||
(new Rules(WorkTable::IS_LISTED->value))
|
||||
->type(Type::BOOLEAN)
|
||||
->default(false),
|
||||
|
||||
(new Rules(WorkTable::DATE_CREATED->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_INT_MAX_LENGTH)
|
||||
->default(time())
|
||||
]);
|
||||
|
||||
$ruleset->validate_or_exit();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
// Generate a slug URL from string
|
||||
private static function gen_slug(string $input): string {
|
||||
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $input)));
|
||||
}
|
||||
|
||||
// Compute and return modeled year, month, and day from a Unix timestamp
|
||||
private static function gen_date_created(): array {
|
||||
// Use provided timestamp in request
|
||||
$date_created = $_POST[WorkTable::DATE_CREATED->value];
|
||||
|
||||
return [
|
||||
WorkTable::DATE_YEAR->value => date("Y", $date_created),
|
||||
WorkTable::DATE_MONTH ->value => date("n", $date_created),
|
||||
WorkTable::DATE_DAY->value => date("j", $date_created)
|
||||
];
|
||||
}
|
||||
|
||||
private function get_entity_by_id(string $id): Response {
|
||||
return (new Call(Endpoints::WORK->value))->params([
|
||||
WorkTable::ID->value => $id
|
||||
])->get();
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Use copy of request body as entity
|
||||
$entity = $_POST;
|
||||
|
||||
// Generate URL slug from title text or UUID if undefined
|
||||
$entity[WorkTable::ID->value] = $_POST[WorkTable::TITLE->value]
|
||||
? self::gen_slug($_POST[WorkTable::TITLE->value])
|
||||
: parent::gen_uuid4();
|
||||
|
||||
// Bail out here if a work entry with id had been created already
|
||||
if ($this->get_entity_by_id($entity[WorkTable::ID->value])->ok) {
|
||||
return new Response("An entity with id '{$slug}' already exist", 409);
|
||||
}
|
||||
|
||||
// Generate the necessary date fields
|
||||
array_merge($entity, self::gen_date_created());
|
||||
|
||||
// Let's try to insert the new entity
|
||||
if (!$this->db->for(WorkTable::NAME)->insert($entity)) {
|
||||
return new Response("Failed to insert work entry", 500);
|
||||
}
|
||||
|
||||
// Generate permalink for new entity
|
||||
return (new Call(Endpoints::WORK_PERMALINKS->value))->post([
|
||||
PermalinksTable::ID => $entity[WorkTable::ID->value],
|
||||
PermalinksTable::REF_WORK_ID => $entity[WorkTable::ID->value],
|
||||
PermalinksTable::DATE_CREATED => time()
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use const VLW\API\RESP_DELETE_OK;
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Work\ActionsTable;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/WorkActions.php");
|
||||
|
||||
class DELETE_WorkActions extends Database {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules(ActionsTable::REF_WORK_ID->value))
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
return $this->db->for(ActionsTable::NAME)->delete($_POST) === true
|
||||
? new Response(RESP_DELETE_OK)
|
||||
: new Response("Failed to delete action for work entity", 500);
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Work\ActionsTable;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Work/WorkActions.php");
|
||||
|
||||
class GET_WorkActions extends Database {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(ActionsTable::REF_WORK_ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
|
||||
$ruleset->validate_or_exit();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
$response = $this->db->for(ActionsTable::NAME)
|
||||
->where($_GET)
|
||||
->select([
|
||||
ActionsTable::REF_WORK_ID->value,
|
||||
ActionsTable::DISPLAY_TEXT->value,
|
||||
ActionsTable::HREF->value,
|
||||
ActionsTable::CLASS_LIST->value
|
||||
]);
|
||||
|
||||
return $response->num_rows > 0
|
||||
? new Response(parent::index_array_by_key($response->fetch_all(MYSQLI_ASSOC), ActionsTable::REF_WORK_ID->value))
|
||||
: new Response([], 404);
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Call;
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\API\Endpoints;
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Work\{
|
||||
WorkTable,
|
||||
ActionsTable
|
||||
};
|
||||
|
||||
require_once Path::root("src/Endpoints.php");
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Work/Work.php");
|
||||
require_once Path::root("src/Database/Models/Work/WorkActions.php");
|
||||
|
||||
class POST_WorkActions extends Database {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules(ActionsTable::REF_WORK_ID->value))
|
||||
->required()
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(ActionsTable::DISPLAY_TEXT->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(ActionsTable::HREF->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->type(Type::NULL)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(ActionsTable::CLASS_LIST->value))
|
||||
->type(Type::ARRAY)
|
||||
->min(1)
|
||||
->default([])
|
||||
]);
|
||||
|
||||
$ruleset->validate_or_exit();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
private static function get_entity(): Response {
|
||||
return (new Call(Endpoints::WORK->value))->params([
|
||||
WorkTable::ID->value => $_POST[ActionsTable::REF_WORK_ID->value]
|
||||
])->get();
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if work entity could not be fetched
|
||||
$entity = self::get_entity();
|
||||
if (!$entity->ok) {
|
||||
return $entity;
|
||||
}
|
||||
|
||||
return $this->db->for(ActionsTable::NAME)->insert($_POST) === true
|
||||
? new Response($_POST[ActionsTable::REF_WORK_ID->value], 201)
|
||||
: new Response("Failed to add action to work entity", 500);
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Work\PermalinksTable;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Work/WorkPermalinks.php");
|
||||
|
||||
class GET_WorkPermalinks extends Database {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(PermalinksTable::ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(PermalinksTable::REF_WORK_ID->value))
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
||||
]);
|
||||
|
||||
$ruleset->validate_or_exit();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
$response = $this->db->for(PermalinksTable::NAME)
|
||||
->where($_GET)
|
||||
->select([
|
||||
PermalinksTable::ID->value,
|
||||
PermalinksTable::REF_WORK_ID->value,
|
||||
PermalinksTable::DATE_CREATED->value
|
||||
]);
|
||||
|
||||
return $response->num_rows > 0
|
||||
? new Response($response->fetch_all(MYSQLI_ASSOC))
|
||||
: new Response([], 404);
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\Call;
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Work\PermalinksTable;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Work/WorkPermalinks.php");
|
||||
|
||||
class POST_WorkPermalinks extends Database {
|
||||
protected Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->POST([
|
||||
(new Rules(PermalinksTable::ID->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(PermalinksTable::REF_WORK_ID->value))
|
||||
->required()
|
||||
->type(Type::STRING)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(PermalinksTable::DATE_CREATED->value))
|
||||
->type(Type::NUMBER)
|
||||
->min(1)
|
||||
->max(parent::MYSQL_INT_MAX_LENGTH)
|
||||
->default(time())
|
||||
]);
|
||||
|
||||
$ruleset->validate_or_exit();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
private static function get_entity(): Response {
|
||||
return (new Call(Endpoints::WORK->value))->params([
|
||||
WorkTable::ID->value => $_POST[TagsTable::REF_WORK_ID->value]
|
||||
])->get();
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
// Bail out if work entity could not be fetched
|
||||
$entity = self::get_entity();
|
||||
if (!$entity->ok) {
|
||||
return $entity;
|
||||
}
|
||||
|
||||
return $this->db->for(PermalinksTable::NAME)->insert($_POST) === true
|
||||
? new Response($_POST[PermalinksTable::ID->value], 201)
|
||||
: new Response("Failed to add permalink to work entity", 500);
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use const VLW\API\RESP_DELETE_OK;
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Work\TagsTable;
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Work/WorkTags.php");
|
||||
|
||||
class DELETE_WorkTags extends Database {
|
||||
private Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(TagsTable::REF_WORK_ID->value))
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(TagsTable::NAME->value))
|
||||
->type(Type::ENUM, TagsNameEnum::names())
|
||||
]);
|
||||
|
||||
$ruleset->validate_or_exit();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
return $this->db->for(TagsTable::NAME)->delete($_POST) === true
|
||||
? new Response(RESP_DELETE_OK)
|
||||
: new Response("Failed to delete value from document", 500);
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Reflect\{Response, Path};
|
||||
use ReflectRules\{Ruleset, Rules, Type};
|
||||
|
||||
use VLW\Database\Database;
|
||||
use VLW\Database\Tables\Work\{
|
||||
TagsTable,
|
||||
TagsNameEnum
|
||||
};
|
||||
|
||||
require_once Path::root("src/Database/Database.php");
|
||||
require_once Path::root("src/Database/Models/Work/WorkTags.php");
|
||||
|
||||
class GET_WorkTags extends Database {
|
||||
private Ruleset $ruleset;
|
||||
|
||||
public function __construct() {
|
||||
$this->ruleset = new Ruleset(strict: true);
|
||||
|
||||
$this->ruleset->GET([
|
||||
(new Rules(TagsTable::REF_WORK_ID->value))
|
||||
->min(1)
|
||||
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
||||
|
||||
(new Rules(TagsTable::NAME->value))
|
||||
->type(Type::ENUM, TagsNameEnum::names())
|
||||
]);
|
||||
|
||||
$ruleset->validate_or_exit();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function main(): Response {
|
||||
$response = $this->db->for(TagsTable::NAME)
|
||||
->where($_GET)
|
||||
->select([
|
||||
TagsTable::REF_WORK_ID->value,
|
||||
TagsTable::NAME->value
|
||||
]);
|
||||
|
||||
return $response->num_rows > 0
|
||||
? new Response(parent::index_array_by_key($response->fetch_all(MYSQLI_ASSOC), TagsTable::REF_WORK_ID->value))
|
||||
: new Response([], 404);
|
||||
}
|
||||
}
|