Skip to content

Commit dbe33cb

Browse files
committed
feat: add metadata, custom description and labels
1 parent 0e9dc5a commit dbe33cb

File tree

8 files changed

+77
-6
lines changed

8 files changed

+77
-6
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ https://bp.adriansoftware.de
3434
- Secure by default. **Read-only** access
3535
- Extremly **fast** file serving through **nginx**
3636
- **README** markdown rendering support
37+
- add **custom description and labels** to files and folders
3738
- **Low memory** footprint (~10MB)
3839
- Light and **Darkmode**
3940
- Many **Themes** available
@@ -64,4 +65,10 @@ diretly embed pohpo in nginx maximum performance
6465
6566
- when path contains a dot it triggers full reload -> turbolinks
6667
68+
69+
TODO Features:
70+
- add descripton,labels metadata in item use <file/folder>.dbmeta.json
71+
72+
- replace github utpp download with npm i -g utpp
73+
6774
-->
File renamed without changes.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
sidebar_position: -1
3+
---
4+
5+
import Image from "@theme/IdealImage";
6+
7+
# Metadata
8+
9+
Files and folder can be enriched with metadata and displayed. Metadata is stored in a file called `<name>.dbmeta.json`, where `<name>` is the exact file/folder name, in the same folder as the file or folder. Metadata is stored in a JSON format specified below.
10+
11+
The `*.dbmeta.json` files are hidden from the user and cannot be viewed.
12+
13+
<!-- This feature is enabled by default. To disable this, set the environment variable `NO_METADATA` to `true` when starting the container. -->
14+
15+
<Image img={require("@site/static/img/metadata.png")} />
16+
17+
```json title="/foo bar/cool project.dbmeta.json"
18+
{
19+
"description": "A short project description ⭐",
20+
"labels": ["danger:Laravel", "primary:PHP 8", "dark:Hot 🔥"]
21+
}
22+
```
23+
<!-- TODO: "password": "mysecurepassword" -->
24+
25+
#### Labels
26+
27+
Labels always start with a style and a colon `:`, followed by the label text. The following styles are available:
28+
- `primary`
29+
- `secondary`
30+
- `success`
31+
- `danger`
32+
- `warning`
33+
- `info`
34+
- `light`
35+
- `dark`
36+

docs/docs/development/roadmap.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
sidebar_position: 1
33
---
44
# Roadmap
5-
- [ ] support timezones other than UTC e.g. EST
6-
- [ ] support relative timestamps e.g. '3 minutes ago'
5+
76
- [ ] File hashes
87
- [ ] i18n: more languages

docs/docs/intro.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ https://bp.adriansoftware.de
1616
- Secure by default. **Read-only** access
1717
- Extremly **fast** file serving through **nginx**
1818
- **README** markdown rendering support
19+
- add **custom description and labels** to files and folders
1920
- **Low memory** footprint (~10MB)
2021
- Light and **Darkmode**
2122
- File **icons**

docs/docusaurus.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ const config = {
211211
prism: {
212212
theme: lightCodeTheme,
213213
darkTheme: darkCodeTheme,
214-
additionalLanguages: ['php'],
214+
additionalLanguages: ['php','json'],
215215
magicComments: [
216216
{
217217
className: 'theme-code-block-highlighted-line',

docs/static/img/metadata.png

15 KB
Loading

src/index.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
define('VERSION', '2.2.1');
3+
define('VERSION', '2.3.0');
44

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

@@ -37,6 +37,7 @@ class File
3737
public bool $is_dir;
3838
public string $modified_date;
3939
public int $dl_count;
40+
public ?object $meta;
4041

4142
public function __toString(): string
4243
{
@@ -61,8 +62,8 @@ public function __toString(): string
6162
$sorted_files = [];
6263
$sorted_folders = [];
6364
foreach (($files = scandir($local_path)) as $file) {
64-
// always skip current folder '.' or parent folder '..' if current path is root or file should be ignored
65-
if ($file === '.' || $file === '..' && count($url_parts) === 0 $[if `process.env.IGNORE`]$|| $file !== '..' && fnmatch("${{`process.env.IGNORE ?? ""`}}$", $file)$[end]$) continue;
65+
// always skip current folder '.' or parent folder '..' if current path is root or file should be ignored or .dbmeta.json
66+
if ($file === '.' || $file === '..' && count($url_parts) === 0 $[if `process.env.IGNORE`]$|| $file !== '..' && fnmatch("${{`process.env.IGNORE ?? ""`}}$", $file)$[end]$ || str_contains($file, ".dbmeta.json")) continue;
6667

6768
$[if `process.env.IGNORE`]$
6869
foreach ($url_parts as $int_path) { /* check if parent folders are hidden */
@@ -82,13 +83,20 @@ public function __toString(): string
8283

8384
$file_modified_date = gmdate('Y-m-d\TH:i:s\Z', filemtime($local_path . '/' . $file));
8485

86+
// load metadata if file exists
87+
$meta_file = realpath($local_path . '/' . $file . '.dbmeta.json');
88+
if ($meta_file !== false) {
89+
$meta = json_decode(file_get_contents($meta_file));
90+
}
91+
8592
$item = new File();
8693
$item->name = $file;
8794
$item->url = $url;
8895
$item->size = human_filesize($file_size);
8996
$item->is_dir = $is_dir;
9097
$item->modified_date = $file_modified_date;
9198
$item->dl_count = $[if `!process.env.NO_DL_COUNT`]$!$is_dir ? $redis->get($url) :$[end]$ 0;
99+
$item->meta = $meta ?? null;
92100
if ($is_dir) {
93101
array_push($sorted_folders, $item);
94102
} else {
@@ -120,6 +128,9 @@ public function __toString(): string
120128
}
121129
$[end]$
122130
131+
// skip if file is .dbmeta.json
132+
if (str_contains($local_path, ".dbmeta.json")) goto skip;
133+
123134
// increment redis view counter
124135
$[if `!process.env.NO_DL_COUNT`]$
125136
$redis = new Redis();
@@ -265,7 +276,24 @@ public function __toString(): string
265276
</svg>
266277
</div>
267278
<?php } ?>
279+
<span>
268280
<?= $file->name ?>
281+
<?php
282+
if ($file->meta !== null) {
283+
if ($file->meta->description !== null) {
284+
?>
285+
<span class="text-body-secondary"><?= $file->meta->description ?></span>
286+
<?php
287+
}
288+
foreach ($file->meta->labels as $lbl) {
289+
$l = explode(":", $lbl, 2);
290+
?>
291+
<span class="badge bg-<?= $l[0] ?>"><?= $l[1] ?></span>
292+
<?php
293+
}
294+
}
295+
?>
296+
</span>
269297
<?php if (!$file->is_dir) { ?>
270298
$[if `!process.env.NO_DL_COUNT`]$
271299
<span class="ms-auto d-none d-md-block border rounded-1 text-end px-1 <?= $file->dl_count === 0 ? "text-body-tertiary" : "" ?>">

0 commit comments

Comments
 (0)