Skip to content

Commit

Permalink
update dplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
reruin committed Feb 14, 2020
1 parent 42f82e9 commit 5e4168d
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 11 deletions.
6 changes: 5 additions & 1 deletion app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ const db = createFiledb(configPath , {raw:true} , {

anonymous_uplod_enable:0,

plugin_option:[]
plugin_option:[],

custom_style:'',

custom_script:'',
});

if(process.env.PORT){
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const handlers = async (a, body) => {
cache.clear()
result.message = 'Success'
} else if (a == 'cfg') {
let { proxy_enable, preview_enable, readme_enable, max_age_dir, max_age_file,max_age_download, webdav_path, anonymous_uplod_enable, ignore_file_extensions , ignore_paths } = body
let { proxy_enable, preview_enable, readme_enable, max_age_dir, max_age_file,max_age_download, webdav_path, anonymous_uplod_enable, ignore_file_extensions , ignore_paths , custom_style , custom_script } = body
let opts = {}
if (max_age_dir !== undefined) {
max_age_dir = parseInt(max_age_dir)
Expand Down Expand Up @@ -110,6 +110,8 @@ const handlers = async (a, body) => {
if (webdav_path) {
opts.webdav_path = webdav_path
}
opts.custom_script = custom_script
opts.custom_style = custom_style
opts.ignore_paths = config.getConfig('ignore_paths')
opts.ignore_file_extensions = ignore_file_extensions
opts.ignore_paths.__root__ = ignore_paths.split(',')
Expand Down
8 changes: 6 additions & 2 deletions app/middleware/koa-render.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const { getSkin } = require('../config')
const { getSkin , getConfig } = require('../config')

module.exports = (ctx, next) => {
if(ctx.renderSkin) return next()
ctx.response.renderSkin = ctx.renderSkin = (path , options) => {
return ctx.render(getSkin()+'/'+path, options)
let data = { ...options , g_config:{
custom_style:getConfig('custom_style'),
custom_script:getConfig('custom_script'),
}}
return ctx.render(getSkin()+'/'+path, data)
}
return next()
}
12 changes: 12 additions & 0 deletions app/views/default/manage.pug
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ block content
select.form-control(name='anonymous_uplod_enable',value=config.anonymous_uplod_enable,required)
option(value='1', selected=config.anonymous_uplod_enable==1 ? 'selected' : null)= __('enable')
option(value='0', selected=config.anonymous_uplod_enable==0 ? 'selected' : null)= __('disable')
.form-group
.col-sm-4
label= __('custom_style')
.col-sm-8
textarea.form-control(name='custom_style')
| #{config.custom_style}
.form-group
.col-sm-4
label= __('custom_script')
.col-sm-8
textarea.form-control(name='custom_script')
| #{config.custom_script}
.form-group.text-center
button.btn.btn-default(type='submit')= __('save')
.panel.panel-default
Expand Down
5 changes: 4 additions & 1 deletion app/views/default/partial/footer.pug
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
footer
p
a(href='https://github.com/reruin/sharelist',target='_blank') GitHub
a(href='/manage',target='_blank')= __('manage')
a(href='/manage',target='_blank')= __('manage')
-if(g_config.custom_script)
.
!{g_config.custom_script}
6 changes: 4 additions & 2 deletions app/views/default/partial/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ html

// META
link(rel='stylesheet', href='//cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css')
link(rel='stylesheet', type='text/css',href='/style/font/font.css')
link(rel='stylesheet', type='text/css',href='https://fonts.loli.net/css?family=Source+Code+Pro')
link(rel='stylesheet', type='text/css', href='/style/main.css')

-if(g_config && g_config.custom_style)
.
!{g_config.custom_style}
body
block content
4 changes: 4 additions & 0 deletions example/preview/movie.vtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
WEBVTT
00:00:00.001 --> 00:00:03.000
鸟叫声
2 changes: 2 additions & 0 deletions locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ module.exports = {
"ignore_paths":"Ignore Path",
"ignore_paths_placeholder":"e.g. /a,/b/c",
"plugin_option":"Plugin Option",
"custom_style":"Custom Style",
"custom_script":"Custom Script",
"reboot":"Reboot",
}
2 changes: 2 additions & 0 deletions locales/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ module.exports = {
"ignore_paths":"忽略路径",
"ignore_paths_placeholder":"路径,多个用逗号分隔",
"plugin_option":"插件配置",
"custom_style":"自定义样式",
"custom_script":"自定义脚本",
"reboot":"重启"
}
2 changes: 2 additions & 0 deletions locales/zh-TW.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ module.exports = {
"ignore_paths":"忽略路徑",
"ignore_paths_placeholder":"路徑,多個用逗號分隔",
"plugin_option":"插件配置",
"custom_style":"自定義樣式",
"custom_script":"自定義腳本",
"reboot":"重啟",
}
41 changes: 37 additions & 4 deletions plugins/preview.media.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ module.exports = ({getSource , getPluginOption , setPluginOption}) => {
// <video src="${req.path}" style="min-width: 90%;min-height: 60vh;" controls="controls" autoplay="autoplay"></video>
// `,
body: videoPlayer == 'dplayer' ? `
<script src="https://cdn.bootcss.com/dplayer/1.25.0/DPlayer.min.js"></script>
<link href="https://cdn.bootcss.com/dplayer/1.25.0/DPlayer.min.css" rel="stylesheet" />
<div id="dplayer" style="margin-top:32px;height:60vh;">
<script src="https://cdn.bootcss.com/dplayer/1.25.0/DPlayer.min.js"></script>
<div id="dplayer" style="margin-top:32px;height:60vh;"></div>
<script>
var url = '${decodeUrl(req)}' , subtitle = url.replace(/\\.[^\\?]+/,'.vtt');
var dp = new DPlayer({
container: document.getElementById('dplayer'),
video: {
url: '${decodeUrl(req)}',
video:{
url: url,
},
subtitle: {
url: subtitle,
fontSize: '25px',
bottom: '7%',
},
});
</script>
Expand Down Expand Up @@ -77,10 +83,37 @@ module.exports = ({getSource , getPluginOption , setPluginOption}) => {
}
}

const hls = async (data , req) => {
return {
...data,
body: `
<link href="https://cdn.bootcss.com/dplayer/1.25.0/DPlayer.min.css" rel="stylesheet" />
<script src="https://cdn.bootcss.com/hls.js/8.0.0-beta.3/hls.min.js"></script>
<script src="https://cdn.bootcss.com/dplayer/1.25.0/DPlayer.min.js"></script>
<div id="dplayer" style="margin-top:32px;height:60vh;"></div>
<script>
var url = '${decodeUrl(req)}';
var dp = new DPlayer({
container: document.getElementById('dplayer'),
video:{
url: url,
type:'hls'
},
});
</script>
`
}
}


videoFormat.split(',').forEach( ext => {
preview[ext] = video
});

['m3u8'].forEach( ext => {
preview[ext] = hls
});

['mp3','m4a','acc'].forEach( ext => {
preview[ext] = audio
Expand Down

0 comments on commit 5e4168d

Please sign in to comment.