From d54d3077cb41b336104e59d925668053afb2b64e Mon Sep 17 00:00:00 2001 From: David Bailey Date: Mon, 11 Dec 2023 16:22:42 +0100 Subject: [PATCH] feat: :sparkles: use new adapter upload function --- www/router.php | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/www/router.php b/www/router.php index faf57d2..2f2d0e8 100644 --- a/www/router.php +++ b/www/router.php @@ -49,21 +49,41 @@ if($SURI == '/') { } elseif($SURI == '/api/upload') { if(array_key_exists('post_data', $_FILES)) { - $upload_content = file_get_contents($_FILES['post_data']['tmp_name']); - $upload_path = $_POST['post_path']; - $adapter->save_markdown_post($upload_path, $upload_content); + + $adapter->handle_upload($_POST['post_path'], $_FILES['post_data']['tmp_name']); } echo $twig->render('upload.html'); } +} elseif($_SERVER['HTTP_SEC_FETCH_DEST'] == 'image') { + header('Location: /raw' . $SURI); + exit(0); } elseif(true) { $post = $adapter->get_post_by_path($SURI); - echo $twig->render('about.html', [ - "post" => $post, - "subposts" => $post['subposts'] - ]); + if($post['post_metadata']['type'] == 'directory') { + if(preg_match('/^(.*[^\/])((?:#.*)?)$/', $SURI, $match)) { + header('Location: ' . $match[1] . '/' . $match[2]); + exit(0); + } + + echo $twig->render('directory.html', [ + "post" => $post, + "subposts" => $post['subposts'] + ]); + } + elseif($post['post_metadata']['type'] == 'text/markdown') { + echo $twig->render('about.html', [ + "post" => $post, + "subposts" => $post['subposts'] + ]); + } + elseif($post['post_metadata']['type'] == 'file') { + echo $twig->render('image.html', [ + "post" => $post + ]); + } } elseif(preg_match('/^\/about(.html)?$/', $SURI)) { echo $twig->render('about.html');