feat(preview): add file preview page with metadata and styling
All checks were successful
Build and Publish Docker Image / deploy (push) Successful in 1m48s

Implement a rich file preview interface to allow users to view file
contents directly in the browser.

Changes include:
- Exposing raw file size (`SizeBytes`) in the download handler's file view.
- Adding comprehensive CSS styling for the preview layout and cards.
- Integrating Prism.js for syntax highlighting of code files.
- Updating Content Security Policy (CSP) headers to permit inline styles and frame sources required by the preview components.
- Adding unit tests to ensure preview metadata attributes are correctly rendered on the download page.
This commit is contained in:
2026-06-03 14:28:50 +03:00
parent e17c5e92a7
commit 3a0dd04e61
12 changed files with 1893 additions and 36 deletions

View File

@@ -15,6 +15,374 @@
text-align: center;
}
.preview-view {
width: min(72rem, calc(100% - 2rem));
min-height: auto;
padding-block: clamp(2rem, 7vh, 4.5rem);
display: block;
}
.preview-card {
width: 100%;
margin: 0 auto;
text-align: left;
}
.preview-card .card-content {
padding: clamp(1rem, 2.4vw, 1.5rem);
}
.preview-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 1rem;
margin-bottom: 1rem;
}
.preview-title-group {
min-width: 0;
}
.preview-header .file-name {
margin: 0;
font-size: clamp(1.35rem, 2.4vw, 2rem);
line-height: 1.12;
}
.preview-header .download-subtitle {
margin: 0.45rem 0 0;
}
.preview-window {
overflow: hidden;
border: 1px solid color-mix(in srgb, var(--border) 78%, var(--primary));
border-radius: var(--radius);
background:
linear-gradient(180deg, color-mix(in srgb, var(--card) 94%, transparent), color-mix(in srgb, var(--background) 92%, transparent));
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}
.preview-window-titlebar {
min-height: 3rem;
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding: 0.72rem 0.9rem;
border-bottom: 1px solid var(--border);
background: color-mix(in srgb, var(--muted) 62%, transparent);
}
.preview-window-titlebar > div:first-child {
min-width: 0;
display: flex;
align-items: baseline;
gap: 0.6rem;
}
.preview-window-titlebar strong {
font-size: 0.92rem;
}
.preview-window-titlebar span {
overflow: hidden;
color: var(--muted-foreground);
font-size: 0.78rem;
text-overflow: ellipsis;
white-space: nowrap;
}
.preview-window-tools {
display: inline-flex;
align-items: center;
justify-content: flex-end;
gap: 0.35rem;
}
.preview-fullscreen-button {
appearance: none;
min-height: 2rem;
padding: 0.35rem 0.7rem;
border: 1px solid color-mix(in srgb, var(--border) 82%, var(--primary));
border-radius: calc(var(--radius) - 0.35rem);
background: color-mix(in srgb, var(--muted) 74%, transparent);
color: var(--foreground);
font: inherit;
font-size: 0.78rem;
font-weight: 700;
cursor: pointer;
}
.preview-fullscreen-button:hover {
background: color-mix(in srgb, var(--primary) 18%, var(--muted));
}
.preview-fullscreen-button[hidden] {
display: none !important;
}
.preview-window-actions {
display: inline-flex;
gap: 0.35rem;
}
.preview-window-actions span {
width: 0.72rem;
height: 0.72rem;
border: 1px solid color-mix(in srgb, var(--border) 75%, var(--foreground));
border-radius: 999px;
background: var(--muted);
}
.preview-tabs {
display: flex;
gap: 0.35rem;
padding: 0.55rem 0.7rem;
border-bottom: 1px solid var(--border);
background: color-mix(in srgb, var(--card) 78%, transparent);
}
.preview-tabs[hidden] {
display: none !important;
}
.preview-tab {
appearance: none;
min-height: 2rem;
padding: 0.35rem 0.7rem;
border: 1px solid transparent;
border-radius: calc(var(--radius) - 0.35rem);
background: transparent;
color: var(--muted-foreground);
font: inherit;
font-size: 0.8rem;
font-weight: 700;
cursor: pointer;
}
.preview-tab:hover,
.preview-tab.is-active {
border-color: color-mix(in srgb, var(--border) 82%, var(--primary));
background: color-mix(in srgb, var(--muted) 78%, transparent);
color: var(--foreground);
}
.preview-stage {
overflow: hidden;
min-height: clamp(18rem, 64vh, 38rem);
display: grid;
place-items: center;
background:
linear-gradient(45deg, color-mix(in srgb, var(--muted) 18%, transparent) 25%, transparent 25%),
linear-gradient(-45deg, color-mix(in srgb, var(--muted) 18%, transparent) 25%, transparent 25%),
color-mix(in srgb, var(--background) 88%, #000);
background-position: 0 0, 0.5rem 0.5rem;
background-size: 1rem 1rem;
}
.preview-stage > * {
grid-area: 1 / 1;
}
.preview-stage > img,
.preview-stage > video {
max-height: clamp(18rem, 64vh, 38rem);
width: 100%;
object-fit: contain;
}
.preview-stage > audio {
width: min(42rem, calc(100% - 2rem));
}
.default-preview,
.large-preview-gate {
width: min(26rem, calc(100% - 2rem));
display: grid;
place-items: center;
gap: 0.9rem;
padding: 2rem;
color: var(--muted-foreground);
text-align: center;
}
.default-preview img {
width: 5.5rem;
height: 5.5rem;
object-fit: contain;
}
.default-preview div {
min-width: 0;
display: grid;
gap: 0.25rem;
}
.default-preview strong {
max-width: 100%;
overflow: hidden;
color: var(--foreground);
font-size: 1rem;
text-overflow: ellipsis;
white-space: nowrap;
}
.default-preview span {
font-size: 0.86rem;
}
.large-preview-gate {
border: 1px solid color-mix(in srgb, var(--border) 82%, var(--danger));
border-radius: var(--radius);
background: color-mix(in srgb, var(--card) 92%, #000);
}
.large-preview-gate strong {
color: var(--foreground);
font-size: 1rem;
}
.large-preview-gate p {
margin: 0;
line-height: 1.45;
}
.large-preview-gate div {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 0.5rem;
}
.native-preview {
width: 100%;
height: clamp(18rem, 64vh, 38rem);
}
.native-audio-preview {
align-self: center;
width: min(42rem, calc(100% - 2rem));
height: auto;
}
.preview-placeholder {
display: grid;
place-items: center;
gap: 0.8rem;
padding: 2rem;
color: var(--muted-foreground);
text-align: center;
}
.preview-placeholder[hidden],
.default-preview[hidden],
.native-preview[hidden],
.large-preview-gate[hidden],
.code-preview[hidden],
.render-preview[hidden] {
display: none !important;
}
.preview-placeholder img {
width: 5rem;
height: 5rem;
object-fit: contain;
opacity: 0.78;
}
.preview-placeholder p {
margin: 0;
font-size: 0.9rem;
}
.code-preview {
min-width: 0;
width: 100%;
height: clamp(18rem, 64vh, 38rem);
overflow: auto;
background: #1b1724;
}
.code-preview pre[class*="language-"] {
width: max-content;
min-width: 100%;
min-height: 100%;
margin: 0;
border: 0;
border-radius: 0;
box-shadow: none;
background: transparent;
font-size: 0.88rem;
line-height: 1.55;
overflow: visible;
text-shadow: none;
}
.code-preview pre {
width: max-content;
min-width: 100%;
min-height: 100%;
margin: 0;
padding: 1rem;
overflow: visible;
color: #f5f3ff;
font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
font-size: 0.88rem;
line-height: 1.55;
white-space: pre;
}
.code-preview pre[class*="language-"] > code {
white-space: pre;
}
.code-preview code[class*="language-"] {
text-shadow: none;
}
.code-preview .token.punctuation {
opacity: 0.9;
}
.render-preview {
width: 100%;
height: clamp(18rem, 64vh, 38rem);
border: 0;
background: var(--background);
}
.preview-window:fullscreen,
.preview-window.is-render-fullscreen {
width: 100dvw;
height: 100dvh;
max-width: none;
display: grid;
grid-template-rows: auto auto minmax(0, 1fr);
border: 0;
border-radius: 0;
background: var(--background);
}
.preview-window.is-render-fullscreen {
position: fixed;
inset: 0;
z-index: 1000;
}
.preview-window:fullscreen .preview-stage,
.preview-window.is-render-fullscreen .preview-stage {
min-height: 0;
height: 100%;
place-items: stretch;
}
.preview-window:fullscreen .render-preview,
.preview-window.is-render-fullscreen .render-preview {
width: 100%;
height: 100%;
}
.file-emblem {
width: 4rem;
height: 4rem;
@@ -801,23 +1169,36 @@ html.reaction-picker-open body {
text-align: right;
}
.preview-stage {
overflow: hidden;
margin-bottom: 1rem;
border: 1px solid var(--border);
border-radius: var(--radius);
background: var(--background);
}
@media (max-width: 720px) {
.preview-view {
width: min(100%, calc(100% - 1rem));
padding-block: 1rem;
}
.preview-stage img,
.preview-stage video {
width: 100%;
max-height: 55vh;
display: block;
object-fit: contain;
}
.preview-header {
flex-direction: column;
align-items: stretch;
}
.preview-stage audio {
width: calc(100% - 2rem);
margin: 1rem;
.preview-header .button {
justify-content: center;
}
.preview-window-titlebar > div:first-child {
display: grid;
gap: 0.2rem;
}
.preview-stage,
.code-preview,
.render-preview,
.native-preview {
min-height: 18rem;
height: min(60vh, 32rem);
}
.preview-stage > img,
.preview-stage > video {
max-height: min(60vh, 32rem);
}
}