Skip to content

Commit

Permalink
update travis
Browse files Browse the repository at this point in the history
  • Loading branch information
reruin committed Mar 9, 2020
1 parent 615e277 commit a0f96b6
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 29 deletions.
25 changes: 9 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
sudo: false
language: node_js
node_js:
- 8
- 9
- 10
- 11
cache:
directories:
- node_modules
install:
- npm install
before_script:
- npm install -g pm2
# script:
# - npm run lint
# - npm run test-cov
# - npm run bench
- 'stable'
services:
- docker
script:
#- npm install pkg -g
#- npm run build
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker build -t reruin/sharelist:latest .
- docker push reruin/sharelist:latest
13 changes: 11 additions & 2 deletions app/controllers/sharelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ const output = async (ctx , data)=>{

const proxy_paths = config.getConfig('proxy_paths') || []

const isProxy = (config.getConfig('proxy_enable') && isProxyPath(ctx.path , proxy_paths)) || data.proxy || downloadLinkAge > 0
const isProxy = (config.getConfig('proxy_enable') && isProxyPath(ctx.path , proxy_paths)) || data.proxy || downloadLinkAge > 0 || !!ctx.webdav

let url = data.url

//部分webdav客户端不被正常识别
if( ctx.webdav ){
data.proxy_headers = {
// 'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8'
}
}

if(isPreview){
//代理 或者 文件系统
await ctx.renderSkin('detail',{
Expand Down
2 changes: 2 additions & 0 deletions app/middleware/koa-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ module.exports = async(ctx, next) => {
depth:ctx.get('depth')
}

ctx.runtime.isWebDAV = true
console.log(ctx.request.headers['user-agent'])
//upload
if(method == 'PUT'){
//{ type: 'upload', name: file.name, size: file.size , path : opts.path }
Expand Down
9 changes: 5 additions & 4 deletions app/plugins/cmd.copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ module.exports = ({ command , pathNormalize , createReadStream , createWriteStre
if(i.type == 'folder'){
files = files.concat( await parseFiles(task , path+'/'+i.name , parent+'/'+i.name) )
}else{
files.push( { path: `${parent}/`+i.name , id: i.id , size:i.size , protocol:i.protocol } )
files.push( { path: `${parent}/`+i.name , id: i.id , name:i.name, size:i.size , protocol:i.protocol } )
}
}
}else{
files.push( { path: data.name , id: data.id , size:data.size,protocol:data.protocol , target_is_file:true} )
files.push( { path: data.name , name:data.name, id: data.id , size:data.size,protocol:data.protocol , target_is_file:true} )
}

files.forEach(i => {
Expand All @@ -73,8 +73,8 @@ module.exports = ({ command , pathNormalize , createReadStream , createWriteStre
let readStream = await createReadStream(i)
if( readStream ){
//It's very important
let size = i.size || readStream.size
let writeStream = await parseWrite(task , pathNormalize( i.target_is_file ? dst : (dst + '/' + i.path), basepath) , {size})
let size = i.size || readStream.size , name = i.name
let writeStream = await parseWrite(task , pathNormalize( i.target_is_file ? dst : (dst + '/' + i.path), basepath) , {size , name})
if( writeStream ){
task.cWriteStream = writeStream
task.cReadStream = readStream
Expand All @@ -89,6 +89,7 @@ module.exports = ({ command , pathNormalize , createReadStream , createWriteStre
}
}else{
task.stats.error++
console.log( 'dst does not support write' )
// return {result:'dst does not support write'}
}
}else{
Expand Down
8 changes: 7 additions & 1 deletion app/utils/sendfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ const sendHTTPFile = async (ctx , url ,data = {}) => {
let range = ctx.get('range')
let fileSize = data.size
let chunksize = fileSize

if(range){
let [start , end] = getRange(ctx.header.range , fileSize)
ctx.set('Content-Range', 'bytes ' + `${start}-${end}/${fileSize}`)
Expand All @@ -107,11 +106,18 @@ const sendHTTPFile = async (ctx , url ,data = {}) => {
chunksize = end - start + 1
}else{
ctx.set('Content-Range', 'bytes ' + `0-${fileSize-1}/${fileSize}`)
ctx.status = 206
}
ctx.length = chunksize
}

let extra = data.proxy_options || {}
if(data.proxy_headers){
for(let i in data.proxy_headers){
headers[i] = data.proxy_headers[i]
}
}

let stream = http({url , headers , ...extra})
stream.on('response', function(response) {
ctx.status = response.statusCode
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dev": "./node_modules/.bin/nodemon app.js -i ./cache",
"prd": "pm2 start app.js --name sharelist --env prod",
"test": "echo \"Error: no test specified\" && exit 1",
"build": "pkg . -t node10-win-x64 --output build/nrop_windows_amd64.exe && pkg . -t node10-macos-x64 --output build/nrop_macos_amd64 && pkg . -t node10-linux-x64 --output build/nrop_linux_amd64"
"build": "pkg . -t node12-win-x64 --output build/sharelist_windows_amd64.exe && pkg . -t node12-macos-x64 --output build/sharelist_macos_amd64 && pkg . -t node12-linux-x64 --output build/sharelist_linux_amd64"
},
"dependencies": {
"@koa/cors": "^2.2.1",
Expand Down
17 changes: 13 additions & 4 deletions plugins/drive.od.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,14 +685,22 @@ module.exports = ({ request, cache, getConfig, querystring, base64 , saveDrive ,

// id 当前有效路径
// target 后续实际路径
const createWriteStream = async ({ id , options = {} , size , target = ''} = {}) => {
const createWriteStream = async ({ id , size , type , name, target = ''} = {}) => {
let predata = await prepare(id)
if (!predata.credentials) return null
let { path, credentials } = predata
let { path:filepath, credentials } = predata

let fullpath = pathNormalize(path +'/' + target)
//为path 创建目的地目录
await mkdir(path , target , credentials)
await mkdir(filepath , target , credentials)


let paths = [filepath,target]
if( type == 'folder' ){
paths.push(name)
}
let fullpath = pathNormalize(paths.join('/'))

console.log(fullpath)
if( size !== undefined ){
cache.clear(`${defaultProtocol}:${id}`)
if( size <= 4194304 ){
Expand All @@ -701,6 +709,7 @@ module.exports = ({ request, cache, getConfig, querystring, base64 , saveDrive ,
return await uploadLargeFile(fullpath , size , credentials)
}
}else{
console.log('无法解析文件大小')
return { error:true , msg:'无法解析文件大小'}
}

Expand Down
4 changes: 3 additions & 1 deletion plugins/drive.odc.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,14 +717,16 @@ module.exports = ({ request, cache, getConfig, querystring, base64 , saveDrive ,

// id 当前有效路径
// target 后续实际路径
const createWriteStream = async ({ id , options = {} , size , target = ''} = {}) => {
const createWriteStream = async ({ id , size , target = ''} = {}) => {
let predata = await prepare(id)

if (!predata.credentials) return null

let { path, credentials } = predata

let fullpath = pathNormalize(path +'/' + target)

console.log('full',fullpath)
//为path 创建目的地目录
await mkdir(path , target , credentials)

Expand Down

0 comments on commit a0f96b6

Please sign in to comment.