From 3b0e3e363f7477d4bc8fce5ca4063348c7bd66a2 Mon Sep 17 00:00:00 2001 From: Starscouts Date: Mon, 26 Aug 2024 11:40:04 +0200 Subject: [PATCH] Remove API v1 from PHP backend --- server/docs/v1/index.php | 205 +-------------------------- server/includes/api/v1/available.php | 9 -- server/includes/api/v1/generate.php | 74 ---------- server/includes/api/v1/history.php | 46 ------ server/includes/api/v1/status.php | 43 ------ 5 files changed, 2 insertions(+), 375 deletions(-) delete mode 100644 server/includes/api/v1/available.php delete mode 100644 server/includes/api/v1/generate.php delete mode 100644 server/includes/api/v1/history.php delete mode 100644 server/includes/api/v1/status.php diff --git a/server/docs/v1/index.php b/server/docs/v1/index.php index 8355c15..6e81039 100644 --- a/server/docs/v1/index.php +++ b/server/docs/v1/index.php @@ -42,211 +42,10 @@ function getAPIKey(): string {

Floofi Voice Generator API docs v1

-
- Notice: These docs are for version 1 of the API. The latest version is version 2, which you can get docs for here. API version 1 may be removed at any time without warning and should be avoided. +
+ Version 1 of the API is now unavailable, please use a later version instead. The latest version is version 2, which you can get docs for here.
-

Voice Generator provides a RESTful API that you can use to interact with various features of the AI.

- -

API limits

- - -

Your API key

-

Your API key is strictly personal, sharing it will allow anyone to use on your behalf. It is displayed below, and you can hover over it or tap it to display it.

- -

To authenticate with the API, you need to set the Authorization header to Bearer <API key>. If you are logged into through the website, your session will work on the API, although this is not a recommended way to use the API. If you are using Insomnia, click on the "Auth" tab and select "Bearer Token."

- -

Output data

-
-error?: {
-    code: number,
-    name: string,
-    see: "https://voice-api.floo.fi/docs/"
-}
-output: any|null
-    
- -

Error codes

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CodeNameMeaning
400Bad RequestA required argument for this endpoint is missing or incorrectly formatted.
401UnauthorizedNo API key was provided with the request. If an API key was provided, it is not valid.
403ForbiddenYou should normally have access to this endpoint, but your account has been blocked by the administrators.
404Not FoundThe requested API endpoint does not exist or is not supported in this version of the API.
405Method Not AllowedThe HTTP method used at this endpoint is not the one that is expected.
409ConflictYou have tried to change the state of an item to a state it is already in.
413Payload Too LargeOne of the parameters sent to this API endpoint is longer than the allowed length.
429Too Many RequestsThis API key has exceeded the number of allowed requests in a certain timespan.
451Unavailable For Legal ReasonsThe request goes against 's content filters and/or terms of use.
500Internal Server ErrorA server error has occurred while processing this request.
501Not ImplementedThe version of the API you are trying to use does not exist.
- -

Endpoints

-

All API endpoints take root in https://voice-api.floo.fi/api.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MethodPathParametersDescriptionOutput
GETv1/status-Get system information.
{
-    "user": string,
-    "version": string,
-    "processingUnits": [
-        {
-            "id": string,
-            "pid": number,
-            "busy": boolean
-        }
-    ]
-}
GET
New
v1/available-Check if enqueing a new generation is possible.
{
-    "available": boolean
-}
GETv1/historyURL: amount: number (optional)Get previous generations associated with this account.
[
-    {
-        "id": string,
-        "version": string,
-        "author": string,
-        "status": generation-status,
-        "input": string,
-        "filename": string,
-        "audio_url": string?,
-        "explicit": boolean
-    }
-]
GETv1/history/:id-Get a specific generation from its ID.
{
-    "id": string,
-    "version": string,
-    "author": string,
-    "status": generation-status,
-    "input": string,
-    "filename": string,
-    "audio_url": string?,
-    "explicit": boolean
-}
DELETEv1/history/:id-Remove a specific generation from your history using its ID.
{
-    "id": string,
-    "version": string,
-    "author": string,
-    "status": "removed",
-    "input": string,
-    "filename": string,
-    "audio_url": null,
-    "explicit": boolean
-}
POSTv1/generateJSON: input: stringEnqueue a new generation job.
{
-    "id": string
-}
- -

Types

-
generation-status
-
"removed"|"processed"|"generating"|"queued"|"crashed"
-


diff --git a/server/includes/api/v1/available.php b/server/includes/api/v1/available.php deleted file mode 100644 index 44a37e0..0000000 --- a/server/includes/api/v1/available.php +++ /dev/null @@ -1,9 +0,0 @@ - getPossible() -]); diff --git a/server/includes/api/v1/generate.php b/server/includes/api/v1/generate.php deleted file mode 100644 index 7ace62d..0000000 --- a/server/includes/api/v1/generate.php +++ /dev/null @@ -1,74 +0,0 @@ - [ - "length" => 160, - "required" => true, - "post" => true - ] -]); - -$possible = true; - -foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs"), function ($i) { return !str_starts_with($i, "."); }) as $item) { - if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $item . "/author.txt") && !file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $item . "/blocked.txt")) { - if (file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $item . "/author.txt") === $profile["id"]) { - if (!(file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $item . "/complete.txt") && file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $item . "/audio.wav"))) $possible = false; - } - } -} - -if (!$possible || !getPossible()) error(429); - -$code = getFilterCode($_POST["input"]); - -// --------------------------- - -$modelText = substr(trim(preg_replace("/[^a-zA-Z':\d()[\].,?! ~]/", "", $_POST["input"] ?? "")), 0, 160); -$uid = uuid(); -$fid = str_replace("-", "", uuid() . "-" . $profile["id"] . "-" . $uid); - -while (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $fid)) { - $fid = str_replace("-", "", uuid() . "-" . $profile["id"] . "-" . $uid); -} - -mkdir($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $fid); -file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $fid . "/model.txt", "sunny"); -file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $fid . "/author.txt", $profile["id"]); -file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $fid . "/timestamp.txt", time()); -file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $fid . "/input_orig.txt", substr(trim($_POST["input"] ?? ""), 0, 160)); - -if ($profile["id"] === json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens.json"), true)['oauth']['admin']) { - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $fid . "/reviewed.txt", ""); -} - -if ($code > 0) { - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $fid . "/held.txt", $code); -} - -file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $fid . "/version.txt", json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/models.json"), true)["sunny"]["version"]); - -if ($code < 2) { - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $fid . "/inputtxt", $modelText); -} else { - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $fid . "/blocked.txt", ""); -} - -if ($code > 1) { - error(451); -} else { - output([ - "id" => $fid - ]); -} diff --git a/server/includes/api/v1/history.php b/server/includes/api/v1/history.php deleted file mode 100644 index 498c6c3..0000000 --- a/server/includes/api/v1/history.php +++ /dev/null @@ -1,46 +0,0 @@ - [ - "required" => false, - "post" => false - ] - ]); - - $list = []; - - if (isset($_GET["amount"]) && is_numeric($_GET["amount"]) && (int)$_GET["amount"] == (float)$_GET["amount"]) { - $list = getList(null, (int)($_GET["amount"])); - } elseif (isset($_GET["amount"])) { - error(400); - } else { - $list = getList(); - } - - output([ - "history" => $list, - "count" => count($list) - ]); -} diff --git a/server/includes/api/v1/status.php b/server/includes/api/v1/status.php deleted file mode 100644 index f026096..0000000 --- a/server/includes/api/v1/status.php +++ /dev/null @@ -1,43 +0,0 @@ - $user, - "version" => file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/version.txt"), - "processingUnits" => array_map(function ($pid) { - $busy = false; - - foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs"), function ($i) { return !str_starts_with($i, "."); }) as $item) { - if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $item . "/process.txt")) { - if ((int)(trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $item . "/process.txt"))) === $pid) { - if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/outputs/" . $item . "/complete.txt")) { - $busy = true; - } - } - } - } - - return [ - "id" => "01-$pid", - "pid" => $pid, - "busy" => $busy - ]; - }, getProcessingUnits()) -]);