Homepage rework

This commit is contained in:
Bradley committed 2026-11-13 22:29:30 -05:00
1 parent 554b7cc82c
commit db8226b980
6 files changed
+521 -41

No files matched your search

+20 -6
View File
@@ -12,6 +12,20 @@ Simple Goal List
- Ahead of time uploading of pictures and videos from external devices
- USB media awareness/playback
## Home dashboard
The homepage groups tasks into playback, adding media, and checking download
activity. **Open media library** is the main playback action; the four media
cards lead to image uploads, video uploads, stream configuration, and YouTube
requests. **View download jobs** opens the download queue. TV and screen controls
are explicitly marked coming soon rather than shown as working buttons.
A selection panel checks the existing playback-status endpoint every five seconds.
It shows the requested selection, not proof that the player is running. If status
is unavailable, navigation still works; without JavaScript, the panel directs
users to the library. The responsive homepage uses local styles/icons and keeps
the original beige background.
## Fullscreen player
Install FFplay (usually provided by FFmpeg), then run the player in the graphical
@@ -47,7 +61,7 @@ Ctrl+C or SIGTERM stops the child process; a child that ignores termination is
killed after two seconds. The player does not modify the database and currently
does not apply `media_playback_option` records.
Use **Play Media** from the home page to select an item in the unified library.
Use **Open media library** from the home page to select an item in the unified library.
Alternatively, set selection flags directly in SQLite. For example, select media
ID 3 without temporarily leaving several active rows:
@@ -65,7 +79,7 @@ just an SSH shell without display access.
## Media library and playback selection
Open **Play Media** from the homepage, or visit `/media`. All media types share
Choose **Open media library** from the homepage, or visit `/media`. All media types share
one page, with a **Play** button per item and image/video/stream icons. Clicking
Play clears the previous active selection and activates the new item in a single
database transaction; default flags are preserved. The separate player picks up
@@ -120,7 +134,7 @@ an incomplete media entry. Retrying a failed upload starts it from the beginning
## Uploading local videos
Use **Upload a Video** on the home page, or visit `/upload/video`. Enter a display
Use **Upload a video** on the home page, or visit `/upload/video`. Enter a display
name and select one video. The limit is 5GB (5 × 1024³ bytes), checked both in the
browser and on the server. Common formats including MP4, MKV, MOV, WebM, AVI,
MPEG, and WMV are accepted by extension. Before saving, FFprobe checks for a
@@ -146,7 +160,7 @@ space for both Flask's temporary upload and the final video file.
## Uploading static images
Use **Upload a Static Image** on the home page, or visit `/upload/photo`. Enter
Use **Upload an image** on the home page, or visit `/upload/photo`. Enter
an image name and choose one JPG/JPEG, PNG, WebP, BMP, TIFF, or GIF file. Files
are checked against their extensions and decoded for validation. Images may be
animated, but only the first frame is checked; dimensions are limited to 50
@@ -195,7 +209,7 @@ The default `Videos/` folder is excluded from Git.
### Web interface
Start the Flask app with `python3 sc_webserver.py` and use the home page's
**Get Video from YouTube** link, or visit `/youtube/download`. Enter a media name
**Get a YouTube video** link, or visit `/youtube/download`. Enter a media name
and a YouTube video URL to queue a job. Invalid submissions show an error without
creating a job; successful submissions redirect to `/youtube/jobs`.
@@ -262,5 +276,5 @@ WHERE youtube_download_job_id = 123
Run the database and worker tests without downloading any videos:
```sh
python3 -m unittest test.youtube_download_job_test test.youtube_download_web_test test.upload_video_test test.upload_photo_test test.player_test test.media_library_test test.submission_validation_test -v
python3 -m unittest test.youtube_download_job_test test.youtube_download_web_test test.upload_video_test test.upload_photo_test test.player_test test.media_library_test test.submission_validation_test test.home_test -v
```
+3 -3
View File
@@ -9,8 +9,8 @@ an FFplay-based player with unified playback selection; device control is still
- [x] Set up a Flask web server with configuration loaded from `config.json`.
- [x] Organize implemented pages into Flask blueprints.
- [x] Build a Bootstrap-based home page with controls grouped into common tools,
playback, and media submission.
- [x] Build a responsive home dashboard with a primary playback action, grouped
media-submission cards, download activity, and a live selection summary.
- [x] Create the configured upload directory automatically when the server starts.
- [x] Upload named static images (up to 100MB) to the configurable `Images` folder,
show progress and navigation warnings, and return home after saving the file
@@ -29,7 +29,7 @@ an FFplay-based player with unified playback selection; device control is still
- [x] Link the home page to a unified media library with Play buttons, live selection
indicators, media-type icons, and cached local image/video thumbnails.
- [ ] Connect the existing placeholder controls to backend actions.
- [ ] Implement backend actions for TV and screen controls currently marked coming soon.
- [x] Add input validation for media names, duplicate names, stream URLs, and
uploaded files.
- [ ] Ensure upload destinations remain inside the configured upload directory.
+122 -32
View File
@@ -1,38 +1,128 @@
{% macro icon(name) -%}
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
{% if name == 'image' %}
<rect x="3" y="4" width="18" height="16" rx="2"/><circle cx="8" cy="9" r="1.5"/><path d="m4 17 5-5 3.5 3.5 2.5-2.5 5 5"/>
{% elif name == 'video' %}
<rect x="3" y="5" width="18" height="14" rx="2"/><path d="m10 9 5 3-5 3z"/>
{% elif name == 'stream' %}
<circle cx="12" cy="12" r="2"/><path d="M8.5 8.5a5 5 0 0 0 0 7m7-7a5 5 0 0 1 0 7M5.5 5.5a9 9 0 0 0 0 13m13-13a9 9 0 0 1 0 13"/>
{% elif name == 'youtube' %}
<rect x="3" y="6" width="18" height="12" rx="3"/><path d="m10 9.5 4.5 2.5-4.5 2.5z"/>
{% elif name == 'download' %}
<path d="M12 3v11m-4-4 4 4 4-4M4 16v3a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-3"/>
{% elif name == 'screen' %}
<rect x="3" y="4" width="18" height="14" rx="2"/><path d="M8 21h8m-4-3v3"/>
{% elif name == 'arrow' %}
<path d="M4 12h15m-5-5 5 5-5 5"/>
{% endif %}
</svg>
{%- endmacro %}
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<title>Video Commander</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" type="text/css" href="../static/style.css">
<title>Sanctuary Commander</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='home.css') }}">
<script src="{{ url_for('static', filename='home.js') }}" defer></script>
</head>
<body>
<div class="container">
<h1 class="text-center">Sanctuary Commander</h1>
<hr>
<h3 class="text-center">Common Tools</h3>
<div class="row">
<button class="col-sm-4 btn btn-secondary p-3 my-1">Toggle TVs On/Off</button>
<button class="col-sm-4 btn btn-secondary p-3 my-1">Disable Video</button>
<button class="col-sm-4 btn btn-secondary p-3 my-1">Blackout Screen</button>
</div>
<hr>
<h3 class="text-center">Play Something</h3>
<div class="row">
<a class="col-sm-4 btn btn-primary p-3 my-1" href="{{ url_for('media_library.media_list') }}">Play Media</a>
</div>
<hr>
<h3 class="text-center">Add Something</h3>
<div class="row">
<a class="col-sm-4 btn btn-secondary p-3 my-1" href="/upload/photo">Upload a Static Image</a>
<a class="col-sm-4 btn btn-secondary p-3 my-1" href="/configure/stream">Configure a Stream</a>
</div>
<div class="row">
<a class="col-sm-4 btn btn-secondary p-3 my-1" href="{{ url_for('upload_video.get_page') }}">Upload a Video</a>
<a class="col-sm-4 btn btn-secondary p-3 my-1" href="{{ url_for('youtube_download.request_download') }}">Get Video from YouTube</a>
<a class="col-sm-4 btn btn-secondary p-3 my-1" href="{{ url_for('youtube_download.list_jobs') }}">YouTube Download Jobs</a>
</div>
<body class="home-page">
<div class="home-shell">
<header class="home-header">
<a class="brand" href="{{ url_for('home.root_route') }}" aria-label="Sanctuary Commander home">
<span class="brand-mark">{{ icon('screen') }}</span>
<span class="brand-name">Sanctuary <span>Commander</span></span>
</a>
<span class="header-label">MEDIA CONTROL <span aria-hidden="true">/</span> HOME</span>
</header>
<main>
<section class="hero" aria-labelledby="home-title">
<div class="hero-copy">
<p class="eyebrow"><span class="eyebrow-line" aria-hidden="true"></span> YOUR CONTROL CENTER</p>
<h1 id="home-title">Your media,<br><em>ready for the moment.</em></h1>
<p class="hero-description">Choose what’s on screen, prepare content ahead of time, and keep everything in one place.</p>
<a class="primary-link" href="{{ url_for('media_library.media_list') }}">
Open media library <span class="link-arrow">{{ icon('arrow') }}</span>
</a>
</div>
<aside class="selection-card" aria-labelledby="selection-heading"
data-selection-url="{{ url_for('media_library.playback_status') }}">
<div class="selection-topline">
<span id="selection-heading" class="selection-label">PLAYBACK SELECTION</span>
<span class="selection-sparkle" aria-hidden="true">✳</span>
</div>
<div class="selection-visual" aria-hidden="true">
<div class="screen-art">
<span class="screen-art-play"><svg viewBox="0 0 24 24" fill="currentColor"><path d="m9 6 10 6-10 6z"/></svg></span>
<span class="screen-art-line"></span>
</div>
<span class="screen-art-base"></span>
</div>
<div class="selection-content" aria-live="polite" aria-atomic="true">
<p class="selection-caption">CURRENT SELECTION</p>
<p id="home-selection" class="selection-name">Open your library to view the selection.</p>
<p id="home-selection-detail" class="selection-detail">The player runs separately on your display.</p>
</div>
</aside>
</section>
<section class="prepare-section" aria-labelledby="prepare-heading">
<div class="section-heading">
<div>
<p class="eyebrow">BUILD YOUR LIBRARY</p>
<h2 id="prepare-heading">Add something new<span class="heading-period">.</span></h2>
</div>
<p>Get your content ready before you need it.</p>
</div>
<div class="action-grid">
<a class="action-card" href="{{ url_for('upload_photo.get_page') }}">
<span class="action-icon icon-image">{{ icon('image') }}</span>
<span class="action-card-copy"><span class="action-title">Upload an image</span><span class="action-description">Add a photo or slide from your device.</span></span>
<span class="action-arrow">{{ icon('arrow') }}</span>
</a>
<a class="action-card" href="{{ url_for('upload_video.get_page') }}">
<span class="action-icon icon-video">{{ icon('video') }}</span>
<span class="action-card-copy"><span class="action-title">Upload a video</span><span class="action-description">Save a video for playback later.</span></span>
<span class="action-arrow">{{ icon('arrow') }}</span>
</a>
<a class="action-card" href="{{ url_for('configure_stream.get_page') }}">
<span class="action-icon icon-stream">{{ icon('stream') }}</span>
<span class="action-card-copy"><span class="action-title">Connect a stream</span><span class="action-description">Add a live or network stream.</span></span>
<span class="action-arrow">{{ icon('arrow') }}</span>
</a>
<a class="action-card" href="{{ url_for('youtube_download.request_download') }}">
<span class="action-icon icon-youtube">{{ icon('youtube') }}</span>
<span class="action-card-copy"><span class="action-title">Get a YouTube video</span><span class="action-description">Download a video to play offline.</span></span>
<span class="action-arrow">{{ icon('arrow') }}</span>
</a>
</div>
</section>
<section class="download-panel" aria-labelledby="downloads-heading">
<span class="download-icon">{{ icon('download') }}</span>
<div class="download-copy">
<p class="eyebrow">DOWNLOAD ACTIVITY</p>
<h2 id="downloads-heading">YouTube downloads</h2>
<p>Review pending, in-progress, and failed downloads.</p>
</div>
<a class="secondary-link" href="{{ url_for('youtube_download.list_jobs') }}">
View download jobs <span class="link-arrow">{{ icon('arrow') }}</span>
</a>
</section>
<section class="upcoming-panel" aria-labelledby="upcoming-heading">
<span class="upcoming-icon">{{ icon('screen') }}</span>
<div>
<div class="upcoming-title-row"><h2 id="upcoming-heading">TV &amp; screen controls</h2><span class="upcoming-tag">COMING SOON</span></div>
<p>TV power, disable video, and blackout controls aren’t available yet.</p>
</div>
</section>
</main>
<footer class="home-footer"><span>Sanctuary Commander</span><span>MEDIA CONTROL, MADE SIMPLE</span></footer>
</div>
</body>
</html>
</html>
+250
View File
@@ -0,0 +1,250 @@
/* Homepage styles are scoped to .home-page; the rest of the app keeps its own layout. */
.home-page {
color: #293b34;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
margin: 0;
-webkit-font-smoothing: antialiased;
}
.home-page *, .home-page *::before, .home-page *::after {
box-sizing: border-box;
}
.home-page a {
color: inherit;
text-decoration: none;
}
.home-page a:focus-visible {
outline: 3px solid #8a5735;
outline-offset: 4px;
}
.home-shell {
width: min(100% - 80px, 1220px);
margin: 0 auto;
}
.home-header {
display: flex;
justify-content: space-between;
align-items: center;
min-height: 94px;
border-bottom: 1px solid rgba(65, 68, 52, .19);
}
.brand {
display: inline-flex;
gap: 12px;
align-items: center;
}
.brand-mark, .action-icon, .download-icon, .upcoming-icon {
display: grid;
place-items: center;
flex: none;
}
.brand-mark {
width: 39px;
height: 39px;
border-radius: 11px;
background: #344c40;
color: #fffaf0;
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-name { font-family: Georgia, "Times New Roman", serif; font-weight: 700; font-size: 19px; letter-spacing: -.5px; }
.brand-name span { font-weight: 400; }
.header-label { color: #6b6858; font-size: 10px; letter-spacing: .16em; font-weight: 700; }
.header-label span { margin: 0 9px; color: #9d8f75; }
.hero {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(300px, 405px);
gap: clamp(40px, 7vw, 110px);
align-items: center;
padding: 74px 0 82px;
}
.eyebrow {
margin: 0;
color: #756b56;
font-size: 10px;
font-weight: 750;
letter-spacing: .16em;
line-height: 1.4;
}
.hero-copy > .eyebrow { display: flex; align-items: center; gap: 10px; }
.eyebrow-line { width: 25px; height: 2px; background: #a17d55; }
.hero h1, .section-heading h2 {
font-family: Georgia, "Times New Roman", serif;
font-weight: 400;
letter-spacing: -.045em;
}
.hero h1 {
margin: 24px 0 20px;
color: #293c32;
font-size: clamp(42px, 5.35vw, 72px);
line-height: 1.06;
}
.hero h1 em { color: #8a694d; font-weight: 400; }
.hero-description { max-width: 460px; margin: 0 0 30px; color: #5e6255; font-size: 17px; line-height: 1.7; }
.primary-link, .secondary-link {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 24px;
min-height: 52px;
padding: 13px 17px 13px 20px;
border-radius: 8px;
font-size: 14px;
font-weight: 700;
transition: background-color .18s ease, transform .18s ease;
}
.home-page .primary-link { background: #344c40; color: #fffdf7; }
.primary-link:hover { background: #22372c; transform: translateY(-2px); }
.link-arrow, .action-arrow { display: inline-flex; flex: none; }
.link-arrow svg, .action-arrow svg { width: 18px; height: 18px; }
.selection-card {
position: relative;
overflow: hidden;
min-width: 0;
padding: 26px 29px 28px;
border: 1px solid rgba(255, 255, 255, .12);
border-radius: 16px;
background: #334b3f;
box-shadow: 0 18px 36px rgba(63, 57, 39, .13);
color: #fff9ec;
}
.selection-card::after {
content: "";
position: absolute;
width: 250px;
height: 250px;
right: -105px;
top: -150px;
border: 1px solid rgba(237, 228, 202, .13);
border-radius: 50%;
box-shadow: 0 0 0 38px rgba(237, 228, 202, .025), 0 0 0 76px rgba(237, 228, 202, .025);
pointer-events: none;
}
.selection-topline { display: flex; align-items: center; justify-content: space-between; }
.selection-label, .selection-caption { font-size: 10px; font-weight: 700; letter-spacing: .16em; }
.selection-label { color: #e4d9bc; }
.selection-sparkle { color: #dbc998; font-size: 23px; line-height: 1; }
.selection-visual { display: flex; flex-direction: column; align-items: center; padding: 27px 0 21px; }
.screen-art { position: relative; display: grid; place-items: center; width: 138px; height: 83px; border: 1px solid rgba(240, 231, 205, .44); border-radius: 7px; background: rgba(255, 255, 255, .035); }
.screen-art-play { display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid rgba(240, 231, 205, .48); border-radius: 50%; color: #eee2c7; }
.screen-art-play svg { width: 15px; height: 15px; margin-left: 2px; }
.screen-art-line { position: absolute; right: 8px; bottom: 8px; left: 8px; height: 1px; background: rgba(240, 231, 205, .25); }
.screen-art-base { width: 44px; height: 7px; border-bottom: 1px solid rgba(240, 231, 205, .45); border-left: 1px solid rgba(240, 231, 205, .45); border-right: 1px solid rgba(240, 231, 205, .45); }
.selection-content { border-top: 1px solid rgba(240, 231, 205, .17); padding-top: 17px; }
.selection-caption { margin: 0 0 7px; color: #dfd0b1; }
.selection-name { margin: 0; color: #fffdf6; font-size: 17px; font-weight: 650; line-height: 1.35; overflow-wrap: anywhere; }
.selection-detail { margin: 7px 0 0; color: #e0e4d6; font-size: 12px; line-height: 1.55; }
.prepare-section { padding-bottom: 22px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 25px; }
.section-heading h2 { margin: 7px 0 0; color: #293c32; font-size: clamp(30px, 3vw, 40px); line-height: 1.15; }
.heading-period { color: #a47a54; }
.section-heading > p { margin: 0 0 4px; color: #646758; font-size: 14px; line-height: 1.5; }
.action-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.home-page .action-card {
position: relative;
display: flex;
flex-direction: column;
min-height: 198px;
padding: 21px;
border: 1px solid rgba(105, 99, 80, .16);
border-radius: 12px;
background: #f8f5ec;
box-shadow: 0 3px 10px rgba(73, 66, 49, .035);
transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.action-card:hover { transform: translateY(-3px); border-color: #a6a289; box-shadow: 0 10px 20px rgba(73, 66, 49, .09); }
.action-icon { width: 43px; height: 43px; margin-bottom: 19px; border-radius: 10px; }
.action-icon svg, .download-icon svg, .upcoming-icon svg { width: 22px; height: 22px; }
.icon-image { background: #e5eadc; color: #46664c; }
.icon-video { background: #e7e3d8; color: #655b4c; }
.icon-stream { background: #e0e9e3; color: #41675a; }
.icon-youtube { background: #f0e1d7; color: #94563f; }
.action-card-copy { display: flex; flex-direction: column; padding-right: 12px; }
.action-title { color: #2c3d34; font-size: 15px; font-weight: 700; line-height: 1.35; }
.action-description { max-width: 190px; margin-top: 7px; color: #666c5e; font-size: 13px; line-height: 1.5; }
.action-arrow { position: absolute; right: 20px; bottom: 20px; color: #697a67; }
.download-panel {
display: flex;
align-items: center;
gap: 18px;
padding: 22px 24px;
border: 1px solid rgba(105, 99, 80, .16);
border-radius: 12px;
background: #f2ede0;
}
.download-icon { width: 45px; height: 45px; border-radius: 10px; background: #e1ded0; color: #4d6150; }
.download-copy { flex: 1; min-width: 0; }
.download-copy h2 { margin: 5px 0 3px; font-size: 16px; line-height: 1.3; }
.download-copy > p:last-child { margin: 0; color: #64695b; font-size: 13px; line-height: 1.5; }
.home-page .secondary-link { flex: none; gap: 14px; border: 1px solid #a2a394; background: transparent; color: #344c40; font-size: 13px; }
.secondary-link:hover { background: #e5e5d8; }
.upcoming-panel { display: flex; align-items: flex-start; gap: 12px; margin-top: 29px; padding: 0 2px; }
.upcoming-icon { width: 24px; height: 24px; color: #777b6c; }
.upcoming-icon svg { width: 20px; height: 20px; }
.upcoming-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.upcoming-title-row h2 { margin: 0; color: #525c50; font-size: 13px; line-height: 24px; }
.upcoming-tag { padding: 3px 7px; border: 1px solid #b6ac95; border-radius: 4px; color: #6d695b; font-size: 9px; font-weight: 700; letter-spacing: .09em; }
.upcoming-panel p { margin: 2px 0 0; color: #666b5e; font-size: 12px; line-height: 1.5; }
.home-footer { display: flex; justify-content: space-between; gap: 16px; margin-top: 45px; padding: 21px 0 28px; border-top: 1px solid rgba(65, 68, 52, .19); color: #6e6c5d; font-size: 11px; }
.home-footer span:last-child { font-size: 9px; font-weight: 700; letter-spacing: .14em; }
@media (max-width: 900px) {
.hero { gap: 35px; }
.action-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.action-card { min-height: 178px; }
}
@media (max-width: 640px) {
.home-shell { width: min(100% - 36px, 500px); }
.home-header { min-height: 76px; }
.header-label { display: none; }
.hero { grid-template-columns: 1fr; gap: 32px; padding: 48px 0 52px; }
.hero h1 { margin-top: 20px; font-size: clamp(40px, 10vw, 55px); }
.hero-description { font-size: 16px; }
.selection-card { padding: 22px; }
.selection-visual { padding: 20px 0; }
.section-heading { display: block; }
.section-heading > p { margin-top: 9px; }
.action-grid { gap: 10px; }
.home-page .action-card { min-height: 190px; padding: 16px; }
.action-arrow { right: 15px; bottom: 15px; }
.download-panel { flex-wrap: wrap; gap: 13px; padding: 18px; }
.download-copy { flex: 1 1 calc(100% - 60px); }
.home-page .secondary-link { width: 100%; }
.home-footer { margin-top: 35px; }
}
@media (max-width: 360px) {
.action-grid { grid-template-columns: 1fr; }
.home-page .action-card { min-height: 156px; }
.home-footer span:last-child { display: none; }
}
@media (prefers-reduced-motion: reduce) {
.home-page .primary-link, .home-page .secondary-link, .home-page .action-card { transition: none; }
.home-page .primary-link:hover, .home-page .action-card:hover { transform: none; }
}
+27
View File
@@ -0,0 +1,27 @@
const selectionCard = document.querySelector('[data-selection-url]')
const selectionName = document.getElementById('home-selection')
const selectionDetail = document.getElementById('home-selection-detail')
function updateSelectionText(element, text) {
// Avoid repeated screen-reader announcements when the selection hasn't changed.
if (element.textContent !== text) element.textContent = text
}
async function refreshHomeSelection() {
try {
const response = await fetch(selectionCard.dataset.selectionUrl, {cache: 'no-store'})
if (!response.ok) throw new Error('Selection unavailable')
const state = await response.json()
updateSelectionText(selectionName, state.blank ? 'Blank screen selected' : state.selected_name)
updateSelectionText(selectionDetail, state.using_default && !state.blank
? 'Default selection. The player runs separately on your display.'
: 'This is the requested selection; the player runs separately on your display.')
} catch (error) {
updateSelectionText(selectionName, 'Selection unavailable')
updateSelectionText(selectionDetail, 'Open the media library to try again.')
} finally {
window.setTimeout(refreshHomeSelection, 5000)
}
}
refreshHomeSelection()
+99
View File
@@ -0,0 +1,99 @@
from html.parser import HTMLParser
import json
import os
from pathlib import Path
import runpy
import subprocess
import sys
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
class HomeElements(HTMLParser):
def __init__(self):
super().__init__()
self.links = []
self.buttons = []
self.headings = []
self.selection_url = None
def handle_starttag(self, tag, attrs):
attrs = dict(attrs)
if tag == 'a':
self.links.append(attrs.get('href'))
if tag == 'button':
self.buttons.append(attrs)
if tag in ('h1', 'h2'):
self.headings.append(tag)
if 'data-selection-url' in attrs:
self.selection_url = attrs['data-selection-url']
class HomeTest(unittest.TestCase):
def setUp(self):
self.directory = tempfile.TemporaryDirectory()
self.addCleanup(self.directory.cleanup)
self.workdir = Path(self.directory.name)
(self.workdir / 'config.json').write_text(json.dumps({
'database': {'type': 'SQLite', 'name': 'test.db'},
'upload_location': 'uploads'
}))
subprocess.run([sys.executable, str(ROOT / 'sc_database_generator.py')],
cwd=self.workdir, check=True, capture_output=True)
original = Path.cwd()
try:
os.chdir(self.workdir)
self.app = runpy.run_path(str(ROOT / 'sc_webserver.py'))['app']
finally:
os.chdir(original)
self.app.config['TESTING'] = True
self.client = self.app.test_client()
def test_working_actions_are_grouped_and_all_destinations_work(self):
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
elements = HomeElements()
elements.feed(response.get_data(as_text=True))
self.assertCountEqual(elements.links, ['/', '/media', '/upload/photo', '/upload/video',
'/configure/stream', '/youtube/download', '/youtube/jobs'])
self.assertEqual(elements.buttons, []) # No deceptively enabled placeholder controls.
self.assertEqual(elements.headings.count('h1'), 1)
self.assertEqual(elements.selection_url, '/media/status')
for link in elements.links:
with self.subTest(link=link):
self.assertEqual(self.client.get(link).status_code, 200)
self.assertIn(b'COMING SOON', response.data)
self.assertIn(b'TV &amp; screen controls', response.data)
self.assertIn(b'<title>Sanctuary Commander</title>', response.data)
def test_home_uses_local_assets_and_preserves_original_background(self):
home = self.client.get('/')
for asset in ('style.css', 'home.css', 'home.js'):
self.assertIn(f'/static/{asset}'.encode(), home.data)
with self.client.get(f'/static/{asset}') as response:
self.assertEqual(response.status_code, 200)
self.assertNotIn(b'cdn.jsdelivr', home.data)
with self.client.get('/static/style.css') as response:
self.assertIn(b'background-color: #ebe1c7 !important', response.data)
with self.client.get('/static/home.css') as response:
self.assertIn(b'@media (max-width: 640px)', response.data)
self.assertIn(b'prefers-reduced-motion', response.data)
self.assertIn(b':focus-visible', response.data)
def test_home_navigation_survives_database_failure(self):
# Only the optional status panel depends on the database, not navigation.
from unittest.mock import patch
import sqlite3
with patch('utilities.database.sqlite.SQLite.query', side_effect=sqlite3.OperationalError('Unavailable')):
self.assertEqual(self.client.get('/').status_code, 200)
with self.assertLogs(self.app.logger, level='ERROR'):
response = self.client.get('/media/status')
self.assertEqual(response.status_code, 503)
self.assertEqual(response.json['status'], 'FAILED')
if __name__ == '__main__':
unittest.main()