Pārlūkot izejas kodu

Fix #41: display multimedia in microblog correctly

George S. Baugh 5 gadi atpakaļ
vecāks
revīzija
2fa136a299
2 mainītis faili ar 27 papildinājumiem un 3 dzēšanām
  1. 15 3
      lib/Trog/Data/DUMMY.pm
  2. 12 0
      www/templates/posts.tx

+ 15 - 3
lib/Trog/Data/DUMMY.pm

@@ -193,9 +193,21 @@ sub _process ($post) {
     delete $post->{file};
     delete $post->{preview_file};
 
-    my $mf = Mojo::File->new("www/$post->{href}");
-    my $ext = '.'.$mf->extname();
-    $post->{content_type} = Plack::MIME->mime_type($ext) if $ext;
+    if ($post->{href}) {
+        my $mf = Mojo::File->new("www/$post->{href}");
+        my $ext = '.'.$mf->extname();
+        $post->{content_type} = Plack::MIME->mime_type($ext) if $ext;
+    }
+    if ($post->{video_href}) {
+        my $mf = Mojo::File->new("www/$post->{video_href}");
+        my $ext = '.'.$mf->extname();
+        $post->{video_content_type} = Plack::MIME->mime_type($ext) if $ext;
+    }
+    if ($post->{audio_href}) {
+        my $mf = Mojo::File->new("www/$post->{audio_href}");
+        my $ext = '.'.$mf->extname();
+        $post->{audio_content_type} = Plack::MIME->mime_type($ext) if $ext;
+    }
 
     return $post;
 }

+ 12 - 0
www/templates/posts.tx

@@ -22,6 +22,18 @@
                 <span id="<: $post.id :>-time" style="float:right;"><: $post.created :></span>
                 <a class='usericon <: $post.user :>' title='Posted by <: $post.user :>'></a>
             </h3>
+            : if ( $post.video_href ) {
+                <video class="responsive" controls>
+                    <source src="<: $post.video_href :>" type="<: $post.video_content_type :>" />
+                    Your browser does not support the video tag.
+                </video>
+            : }
+            : if ( $post.audio_href ) {
+                <audio controls>
+                    <source src="<: $post.audio_href :>" type="<: $post.audio_content_type :>" />
+                    Your browser does not support the audio tag.
+                </audio>
+            : }
             : if ( $post.is_video ) {
                 <video class="responsive" controls poster="<: $post.preview :>" >
                     <source src="<: $post.href :>" type="<: $post.content_type :>" />