forked from reruin/sharelist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
212 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
webdav:https://sharelist.reruin.net/webdav |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* WebDAV | ||
*/ | ||
|
||
|
||
const name = 'webdav' | ||
|
||
const version = '1.0' | ||
|
||
const protocols = ['webdav'] | ||
|
||
const defaultProtocol = 'webdav' | ||
|
||
const path = require('path') | ||
|
||
const { createClient } = require("webdav"); | ||
|
||
const { URL } = require("url") | ||
|
||
const { Writable } = require('stream') | ||
|
||
const clientMap = {} | ||
|
||
module.exports = ({ getConfig, cache , base64 }) => { | ||
|
||
const extname = (p) => path.extname(p).substring(1) | ||
|
||
const getPath = (url) => { | ||
let { pathname } = new URL('ftp:' + url); | ||
return pathname | ||
} | ||
|
||
const getClient = async (url, cd = false) => { | ||
let key = (url.match(/https?\:\/\/[\w\W]+?\//) || [''])[0]; | ||
let { protocol , username, password, host, port, pathname } = new URL(url); | ||
let client = clientMap[key] | ||
let remote_url = protocol + '//' + host + pathname | ||
console.log(remote_url , username , password) | ||
if (!client) { | ||
client = createClient(remote_url,{ | ||
username:decodeURIComponent(username),password:decodeURIComponent(password) | ||
}); | ||
|
||
clientMap[key] = client | ||
} | ||
|
||
return client; | ||
|
||
} | ||
|
||
const folder = async (id) => { | ||
let [server , path] = id.split('>'); | ||
let resp = { id: id, type: 'folder', protocol: defaultProtocol } | ||
|
||
/* | ||
let resid = `${defaultProtocol}:${id}` | ||
let r = cache(resid) | ||
if (r) { | ||
resp = r | ||
if ( | ||
resp.$cached_at && | ||
resp.children && | ||
(Date.now() - resp.$cached_at < getConfig().max_age_dir) | ||
) { | ||
console.log('get webdav folder from cache') | ||
return resp | ||
} | ||
} | ||
*/ | ||
|
||
let client = await getClient(server) | ||
|
||
if (client) { | ||
let data = await client.getDirectoryContents(path || '/'); | ||
|
||
let children = []; | ||
data.forEach(i => { | ||
let path = (server + '>' + i.filename) | ||
let obj = { | ||
id: path, | ||
name: i.basename, | ||
protocol: defaultProtocol, | ||
size: i.size, | ||
created_at: i.lastmod, | ||
updated_at: i.lastmod, | ||
ext: extname(i.basename), | ||
mime:i.mime, | ||
type: i.type == 'directory' ? 'folder' : 'other' | ||
} | ||
|
||
children.push(obj) | ||
}) | ||
|
||
resp.$cached_at = Date.now() | ||
resp.children = children | ||
//cache(resid, resp) | ||
|
||
return resp | ||
} else { | ||
return false | ||
} | ||
} | ||
|
||
const file = async (id , data = {}) => { | ||
|
||
data.outputType = 'stream' | ||
data.proxy = 'stream' | ||
|
||
return data | ||
} | ||
|
||
const stream = async (id, options = {}) => { | ||
let [server , path] = id.split('>'); | ||
let client = await getClient(server, true) | ||
|
||
if (client) { | ||
let writeStream = options.writeStream; | ||
let headers = Object.assign({},options.headers); | ||
|
||
if(options.range && options.range.length == 2){ | ||
headers['Content-Range'] = 'bytes ' + `${options.range[0]}-${options.range[1]}/${data.size}` | ||
} | ||
if (writeStream) { | ||
return client.createReadStream(path , {headers}).pipe(writeStream) | ||
} else { | ||
return await client.getFileContents(path) | ||
} | ||
} else { | ||
return null | ||
} | ||
} | ||
|
||
return { name, version, drive: { protocols, folder, file, stream } } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,6 +246,10 @@ balanced-match@^1.0.0: | |
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" | ||
|
||
base-64@^0.1.0: | ||
version "0.1.0" | ||
resolved "https://registry.yarnpkg.com/base-64/-/base-64-0.1.0.tgz#780a99c84e7d600260361511c4877613bf24f6bb" | ||
|
||
base@^0.11.1: | ||
version "0.11.2" | ||
resolved "https://registry.yarnpkg.com/base/-/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f" | ||
|
@@ -1133,6 +1137,10 @@ [email protected]: | |
version "2.16.3" | ||
resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed" | ||
|
||
hot-patcher@^0.5.0: | ||
version "0.5.0" | ||
resolved "https://registry.yarnpkg.com/hot-patcher/-/hot-patcher-0.5.0.tgz#9d401424585aaf3a91646b816ceff40eb6a916b9" | ||
|
||
http-assert@^1.3.0: | ||
version "1.4.0" | ||
resolved "https://registry.yarnpkg.com/http-assert/-/http-assert-1.4.0.tgz#0e550b4fca6adf121bbeed83248c17e62f593a9a" | ||
|
@@ -1770,6 +1778,10 @@ [email protected]: | |
version "0.3.0" | ||
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" | ||
|
||
merge@^1.2.1: | ||
version "1.2.1" | ||
resolved "https://registry.yarnpkg.com/merge/-/merge-1.2.1.tgz#38bebf80c3220a8a487b6fcfb3941bb11720c145" | ||
|
||
methods@^1.0.1, methods@^1.1.1: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" | ||
|
@@ -1806,10 +1818,14 @@ mime@^1.2.11: | |
version "1.6.0" | ||
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" | ||
|
||
mime@^2.2.0, mime@^2.3.1: | ||
mime@^2.2.0: | ||
version "2.4.0" | ||
resolved "https://registry.yarnpkg.com/mime/-/mime-2.4.0.tgz#e051fd881358585f3279df333fe694da0bcffdd6" | ||
|
||
mime@^2.4.2: | ||
version "2.4.2" | ||
resolved "https://registry.yarnpkg.com/mime/-/mime-2.4.2.tgz#ce5229a5e99ffc313abac806b482c10e7ba6ac78" | ||
|
||
minimatch@^3.0.4: | ||
version "3.0.4" | ||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" | ||
|
@@ -2132,6 +2148,10 @@ path-parse@^1.0.6: | |
version "1.0.6" | ||
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" | ||
|
||
path-posix@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/path-posix/-/path-posix-1.0.0.tgz#06b26113f56beab042545a23bfa88003ccac260f" | ||
|
||
path-to-regexp@^1.1.1: | ||
version "1.7.0" | ||
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d" | ||
|
@@ -2372,6 +2392,10 @@ qs@~6.4.0: | |
version "6.4.0" | ||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233" | ||
|
||
querystringify@^2.0.0: | ||
version "2.1.1" | ||
resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.1.1.tgz#60e5a5fd64a7f8bfa4d2ab2ed6fdf4c85bad154e" | ||
|
||
random-bytes@~1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/random-bytes/-/random-bytes-1.0.0.tgz#4f68a1dc0ae58bd3fb95848c30324db75d64360b" | ||
|
@@ -2488,6 +2512,10 @@ [email protected]: | |
tunnel-agent "^0.6.0" | ||
uuid "^3.0.0" | ||
|
||
requires-port@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" | ||
|
||
resolve-path@^1.3.1: | ||
version "1.4.0" | ||
resolved "https://registry.yarnpkg.com/resolve-path/-/resolve-path-1.4.0.tgz#c4bda9f5efb2fce65247873ab36bb4d834fe16f7" | ||
|
@@ -2987,12 +3015,23 @@ urix@^0.1.0: | |
version "0.1.0" | ||
resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72" | ||
|
||
url-join@^4.0.0: | ||
version "4.0.0" | ||
resolved "https://registry.yarnpkg.com/url-join/-/url-join-4.0.0.tgz#4d3340e807d3773bda9991f8305acdcc2a665d2a" | ||
|
||
url-parse-lax@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/url-parse-lax/-/url-parse-lax-1.0.0.tgz#7af8f303645e9bd79a272e7a14ac68bc0609da73" | ||
dependencies: | ||
prepend-http "^1.0.1" | ||
|
||
url-parse@^1.4.4: | ||
version "1.4.6" | ||
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.4.6.tgz#baf91d6e6783c8a795eb476892ffef2737fc0456" | ||
dependencies: | ||
querystringify "^2.0.0" | ||
requires-port "^1.0.0" | ||
|
||
url-template@^2.0.8: | ||
version "2.0.8" | ||
resolved "https://registry.yarnpkg.com/url-template/-/url-template-2.0.8.tgz#fc565a3cccbff7730c775f5641f9555791439f21" | ||
|
@@ -3051,6 +3090,20 @@ vxx@^1.2.0: | |
shimmer "^1.0.0" | ||
uuid "^3.0.1" | ||
|
||
webdav@^2.6.0: | ||
version "2.6.0" | ||
resolved "https://registry.yarnpkg.com/webdav/-/webdav-2.6.0.tgz#28918f01c2e1d0757c7bc719a1b240976db56979" | ||
dependencies: | ||
axios "^0.18.0" | ||
base-64 "^0.1.0" | ||
hot-patcher "^0.5.0" | ||
merge "^1.2.1" | ||
minimatch "^3.0.4" | ||
path-posix "^1.0.0" | ||
url-join "^4.0.0" | ||
url-parse "^1.4.4" | ||
xml2js "^0.4.19" | ||
|
||
which@^1.2.9: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" | ||
|