Skip to content

Commit bd4aa4f

Browse files
authored
feat: Add support for Video type in View table to display videos (#3061)
1 parent cd75c5a commit bd4aa4f

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Parse Dashboard is a standalone dashboard for managing your [Parse Server](https
9999
- [Pointer](#pointer)
100100
- [Link](#link)
101101
- [Image](#image)
102+
- [Video](#video)
102103
- [Contributing](#contributing)
103104

104105
# Getting Started
@@ -1633,6 +1634,24 @@ Example:
16331634
> [!Warning]
16341635
> The URL will be directly invoked by the browser when trying to display the image. For security reasons, make sure you either control the full URL, including the image file name, or sanitize the URL before returning it to the dashboard. URLs containing `javascript:` or `<script` will be blocked automatically and replaced with a placeholder.
16351636
1637+
#### Video
1638+
1639+
Videos are rendered directly in the output table with a `<video>` tag that includes playback controls. The content mode is always "scale to fit", meaning that the video maintains its aspect ratio within the specified dimensions.
1640+
1641+
Example:
1642+
1643+
```json
1644+
{
1645+
"__type": "Video",
1646+
"url": "https://example.com/video.mp4",
1647+
"width": "320",
1648+
"height": "240"
1649+
}
1650+
```
1651+
1652+
> [!Warning]
1653+
> The URL will be directly invoked by the browser when trying to display the video. For security reasons, make sure you either control the full URL, including the video file name, or sanitize the URL before returning it to the dashboard. URLs containing `javascript:` or `<script` will be blocked automatically and replaced with a placeholder.
1654+
16361655
# Contributing
16371656
16381657
We really want Parse to be yours, to see it grow and thrive in the open source community. Please see the [Contributing to Parse Dashboard guide](CONTRIBUTING.md).

src/dashboard/Data/Views/Views.react.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ class Views extends TableView {
273273
type = 'Link';
274274
} else if (val.__type === 'Image') {
275275
type = 'Image';
276+
} else if (val.__type === 'Video') {
277+
type = 'Video';
276278
} else {
277279
type = 'Object';
278280
}
@@ -406,6 +408,8 @@ class Views extends TableView {
406408
type = 'Link';
407409
} else if (value.__type === 'Image') {
408410
type = 'Image';
411+
} else if (value.__type === 'Video') {
412+
type = 'Video';
409413
} else {
410414
type = 'Object';
411415
}
@@ -490,6 +494,43 @@ class Views extends TableView {
490494
}}
491495
/>
492496
);
497+
} else if (type === 'Video') {
498+
// Sanitize URL
499+
let url = value.url;
500+
if (
501+
!url ||
502+
url.match(/javascript/i) ||
503+
url.match(/<script/i)
504+
) {
505+
url = '#';
506+
}
507+
508+
// Parse dimensions, ensuring they are positive numbers
509+
const width = value.width && parseInt(value.width, 10) > 0 ? parseInt(value.width, 10) : null;
510+
const height = value.height && parseInt(value.height, 10) > 0 ? parseInt(value.height, 10) : null;
511+
512+
// Create style object for scale-to-fit behavior
513+
const videoStyle = {
514+
maxWidth: width ? `${width}px` : '100%',
515+
maxHeight: height ? `${height}px` : '100%',
516+
objectFit: 'contain', // This ensures scale-to-fit behavior maintaining aspect ratio
517+
display: 'block'
518+
};
519+
520+
content = (
521+
<video
522+
src={url}
523+
controls
524+
style={videoStyle}
525+
onError={(e) => {
526+
if (e.target && e.target.style) {
527+
e.target.style.display = 'none';
528+
}
529+
}}
530+
>
531+
Your browser does not support the video tag.
532+
</video>
533+
);
493534
} else if (value === undefined) {
494535
content = '';
495536
} else {

0 commit comments

Comments
 (0)