Flarum添加视频支持

依赖插件

添加自定义预览视频的模板

由于是docker运行的flarum, 首先进入flarum的容器中. 然后找到extend.php文件, 改成如下代码:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php

/*
 * This file is part of Flarum.
 *
 * For detailed copyright and license information, please view the
 * LICENSE file that was distributed with this source code.
 */

use Flarum\Extend;
use Flarum\Foundation\AbstractServiceProvider;
use FoF\Upload\Contracts\Template;
use FoF\Upload\File;
use FoF\Upload\Helpers\Util;

class LinxVideoTemplate implements Template                       
{                                                                 
    public function tag(): string                                 
    {                                                             
        return 'linxvideotemplate';                               
    }                                                             
                                                           
    public function name(): string            
    {                                         
        return 'Linx Video Template';         
    }                                         
                                           
    public function description(): string  
    {                                      
        return '随便填点东西';
    }                                                                          
                                                                               
    public function preview(File $file): string                                
    {                                                                          
        return '[embed-video id="insertRandomId" url="' . $file->url . '" type="normal" live="false" qualities=""]';
    }                                                                                                               
}    


class MyServiceProvider extends AbstractServiceProvider    
{                                       
    public function register()               
    {                                                                                                               
        $this->container->make(Util::class)->addRenderTemplate($this->container->make(LinxVideoTemplate::class));   
    }                                                                                                               
}                                                                                                                   
                                                                                                                    
                                                                                                             
return [                                                                                                            
    // Register extenders here to customize your forum!                                                             
    (new Extend\ServiceProvider())                                                                                  
       ->register(MyServiceProvider::class),                                                                                                                                                                                          
];          

回到后台的FoF Upload插件页面

进行如下设置 alt text

正则为:

1
(video\/(3gpp|mp4|mpeg|quicktime|webm))|(audio\/(aiff|midi|mpeg|mp4))|(image\/(gif|jpeg|png))|(application\/(x-(7z|rar|zip)-compressed|zip|arj|x-(bzip2|gzip|lha|stuffit|tar)|pdf))

PS: mp3上传后的MIME也是 audio/mpeg 这样的, 所以不用改

选完后记得点击+号, 然后保存

Licensed under CC BY-NC-SA 4.0
记录平时瞎折腾遇到的各种问题, 方便查找
使用 Hugo 构建
主题 Stack 3.29.0Jimmy 设计