Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
reruin committed Nov 22, 2019
1 parent f857f3f commit a383cb1
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 54 deletions.
41 changes: 30 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ShareList 是一个易用的网盘工具,支持快速挂载 GoogleDrive、OneD
* [忽略文件类型](#忽略文件类型)
* [文件预览](#文件预览)
* [显示README](#显示README)
* [Nginx/Caddy反代注意事项](#Nginx/Caddy反代注意事项)
* [插件开发](#插件开发)


Expand Down Expand Up @@ -50,17 +51,17 @@ ShareList 是一个易用的网盘工具,支持快速挂载 GoogleDrive、OneD
文件(夹)id
/
```
ShareList会根据填写的挂载内容的不同形式,自动开启挂载向导,按指示操作即可。
ShareList会根据填写的挂载内容的不同形式,自动开启挂载向导,按指示操作即可。

### 挂载OneDrive
#### 1. 使用分享ID挂载
[drive.od](plugins/drive.od.js)插件实现。
[plugins/drive.od.js](plugins/drive.od.js)插件实现。
```
挂载标示:od
挂载内容:分享的文件ID。
```
#### 2. 使用官方API挂载
[drive.od.api](plugins/drive.od.api.js)插件实现。
[plugins/drive.od.api.js](plugins/drive.od.api.js)插件实现。
```
挂载标示:oda
挂载内容:
Expand All @@ -69,24 +70,26 @@ ShareList会根据填写的挂载内容的不同形式,自动开启挂载向
/
```
ShareList会根据填写的挂载内容,自动开启挂载向导,按指示操作即可。
对于不符合OneDrive安全要求的域名,将采用中转方式验证,[查看中转页面](https://github.com/reruin/reruin.github.io/blob/master/redirect/onedrive.html)
对于不符合OneDrive安全要求的域名,将采用中转方式验证,[查看中转页面](https://github.com/reruin/reruin.github.io/blob/master/redirect/onedrive.html)
**注意:由于onedrive修改了政策,个人Microsoft帐户已无法通过向导进行绑定。
需前往 [Azure管理后台](https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade) 注册应用并获取 app_id 和 app_secret 。**
#### 3. 挂载OneDrive For Business
[drive.odb](plugins/drive.odb.js)插件实现。
[plugins/drive.odb.js](plugins/drive.odb.js)插件实现。
```
挂载标示:odb
挂载内容:分享的url
```

### 挂载本地文件
[drive.fs](app/plugins/drive.fs.js)插件实现。
[drive.fs.js](app/plugins/drive.fs.js)插件实现。
```
挂载标示:fs
挂载内容:文件路径。
```
**注意:统一使用unix风格路径,例如 windows D盘 为 ```/d/```**

### 挂载GitHub
[drive.github](plugins/drive.github.js)插件实现。用于访问GitHub代码库。有以下两种挂载方式。
[plugins/drive.github.js](plugins/drive.github.js)插件实现。用于访问GitHub代码库。有以下两种挂载方式。
```
挂载标示:github
挂载内容:
Expand All @@ -108,15 +111,15 @@ ShareList会根据填写的挂载内容,自动开启挂载向导,按指示
插件为 ```mp4/jpg ```等禁止上传的格式提供解析支持,只需在文件名后附加```txt```后缀即可。以mp4为例,将```xxx.mp4```命名为```xxx.mp4.txt```后再上传,插件将自动解析为mp4文件。

### 挂载h5ai
[drive.h5ai](plugins/drive.h5ai.js)插件实现,用于访问h5ai目录程序。
[drive.h5ai.js](plugins/drive.h5ai.js)插件实现,用于访问h5ai目录程序。
```
挂载标示:h5ai
挂载路径:http地址
```
例如: ```h5ai:https://larsjung.de/h5ai/demo/```

### 挂载WebDAV
[drive.webdav](plugins/drive.webdav.js)插件实现,用于访问WebDAV服务。
[drive.webdav.js](plugins/drive.webdav.js)插件实现,用于访问WebDAV服务。
```
挂载标示:webdav
挂载路径:
Expand Down Expand Up @@ -173,12 +176,28 @@ data:
由[preview.document](plugins/drive.document.js)插件实现,可预览md、word、ppt、excel。

#### 多媒体
由[preview.media](plugins/drive.media.js)插件实现,可预览图片、音频、视频提供。
由[preview.media](plugins/drive.media.js)插件实现,可预览图片、音频、视频提供。
后台管理,插件设置,```支持预览的视频后缀```可定义可预览视频类型。

#### Torrent
由[preview.torrent](plugins/drive.torrent.js)插件实现,为种子文件提供在线预览。


### Nginx/Caddy反代注意事项
使用反代时,请添加以下配置。
Nginx
```ini
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
```
Caddy
```ini
header_upstream Host {host}
header_upstream X-Real-IP {remote}
header_upstream X-Forwarded-For {remote}
header_upstream X-Forwarded-Proto {scheme}
```

## 插件开发
待完善
Expand Down
25 changes: 22 additions & 3 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const db = createFiledb(configPath , {raw:true} , {

ignore_files:'.passwd',

readme_enable:1
readme_enable:1,

plugin_option:[]
});

if(process.env.PORT){
Expand All @@ -52,6 +54,23 @@ const getSkin = (key) => {
return db.get('skin') || 'default'
}

const getPluginOption = (key) => {
let p = db.get('plugin_option') || []
let hit = p.find(i => i.key == key )
return hit ? hit.value : null
}

const setPluginOption = (key , value) => {
let p = db.get('plugin_option') || []
let hit = p.find(i => i.key == key )
if( hit ){
hit.value = value
}else{
p.push({ key , value})
}
db.save()
}

const setRuntime = (key , value) => {
runtime[key] = value
}
Expand All @@ -63,7 +82,7 @@ const saveDrive = (value , name) => {
let hit = path.find( i => i.name == name)
if(hit){
hit.path = value
db.save(path)
db.save()
}
}

Expand Down Expand Up @@ -93,4 +112,4 @@ const getDrives = (protocols) => {
return ret
}

module.exports = { getConfig , getAllConfig, save , installed , getPath , setRuntime , getRuntime , saveDrive , getDrive , getSkin , getDrives }
module.exports = { getConfig , getAllConfig, save , installed , getPath , setRuntime , getRuntime , saveDrive , getDrive , getSkin , getDrives , getPluginOption , setPluginOption }
16 changes: 15 additions & 1 deletion app/controllers/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const base = require('../utils/base')
const request = require('request')
const config = require('../config')
const cache = require('../utils/cache')
const { getVendors } = require('../services/plugin')
const { getVendors , reload } = require('../services/plugin')
const service = require('../services/sharelist')

const handlers = async (a, body) => {
Expand All @@ -27,6 +27,17 @@ const handlers = async (a, body) => {
} else {
result.message = 'Invalid Arguments'
}
} else if(a == 'plugin_option'){
console.log(body)
for(let i in body){
if(i!=='a'){
let value = config.getPluginOption(i)
console.log(value)
value.value = body[i]
config.setPluginOption(i , value)
}
}

} else if (a == 'token') {
let newtoken = body.token
if (newtoken) {
Expand All @@ -37,6 +48,9 @@ const handlers = async (a, body) => {
result.status = -1
result.message = 'Invalid password'
}
} else if(a == 'reboot'){
reload()
result.message = 'Success'
} else if (a == 'title') {
let title = body.title
if (title) {
Expand Down
20 changes: 18 additions & 2 deletions app/services/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ const getHelpers = (id) => {
pathNormalize,
command,
wrapReadableStream,
getOption:()=>{

},
getPluginOption:(key)=>{
let p = id + '___' + key
return config.getPluginOption(p)
},
setPluginOption:(key , value)=>{
let p = id + '___' + key
config.setPluginOption(p , value)
},
saveDrive : (path , name) => {
let resource = resources[id]
if( resource && resource.drive && resource.drive.protocols){
Expand All @@ -164,7 +175,9 @@ const getHelpers = (id) => {
/**
* 加载插件
*/
var loadOptions = []
const load = (options) => {
loadOptions = options
const dir = options.dir
const dirs = options.dirs

Expand All @@ -190,7 +203,7 @@ const load = (options) => {

const pluginName = name.split('.').slice(0,-1).join('.')
const type = name.split('.')[0]
const id = 'plugin_' + pluginName
const id = 'plugin_' + pluginName.replace(/\./g,'_')
const helpers = getHelpers(id)
const resource = require(filepath).call(helpers,helpers)

Expand Down Expand Up @@ -253,6 +266,9 @@ const load = (options) => {
ready = true
}

const reload = () => {
load(loadOptions)
}
/**
* 根据扩展名获取可处理的驱动
*/
Expand Down Expand Up @@ -443,4 +459,4 @@ const createWriteStream = async (options) => {
}
}

module.exports = { load , getDrive , getStream , getSource , updateFolder , updateFile , updateLnk , getVendors , getAuth , getPreview , isPreviewable , command}
module.exports = { load , reload , getDrive , getStream , getSource , updateFolder , updateFile , updateLnk , getVendors , getAuth , getPreview , isPreviewable , command}
46 changes: 31 additions & 15 deletions app/views/default/manage.pug
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,52 @@ block content
.form-group
a.btn.btn-success(href='?a=export',target='_blank')= __('export')
a.btn.btn-success(href='/manage/shell',target='_blank') Shell
form.form-horizontal(style="display:inline-block;",method='post',action="/manage/api")
input(type='hidden',name='a',value='reboot')
button.btn.btn-danger= __('reboot')
.panel.panel-default
.panel-heading
span= __("general")
.panel-body
form.form-horizontal(method='post',action="/manage/api")
input(type='hidden',name='a',value='cfg')
.form-group
.col-sm-6
.col-sm-4
label= __('proxy_enable')
.col-sm-3
.col-sm-8
select.form-control(name='proxy_enable',value=config.proxy_enable,required)
option(value='1', selected=config.proxy_enable==1 ? 'selected' : null)= __('enable')
option(value='0', selected=config.proxy_enable==0 ? 'selected' : null)= __('disable')
.col-sm-6
.col-sm-4
label= __('preview_enable')
.col-sm-3
.col-sm-8
select.form-control(name='preview_enable',value=config.preview_enable,required)
option(value='1', selected=config.preview_enable==1 ? 'selected' : null)= __('enable')
option(value='0', selected=config.preview_enable==0 ? 'selected' : null)= __('disable')
.form-group
.col-sm-6
.col-sm-4
label= __('max_age_dir')
.col-sm-3
.col-sm-8
input.form-control(type='text', name='max_age_dir' , value=config.max_age_dir / 1000,required)
.form-group
.col-sm-6
.col-sm-4
label= __('max_age_file')
.col-sm-3
.col-sm-8
input.form-control(type='text', name='max_age_file' , value=config.max_age_file / 1000,required)
.form-group
.col-sm-6
.col-sm-4
label= __('webdav_path')
.col-sm-3
.col-sm-8
input.form-control(type='text', name='webdav_path' , value=config.webdav_path,required)
.form-group
.col-sm-6
.col-sm-4
label= __('ignore_file_extensions')
.col-sm-3
.col-sm-8
input.form-control(type='text', name='ignore_file_extensions' , value=config.ignore_file_extensions,placeholder=__('ignore_file_extensions_placeholder'))
.form-group
.col-sm-6
.col-sm-4
label= __('readme_enable')
.col-sm-3
.col-sm-8
select.form-control(name='readme_enable',value=config.readme_enable,required)
option(value='1', selected=config.readme_enable==1 ? 'selected' : null)= __('enable')
option(value='0', selected=config.readme_enable==0 ? 'selected' : null)= __('disable')
Expand All @@ -67,7 +70,20 @@ block content
form.form-horizontal(method='post',action="/manage/api")
input(type='hidden',name='a',value='clear_cache')
button.btn.btn-danger= __('clear_cache')

.panel.panel-default
.panel-heading
span= __("plugin_option")
.panel-body
form.form-horizontal(method='post',action="/manage/api")
input(type='hidden',name='a',value='plugin_option')
each i in config.plugin_option
.form-group
.col-sm-4
label= i.value.label
.col-sm-8
input.form-control(type='text',placeholder=i.value.placeholder, name=i.key , value=i.value.value)
.form-group.text-center
button.btn.btn-default(type='submit')= __('save')
.panel.panel-default
.panel-heading= __('token')
.panel-body
Expand Down
Loading

0 comments on commit a383cb1

Please sign in to comment.