Merge pull request #1817 from MaxLeiter/videos

Support video file previews
This commit is contained in:
Al McKinlay 2017-12-14 08:56:58 +00:00 committed by GitHub
commit 8b52825d51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 17 deletions

View File

@ -4,23 +4,29 @@
<a class="toggle-thumbnail" href="{{link}}" target="_blank" rel="noopener"> <a class="toggle-thumbnail" href="{{link}}" target="_blank" rel="noopener">
<img src="{{thumb}}"> <img src="{{thumb}}">
</a> </a>
{{else}} {{/equal}}
{{#equal type "audio"}} {{#equal type "audio"}}
<audio controls preload="metadata"> <audio controls preload="metadata">
<source src="{{link}}" type="{{res}}"> <source src="{{link}}" type="{{res}}">
Your browser does not support the audio element. Your browser does not support the audio element.
</audio> </audio>
{{else}} {{/equal}}
{{#if thumb}} {{#equal type "video"}}
<a class="toggle-thumbnail" href="{{link}}" target="_blank" rel="noopener"> <video width="320" height="240" preload="metadata" controls>
<img src="{{thumb}}" class="thumb"> <source src="{{link}}" type="{{res}}">
</a> Your browser does not support the video element.
{{/if}} </video>
<a class="toggle-text" href="{{link}}" target="_blank" rel="noopener"> {{/equal}}
<div class="head" title="{{head}}">{{head}}</div> {{#equal type "link"}}
<div class="body" title="{{body}}">{{body}}</div> {{#if thumb}}
<a class="toggle-thumbnail" href="{{link}}" target="_blank" rel="noopener">
<img src="{{thumb}}" class="thumb">
</a> </a>
{{/equal}} {{/if}}
<a class="toggle-text" href="{{link}}" target="_blank" rel="noopener">
<div class="head" title="{{head}}">{{head}}</div>
<div class="body" title="{{body}}">{{body}}</div>
</a>
{{/equal}} {{/equal}}
</div> </div>
{{/preview}} {{/preview}}

View File

@ -120,6 +120,18 @@ function parse(msg, preview, res, client) {
} }
preview.type = "audio"; preview.type = "audio";
preview.res = res.type; preview.res = res.type;
break;
case "video/webm":
case "video/ogg":
case "video/mp4":
if (!preview.link.startsWith("https://")) {
break;
}
preview.res = res.type;
preview.type = "video";
break; break;
default: default:
@ -186,7 +198,7 @@ function fetch(uri, cb) {
if (contentLength > limit) { if (contentLength > limit) {
req.abort(); req.abort();
} }
} else if (/^audio\/.+/.test(res.headers["content-type"])) { } else if (/^(audio|video)\/.+/.test(res.headers["content-type"])) {
req.abort(); // ensure server doesn't download the audio file req.abort(); // ensure server doesn't download the audio file
} else { } else {
// if not image, limit download to 50kb, since we need only meta tags // if not image, limit download to 50kb, since we need only meta tags