Skip to content

Commit

Permalink
feat: add .dbmeta.md rendering. closes #29
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschubek committed Oct 29, 2024
1 parent b9ec59c commit 642a55f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ ENV README_NAME=readme.md

ENV README_FIRST=false

ENV README_META=true

ENV DOWNLOAD_COUNTER=true

ENV README_RENDER=true
Expand Down
20 changes: 15 additions & 5 deletions src/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

define('VERSION', '3.4.1');
define('VERSION', '3.5.0');

define('PUBLIC_FOLDER', __DIR__ . '/public');

Expand Down Expand Up @@ -105,7 +105,7 @@ function available(string $user_path): string | false {
$path = realpath(PUBLIC_FOLDER . $user_path);
if ($path === false || !str_starts_with($path, PUBLIC_FOLDER) || hidden($path)) return false;
$[if `process.env.METADATA === "true"`]$
if (str_contains($path, ".dbmeta.json")) return false;
if (str_contains($path, ".dbmeta.")) return false;
$meta_file = realpath($path . '.dbmeta.json');
if ($meta_file !== false) {
$meta = json_decode(file_get_contents($meta_file));
Expand Down Expand Up @@ -202,7 +202,7 @@ function downloadBatch(array $urls) {
$url = substr($local_path, strlen(PUBLIC_FOLDER)) . '/' . $file;

// always skip current folder '.' or parent folder '..' if current path is root or file should be ignored or .dbmeta.json
if ($file === '.' || $file === '..' && count($url_parts) === 0 || $file !== '..' && hidden($url) $[if `process.env.METADATA === "true"`]$|| str_contains($file, ".dbmeta.json")$[end]$) continue;
if ($file === '.' || $file === '..' && count($url_parts) === 0 || $file !== '..' && hidden($url) $[if `process.env.METADATA === "true"`]$|| str_contains($file, ".dbmeta.")$[end]$) continue;

$file_size = filesize($local_path . '/' . $file);

Expand Down Expand Up @@ -254,7 +254,7 @@ function downloadBatch(array $urls) {
if(isset($_REQUEST["ls"])) {
$info = [];
foreach ($sorted as $file) {
if ($file->name === "..") continue; // skip parent folder
if ($file->name === "..") continue; // skip parent folder
$info[] = [
"url" => $file->url,
"name" => $file->name,
Expand Down Expand Up @@ -286,7 +286,17 @@ function downloadBatch(array $urls) {
break;
}
}
$[end]$

$[if `process.env.README_RENDER === "true" && process.env.README_META === "true"`]$
// check if ".dbmeta.md" exists. overwrite previous readme
if (file_exists($local_path . '/.dbmeta.md')) {
$readme = new File();
$readme->url = substr($local_path, strlen(PUBLIC_FOLDER)) . '/.dbmeta.md';
}
$[end]$

$[if `process.env.README_RENDER === "true"`]$
if ($readme) {
$config = [];

Expand Down Expand Up @@ -782,7 +792,7 @@ function toggletheme() {
<div class="mt-auto">
<div class="container py-2 text-center" id="footer">
<?= $total_items ?> Items | <?= human_filesize($total_size) ?> $[if `process.env.TIMING === "true"`]$| <?= (hrtime(true) - $time_start)/1000000 ?> ms $[end]$$[if `process.env.API === "true"`]$| <a href="<?= '/' . implode(separator: '/', array: $url_parts) . '?ls' ?>" target="_blank"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-api"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 13h5" /><path d="M12 16v-8h3a2 2 0 0 1 2 2v1a2 2 0 0 1 -2 2h-3" /><path d="M20 8v8" /><path d="M9 16v-5.5a2.5 2.5 0 0 0 -5 0v5.5" /></svg></a>$[end]$<br>
<span style="opacity:0.8"><span style="opacity: 0.8;">Powered by</span> <a href="https://dir.adriansoftware.de" class="text-decoration-none text-primary" target="_blank">dir-browser</a> <?= VERSION ?></span>
<span style="opacity:0.8"><span style="opacity: 0.8;">Powered by</span> <a href="https://dir.adriansoftware.de" class="text-decoration-none text-primary" target="_blank">dir-browser</a> v<?= VERSION ?></span>
</div>
</div>
Expand Down

0 comments on commit 642a55f

Please sign in to comment.