summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rwxr-xr-xapp/Models/User.php4
-rw-r--r--database/migrations/2024_12_21_021128_files.php4
-rw-r--r--docs/thoughts.md11
-rw-r--r--resources/js/writing_index.js24
-rw-r--r--resources/views/f_cursor_0221.blade.php136
-rw-r--r--resources/views/f_v1.blade.php79
-rwxr-xr-xresources/views/home.blade.php8
-rwxr-xr-xresources/views/template.blade.php2
-rw-r--r--resources/views/writings/index.blade.php5
-rwxr-xr-xvite.config.js3
11 files changed, 272 insertions, 9 deletions
diff --git a/README.md b/README.md
index 2538804..08d091c 100644
--- a/README.md
+++ b/README.md
@@ -15,6 +15,9 @@ https://laravel.com/docs/11.x/blade
- quickbuttons, for adding in snippets of things like embedding an image
- update markup on a timer instead of every character (and/or see if i can prevent it from making unnecessary network requests like loading embedded files)
+- tests
+ - test the return code and body of every route to make sure no error introduced
+
- general
- import any model via json
- links
@@ -22,4 +25,4 @@ https://laravel.com/docs/11.x/blade
- homepage image
- user dashboard system
- \ No newline at end of file
+
diff --git a/app/Models/User.php b/app/Models/User.php
index 3c5e429..33861eb 100755
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -75,4 +75,8 @@ class User extends Authenticatable
public function getStorageUsed(){
}
+
+ public function files(){
+ return $this->hasMany(File::class);
+ }
}
diff --git a/database/migrations/2024_12_21_021128_files.php b/database/migrations/2024_12_21_021128_files.php
index f76ab53..0c485f0 100644
--- a/database/migrations/2024_12_21_021128_files.php
+++ b/database/migrations/2024_12_21_021128_files.php
@@ -18,7 +18,9 @@ return new class extends Migration
$table->string('path')->unique();
$table->string('source');
$table->string('description');
- $table->string('md5')->required();
+ $table->integer('user_id')->unsigned()->index();
+ $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
+ $table->string('md5')->required();
});
}
diff --git a/docs/thoughts.md b/docs/thoughts.md
new file mode 100644
index 0000000..8aa159a
--- /dev/null
+++ b/docs/thoughts.md
@@ -0,0 +1,11 @@
+allow to write without having accound
+
+
+firstly, i'm not going to worry about models.txt at this point. i can just write migrations directly. no need to generalize into the lapigen stuff yet.
+
+when to use softdeletes?
+
+
+non-database mode. site is aware that it currently doesn't have access to a database, and has alternate behavior that still provides utility.
+
+
diff --git a/resources/js/writing_index.js b/resources/js/writing_index.js
index b8a2ed1..d46bf77 100644
--- a/resources/js/writing_index.js
+++ b/resources/js/writing_index.js
@@ -37,7 +37,8 @@ $(function() {
function initDOM(){
dom.filterMethod = $('#filter_method')[0];
dom.sortMethod = $('#sort_method')[0];
-
+ dom.sortMethod.onchange = sortContentList;
+ dom.filterMethod.onchange = filterContentList;
}
function performReplace(){
@@ -56,4 +57,23 @@ function performReplace(){
dom.inputText.value = dom.inputText.value.replace(regex, dom.replaceStr.value);
dom.contentPreview.innerHTML = marked.parse(dom.inputText.value);
-}; \ No newline at end of file
+};
+
+function sortContentList(){
+ const sortMethod = dom.sortMethod.value;
+ console.log(sortMethod);
+ switch (sorthMethod){
+ case 'date':
+ break;
+ case 'title':
+ break;
+ case 'author':
+ break;
+ case 'category':
+ break;
+ default:
+ break;
+ }
+}
+
+function filterContentList(){} \ No newline at end of file
diff --git a/resources/views/f_cursor_0221.blade.php b/resources/views/f_cursor_0221.blade.php
new file mode 100644
index 0000000..fe9c9f0
--- /dev/null
+++ b/resources/views/f_cursor_0221.blade.php
@@ -0,0 +1,136 @@
+@extends('template')
+<?php
+ $baseDir = 'storage/uploads/';
+ $currentDir = $baseDir;
+
+ //use this if want to require auth
+ /*$valid_username = 'admin'; // Set your username
+ $valid_password = 'password'; // Set your password
+ if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
+ $_SERVER['PHP_AUTH_USER'] != $valid_username || $_SERVER['PHP_AUTH_PW'] != $valid_password) {
+ header('WWW-Authenticate: Basic realm="Secure Directory"');
+ header('HTTP/1.0 401 Unauthorized');
+ echo 'Authentication required';
+ exit;
+ }*/
+
+ // check if requested file or directory
+ if (isset($_GET['file'])) {
+ $fileRequested = $_GET['file'];
+ $filePath = realpath($fileRequested);
+
+ if (file_exists($filePath) && is_file($filePath)) {
+ // Set headers to force download
+ header('Content-Description: File Transfer');
+ header('Content-Type: application/octet-stream');
+ header('Content-Disposition: attachment; filename="' . basename($filePath) . '"');
+ header('Expires: 0');
+ header('Cache-Control: must-revalidate');
+ header('Pragma: public');
+ header('Content-Length: ' . filesize($filePath));
+ readfile($filePath);
+ exit;
+ } else {
+ echo "File not found.";
+ exit;
+ }
+ } else if (isset($_GET['dir'])) {
+ $dir = $_GET['dir'];
+ if (strpos($dir, '..') !== false || strpos($dir, '/') !== false || strpos($dir, '\\') !== false) {
+ echo 'Access Denied';
+ exit;
+ }
+ $dir= basename($dir); // Ensuring the folder name is isolated
+ if (!is_dir("${baseDir}/${dir}")) {
+ echo 'Directory not found';
+ exit;
+ }
+ $currentDir = "${baseDir}/${dir}";
+ }
+
+ // Extracting the name of the current directory
+ $currentDirName = basename($currentDir);
+
+ // Determine the depth of the current directory relative to the base directory
+ $depth = substr_count(str_replace($baseDir, '', $currentDir), '/');
+
+ $contents = scandir($currentDir);
+
+ $files = []; // Array to hold file details
+?>
+ @foreach ($contents as $item)
+ @if ($item !== "." && $item !== "..")
+ @php
+ $filePath = $currentDir . '/' . $item;
+ $fileInfo = [
+ 'name' => htmlspecialchars($item),
+ 'size' => is_file($filePath) ? filesize($filePath) : 0,
+ 'date' => is_file($filePath) ? date("F d Y H:i:s.", filemtime($filePath)) : '',
+ 'is_dir' => is_dir($filePath)
+ ];
+ $files[] = $fileInfo; // Add file info to the array
+ @endphp
+ <li>
+ @if ($fileInfo['is_dir'])
+ <strong>Directory:</strong> <a href="?dir={{ $item }}">{{ $fileInfo['name'] }}</a>
+ @else
+ <a href="/f/{{ $fileInfo['name'] }}">{{ $fileInfo['name'] }}</a>
+ <span>(Size: {{ $fileInfo['size'] }} bytes, Date: {{ $fileInfo['date'] }})</span>
+ @endif
+ </li>
+ @endif
+ @endforeach
+
+ // Add sorting functionality
+ @if (isset($_GET['sort']))
+ @php
+ $sort = $_GET['sort'];
+ usort($files, function($a, $b) use ($sort) {
+ if ($sort === 'size') {
+ return $a['size'] <=> $b['size'];
+ } elseif ($sort === 'date') {
+ return $a['date'] <=> $b['date'];
+ } else { // Default to sorting by name
+ return strcmp($a['name'], $b['name']);
+ }
+ });
+ @endphp
+ @endif
+
+ <ul>
+ @foreach ($files as $fileInfo)
+ <li>
+ @if ($fileInfo['is_dir'])
+ <strong>Directory:</strong> <a href="?dir={{ $fileInfo['name'] }}">{{ $fileInfo['name'] }}</a>
+ @else
+ <a href="/f/{{ $fileInfo['name'] }}">{{ $fileInfo['name'] }}</a>
+ <span>(Size: {{ $fileInfo['size'] }} bytes, Date: {{ $fileInfo['date'] }})</span>
+ @endif
+ </li>
+ @endforeach
+ @if ($currentDir != $baseDir)
+ <li><a href="/f?dir={{ $currentDirName }}">Go Up</a></li>
+ @endif
+ </ul>
+
+@section('body')
+<main>
+ <!--<p><b>Contents of:</b> <em> {{ $currentDir }}</em></p>-->
+ <p><b>{{ htmlspecialchars(ucfirst($currentDirName)) }}</b></p>
+ <ul>
+ @foreach ($files as $fileInfo)
+ <li>
+ @if ($fileInfo['is_dir'])
+ <strong>Directory:</strong> <a href="?dir={{ $fileInfo['name'] }}">{{ $fileInfo['name'] }}</a>
+ @else
+ <a href="/f/{{ $fileInfo['name'] }}">{{ $fileInfo['name'] }}</a>
+ <span>(Size: {{ $fileInfo['size'] }} bytes, Date: {{ $fileInfo['date'] }})</span>
+ @endif
+ </li>
+ @endforeach
+ @if ($currentDir != $baseDir)
+ <li><a href="/f?dir={{ $currentDirName }}">Go Up</a></li>
+ @endif
+ </ul>
+</main>
+@endsection \ No newline at end of file
diff --git a/resources/views/f_v1.blade.php b/resources/views/f_v1.blade.php
new file mode 100644
index 0000000..cff2a4f
--- /dev/null
+++ b/resources/views/f_v1.blade.php
@@ -0,0 +1,79 @@
+@extends('template')
+<?php
+ $baseDir = 'storage/uploads/';
+ $currentDir = $baseDir;
+
+ //use this if want to require auth
+ /*$valid_username = 'admin'; // Set your username
+ $valid_password = 'password'; // Set your password
+ if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
+ $_SERVER['PHP_AUTH_USER'] != $valid_username || $_SERVER['PHP_AUTH_PW'] != $valid_password) {
+ header('WWW-Authenticate: Basic realm="Secure Directory"');
+ header('HTTP/1.0 401 Unauthorized');
+ echo 'Authentication required';
+ exit;
+ }*/
+
+ // check if requested file or directory
+ if (isset($_GET['file'])) {
+ $fileRequested = $_GET['file'];
+ $filePath = realpath($fileRequested);
+
+ if (file_exists($filePath) && is_file($filePath)) {
+ // Set headers to force download
+ header('Content-Description: File Transfer');
+ header('Content-Type: application/octet-stream');
+ header('Content-Disposition: attachment; filename="' . basename($filePath) . '"');
+ header('Expires: 0');
+ header('Cache-Control: must-revalidate');
+ header('Pragma: public');
+ header('Content-Length: ' . filesize($filePath));
+ readfile($filePath);
+ exit;
+ } else {
+ echo "File not found.";
+ exit;
+ }
+ } else if (isset($_GET['dir'])) {
+ $dir = $_GET['dir'];
+ if (strpos($dir, '..') !== false || strpos($dir, '/') !== false || strpos($dir, '\\') !== false) {
+ echo 'Access Denied';
+ exit;
+ }
+ $dir= basename($dir); // Ensuring the folder name is isolated
+ if (!is_dir("${baseDir}/${dir}")) {
+ echo 'Directory not found';
+ exit;
+ }
+ $currentDir = "${baseDir}/${dir}";
+ }
+
+ // Extracting the name of the current directory
+ $currentDirName = basename($currentDir);
+
+ // Determine the depth of the current directory relative to the base directory
+ $depth = substr_count(str_replace($baseDir, '', $currentDir), '/');
+
+ $contents = scandir($currentDir);
+?>
+@section('body')
+<main>
+ <!--<p><b>Contents of:</b> <em> {{ $currentDir }}</em></p>-->
+ <p><b>{{ htmlspecialchars(ucfirst($currentDirName)) }}</b></p>
+ <ul>
+ @foreach ($contents as $item)
+ @if ($item !== "." && $item !== "..")
+ <li>
+ @if (is_dir($currentDir . '/' . $item))
+ <strong>Directory:</strong> <a href="?dir={{ $item }}">{{ htmlspecialchars($item) }}</a>
+ @else
+ <a href="/f/{{ $item }}">{{ htmlspecialchars($item) }}</a>
+ @endif
+ </li>
+ @endif
+ @endforeach
+ @if ($currentDir != $baseDir)
+ <li><a href="/f?dir={{ $currentDirName }}">Go Up</a></li>
+ @endif
+</main>
+@endsection \ No newline at end of file
diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php
index 7598045..dcfe2de 100755
--- a/resources/views/home.blade.php
+++ b/resources/views/home.blade.php
@@ -6,11 +6,13 @@
<header>
<h1>A friendly webserver</h1>
- <h2>in Iowa</h2>
+ <h2></h2>
<p>
Welcome
</p>
- <div id = "seeker-status">
+ <div id = "site-status">
+ <h6>Current Status</h6>
+ <p></p>
<p>Number of friends connected: <b id = "numFriendsConnected"></b></p> <!-- show number of other connections to webserver -->
<br>
<p>Who are you?</p><input type = "text" id = "input_who" />
@@ -92,4 +94,4 @@
</section> --}}
-@endsection \ No newline at end of file
+@endsection
diff --git a/resources/views/template.blade.php b/resources/views/template.blade.php
index 2043d47..6678d87 100755
--- a/resources/views/template.blade.php
+++ b/resources/views/template.blade.php
@@ -27,6 +27,8 @@
Home
</a>
@yield('nav')
+ <a href = "/settings" /><small>Settings, Info</small></a><!-- auth-agnostic settings -->
+ <div id = "database-info">Checking connection to database...</div>
@if (Auth::user() == null)
<a href="{{ route('login') }}" class = "form-button" style="margin-left: auto; margin-right: 1rem;">
{{ __('Log In') }}
diff --git a/resources/views/writings/index.blade.php b/resources/views/writings/index.blade.php
index 36cb735..a9c2f54 100644
--- a/resources/views/writings/index.blade.php
+++ b/resources/views/writings/index.blade.php
@@ -1,4 +1,7 @@
@extends('template')
+@section('head')
+@vite(['resources/js/writing_index.js'])
+@endsection
@section('body')
<main>
<div >
@@ -9,7 +12,7 @@
<!-- TODO search -->
<div class = "sidebar">
<legend>Sort by: </legend>
- <select name = "sort_method">
+ <select name = "sort_method" id = "sort_method">
<option value = "date">Date</option>
<option value = "user">Author</option>
<option value = "title">Title</option>
diff --git a/vite.config.js b/vite.config.js
index 0af0b6a..3d01ad3 100755
--- a/vite.config.js
+++ b/vite.config.js
@@ -13,6 +13,7 @@ export default defineConfig({
'resources/css/jstoys.css',
'resources/js/main.js',
'resources/js/marked.js',
+ 'resources/js/writing_index.js',
'resources/js/writing_create.js',
'resources/js/writing_show.js',
'resources/js/blood_gpu.js',
@@ -21,7 +22,7 @@ export default defineConfig({
}),
],
server: {
- host: '192.168.4.32',
+ host: true,
cors: true
}
});