Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- run: |
mk python-release owner=libre-embedded \
repo=runtimepy version=5.15.6
repo=runtimepy version=5.15.7
if: |
matrix.python-version == '3.12'
&& matrix.system == 'ubuntu-latest'
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ mklocal
docs
compile_commands.json
src
*.webm
*.log
tmp
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
=====================================
generator=datazen
version=3.2.3
hash=0f8ffdbd46445346cb834d066f58e765
hash=fd0b9f87927033d8ee2eb5448d8aec76
=====================================
-->

# runtimepy ([5.15.6](https://pypi.org/project/runtimepy/))
# runtimepy ([5.15.7](https://pypi.org/project/runtimepy/))

[![python](https://img.shields.io/pypi/pyversions/runtimepy.svg)](https://pypi.org/project/runtimepy/)
![Build Status](https://github.com/libre-embedded/runtimepy/workflows/Python%20Package/badge.svg)
Expand Down
2 changes: 1 addition & 1 deletion local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
major: 5
minor: 15
patch: 6
patch: 7
entry: runtimepy
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"

[project]
name = "runtimepy"
version = "5.15.6"
version = "5.15.7"
description = "A framework for implementing Python services."
readme = "README.md"
requires-python = ">=3.12"
Expand Down
4 changes: 2 additions & 2 deletions runtimepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.2.3
# hash=08c1dda8bd5fefe13af6a8eb49063498
# hash=7591d3ee09b156575678bdf806e1b5c7
# =====================================

"""
Expand All @@ -10,7 +10,7 @@

DESCRIPTION = "A framework for implementing Python services."
PKG_NAME = "runtimepy"
VERSION = "5.15.6"
VERSION = "5.15.7"

# runtimepy-specific content.
METRICS_NAME = "metrics"
Expand Down
4 changes: 4 additions & 0 deletions runtimepy/data/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ body > :first-child {
.channel-filter-min-width {
min-width: 5.5em;
}

.media-preview {
max-width: 70vw;
}
45 changes: 37 additions & 8 deletions runtimepy/net/server/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# built-in
from io import StringIO
import mimetypes
from os import stat_result
from pathlib import Path
from typing import Iterable, cast

Expand All @@ -17,19 +18,46 @@

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


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

preview = ""

if path.is_file():
mime, _ = mimetypes.guess_type(path, strict=False)
if mime and mime.startswith("image"):
preview = div(tag="img", src=f"/{link}", alt=str(link)).encode_str(
newlines=False
)
if not path.is_file():
return preview

mime, _ = mimetypes.guess_type(path, strict=False)
if mime:
# Image previews.
if mime.startswith("image"):
preview = div(
tag="img",
src=f"/{link}",
alt=str(link),
class_str="media-preview",
).encode_str(newlines=False)

# Video previews.
elif mime.startswith("video"):
elem = div(tag="video", class_str="media-preview")
elem.booleans.add("loop")
elem.booleans.add("controls")

if stats.st_size < AUTOPLAY_PREVIEW_SIZE:
elem.booleans.add("autoplay")

div(parent=elem, tag="source", src=f"/{link}", type=mime)

preview = elem.encode_str(newlines=False)

# Audio previews.
elif mime.startswith("audio"):
elem = div(tag="audio", src=f"/{link}")
elem.booleans.add("controls")
preview = elem.encode_str(newlines=False)

return preview

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

writer.write(
f"| [{name}](/{curr}) | {size_str} | {file_preview(item, curr)} |"
f"| [{name}](/{curr}) | {size_str} | "
f"{file_preview(item, curr, stats)} |"
)

writer.empty()
Expand Down
Binary file added tests/data/rotate.webm
Binary file not shown.
Binary file added tests/data/start.wav
Binary file not shown.
Binary file added tests/data/stop.wav
Binary file not shown.
1 change: 1 addition & 0 deletions tests/net/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async def runtimepy_http_client_server(
# Application.
client.request(RequestHeader(target="/")),
client.request(RequestHeader(target="/tests")),
client.request(RequestHeader(target="/tests/data")),
client.request(RequestHeader(target="/app.html")),
client.request(RequestHeader(target="/app.html")),
client.request(RequestHeader(target="/mux.html")),
Expand Down