feat(API): add new api for use in another project

This commit is contained in:
2026-07-10 01:47:01 +03:30
parent a6a414c2f5
commit d5639f05fc
6 changed files with 262 additions and 0 deletions

View File

@@ -12,6 +12,29 @@ if (preg_match('#^/view/([a-f0-9]+)$#i', $path, $m)) {
exit;
}
// Route: /api/paste/{id}/unlock
if (preg_match('#^/api/paste/([a-f0-9]+)/unlock$#i', $path, $m) && $_SERVER['REQUEST_METHOD'] === 'POST') {
$_GET['id'] = $m[1];
$_GET['action'] = 'unlock';
require __DIR__ . '/api.php';
exit;
}
// Route: /api/paste/{id}
if (preg_match('#^/api/paste/([a-f0-9]+)$#i', $path, $m)) {
$_GET['id'] = $m[1];
$_GET['action'] = 'get';
require __DIR__ . '/api.php';
exit;
}
// Route: /api/paste
if ($path === '/api/paste') {
$_GET['action'] = 'create';
require __DIR__ . '/api.php';
exit;
}
// Route: static assets
if (preg_match('#\.(css|js|png|jpg|ico|svg|woff2?)$#', $path)) {
return false; // let PHP built-in server serve the file