Skip to content

Commit 1471cf8

Browse files
authored
5.15.7 - More dir view previews (#336)
1 parent 1700432 commit 1471cf8

File tree

12 files changed

+49
-16
lines changed

12 files changed

+49
-16
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
7979
- run: |
8080
mk python-release owner=libre-embedded \
81-
repo=runtimepy version=5.15.6
81+
repo=runtimepy version=5.15.7
8282
if: |
8383
matrix.python-version == '3.12'
8484
&& matrix.system == 'ubuntu-latest'

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ mklocal
1717
docs
1818
compile_commands.json
1919
src
20-
*.webm
2120
*.log
2221
tmp

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
=====================================
33
generator=datazen
44
version=3.2.3
5-
hash=0f8ffdbd46445346cb834d066f58e765
5+
hash=fd0b9f87927033d8ee2eb5448d8aec76
66
=====================================
77
-->
88

9-
# runtimepy ([5.15.6](https://pypi.org/project/runtimepy/))
9+
# runtimepy ([5.15.7](https://pypi.org/project/runtimepy/))
1010

1111
[![python](https://img.shields.io/pypi/pyversions/runtimepy.svg)](https://pypi.org/project/runtimepy/)
1212
![Build Status](https://github.com/libre-embedded/runtimepy/workflows/Python%20Package/badge.svg)

local/variables/package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
major: 5
33
minor: 15
4-
patch: 6
4+
patch: 7
55
entry: runtimepy

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"
44

55
[project]
66
name = "runtimepy"
7-
version = "5.15.6"
7+
version = "5.15.7"
88
description = "A framework for implementing Python services."
99
readme = "README.md"
1010
requires-python = ">=3.12"

runtimepy/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# =====================================
22
# generator=datazen
33
# version=3.2.3
4-
# hash=08c1dda8bd5fefe13af6a8eb49063498
4+
# hash=7591d3ee09b156575678bdf806e1b5c7
55
# =====================================
66

77
"""
@@ -10,7 +10,7 @@
1010

1111
DESCRIPTION = "A framework for implementing Python services."
1212
PKG_NAME = "runtimepy"
13-
VERSION = "5.15.6"
13+
VERSION = "5.15.7"
1414

1515
# runtimepy-specific content.
1616
METRICS_NAME = "metrics"

runtimepy/data/css/main.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,7 @@ body > :first-child {
8282
.channel-filter-min-width {
8383
min-width: 5.5em;
8484
}
85+
86+
.media-preview {
87+
max-width: 70vw;
88+
}

runtimepy/net/server/markdown.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# built-in
66
from io import StringIO
77
import mimetypes
8+
from os import stat_result
89
from pathlib import Path
910
from typing import Iterable, cast
1011

@@ -17,19 +18,46 @@
1718

1819
LOGO_MARKDOWN = "[![logo](/static/png/chip-circle-bootstrap/128x128.png)](/)"
1920
DIR_FILE = "dir.html"
21+
AUTOPLAY_PREVIEW_SIZE = 100 * (1024 * 1024) # 100 MiB
2022

2123

22-
def file_preview(path: Path, link: Path) -> str:
24+
def file_preview(path: Path, link: Path, stats: stat_result) -> str:
2325
"""Get possible preview text for a file."""
2426

2527
preview = ""
2628

27-
if path.is_file():
28-
mime, _ = mimetypes.guess_type(path, strict=False)
29-
if mime and mime.startswith("image"):
30-
preview = div(tag="img", src=f"/{link}", alt=str(link)).encode_str(
31-
newlines=False
32-
)
29+
if not path.is_file():
30+
return preview
31+
32+
mime, _ = mimetypes.guess_type(path, strict=False)
33+
if mime:
34+
# Image previews.
35+
if mime.startswith("image"):
36+
preview = div(
37+
tag="img",
38+
src=f"/{link}",
39+
alt=str(link),
40+
class_str="media-preview",
41+
).encode_str(newlines=False)
42+
43+
# Video previews.
44+
elif mime.startswith("video"):
45+
elem = div(tag="video", class_str="media-preview")
46+
elem.booleans.add("loop")
47+
elem.booleans.add("controls")
48+
49+
if stats.st_size < AUTOPLAY_PREVIEW_SIZE:
50+
elem.booleans.add("autoplay")
51+
52+
div(parent=elem, tag="source", src=f"/{link}", type=mime)
53+
54+
preview = elem.encode_str(newlines=False)
55+
56+
# Audio previews.
57+
elif mime.startswith("audio"):
58+
elem = div(tag="audio", src=f"/{link}")
59+
elem.booleans.add("controls")
60+
preview = elem.encode_str(newlines=False)
3361

3462
return preview
3563

@@ -65,7 +93,8 @@ def write_markdown_dir(
6593
size_str = byte_count_str(stats.st_size) if item.is_file() else ""
6694

6795
writer.write(
68-
f"| [{name}](/{curr}) | {size_str} | {file_preview(item, curr)} |"
96+
f"| [{name}](/{curr}) | {size_str} | "
97+
f"{file_preview(item, curr, stats)} |"
6998
)
7099

71100
writer.empty()

tests/data/rotate.webm

2.88 MB
Binary file not shown.

tests/data/start.wav

461 KB
Binary file not shown.

0 commit comments

Comments
 (0)