Начал делать API для постов

This commit is contained in:
Shr3dd3r 2023-09-06 05:38:18 +03:00
parent 983a5d0353
commit 9a4658f3ea
7 changed files with 71 additions and 1 deletions

View File

@ -9,4 +9,6 @@ The newest generation imageboard.
- `sudo rm -r /usr/share/nginx/html/testing/E949 && sudo cp -R . /usr/share/nginx/html/testing/E949/ && sudo chown -R http:http /usr/share/nginx/html/testing`
- `mysql -u e949 -p`
- `#049e59` -> `#094e59`

View File

@ -39,6 +39,7 @@
- Может банить кого угодно
- Может удалять чьи угодно аккаунты
- Может редактировать чужие посты
- Может управлять одобренными тегами
- Аватарки
- Бан
- Полное удаление

36
api/post/create.php Normal file
View File

@ -0,0 +1,36 @@
<?php // Create new post
require_once("../_auth.php");
require_once("../_utils.php");
// Create single publication
function Post_Create ($author, $tags, $pic_path, $title = null, $prev_path = null, $comms_enabled = false, $edit_lock = false) {
global $db;
// $s = $db->prepare("INSERT ...");
// $s->bind_param("s", $author);
// $s->execute();
// $d = $s->get_result()->fetch_assoc();
//
// if (!(bool)$d) {
// return null;
// }
return $result;
}
if (ThisFileIsRequested(__FILE__)) {
require_once("../_json.php");
// Check if there are necessary input
if (!(isset($_POST["tags"]) && isset($_FILES["pic"])))
ReturnJSONError($Err_RDP_InvalidArgs, "not enough arguments");
// TODO
}
?>

View File

@ -5,6 +5,21 @@ require_once("../_utils.php");
// Increment number of views for post
function Post_AddView ($id) {
global $db;
$s = $db->prepare("UPDATE posts SET views = views + 1 WHERE id = ?");
$s->bind_param("s", $id);
$s->execute();
$d = $s->get_result()->fetch_assoc();
if (!(bool)$d) {
require_once("../_json.php");
ReturnJSONError($Err_Int_Unexpected, "failed to increment number of views");
}
}
// Get single publication by ID
function Post_GetByID ($id) {
global $db;
@ -34,7 +49,7 @@ function Post_GetByID ($id) {
$result["preview_path"] = $d["preview_path"];
$result["edit_lock"] = $d["edit_lock"];
// TODO: increment views of post
Post_AddView($id);
return $result;
}

View File

@ -1,4 +1,5 @@
<?php // Deleting existing account
require_once("../_auth.php");
require_once("../_utils.php");
require_once("./index.php");

View File

@ -14,5 +14,17 @@
},
"accounts": {
"external_avatars": false
},
"media": {
"max_pic_size": 56623104,
"allowed_exts": [
"jpg",
"jpeg",
"png"
],
"allowed_mimetypes": [
"image/jpeg",
"image/png"
]
}
}

View File

@ -69,4 +69,7 @@ CREATE TABLE invites (
author_id INT UNSIGNED NULL COMMENT 'ID of user, who created invite',
uses_last SMALLINT UNSIGNED NOT NULL COMMENT 'Remaining uses of invite'
);
CREATE TABLE approved_tags (
value VARCHAR(255) NOT NULL COMMENT 'The tag itself'
);
```