Skip to content

Commit

Permalink
fix: bonjour service name conflict(reruin#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
reruin committed Jan 25, 2021
1 parent 0776ebc commit 1b9707c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
3 changes: 2 additions & 1 deletion endpoints/rss.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ class RSS {
start() {
let { app, path } = this
let port = app.getConfig('port')
let sitename = app.getConfig('title')
let router = app.router().all(this.path + ':path(.*)', async (ctx, next) => {
await this.onRequest(ctx, next)
})
app.web().use(router.routes())

this.zeroconf = app.bonjour.publish({ name: 'ShareList RSS', type: 'http', port, txt: { path } })
this.zeroconf = app.bonjour.publish({ name: `ShareList RSS(${sitename})`, type: 'http', port, txt: { path } })
}

async onRequest(ctx, next) {
Expand Down
48 changes: 37 additions & 11 deletions endpoints/webdav.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,15 @@ const propfind = async (config,app) => {
}
}

const copy = async (config,app) => {
console.log(config)
}

const WebDAVResponse = async (config , app) => {
const allows = ['GET', 'HEAD', 'OPTIONS', 'PROPFIND']
const allows = ['GET', 'HEAD', 'OPTIONS', 'PROPFIND' , 'COPY']
const httpAuthRealm = "ShareList WebDAV"

let { path, method , depth } = config
let { path, method , depth , req } = config
console.log('WebDAV',method)
if( method == 'propfind' ){
return await propfind(config , app)
Expand All @@ -279,9 +283,22 @@ const WebDAVResponse = async (config , app) => {
status:'200 OK'
}
}
else if( method == 'get'){
else if( method == 'get' ){
return await get(config,app)
}else{
}
else if( method == 'put' ){
// upload
// let data = await app.command('ls', config.path)
req.pause()
let { driver , id } = await app.getDriver(config.path)
if( driver.createWriteStream ){
console.log(config.path)
let stream = await driver.createWriteStream({id})
console.log(stream)
req.pipe(stream)
}
}
else{
return {
status:'405 Method not allowed',
headers:{
Expand All @@ -304,6 +321,7 @@ class WebDAV {
start(){
let { app , path } = this
let port = app.getConfig('port')
let sitename = app.getConfig('title')

app.web().use(async (ctx,next) => {
let url = ctx.req.url
Expand All @@ -316,22 +334,30 @@ class WebDAV {
}
})

this.zeroconf = app.bonjour.publish({ name: 'ShareList WebDAV', type: 'webdav', port, txt: { path } })
this.zeroconf = app.bonjour.publish({ name: `ShareList WebDAV(${sitename})`, type: 'webdav', port, txt: { path } })
}

async onRequest(ctx,next , url){
let json = await xml2js(await parser(ctx.req),{
explicitChildren:true,
explicitArray:false
})
console.log(ctx.headers , ctx.method)
let { headers } = ctx

let method = ctx.method.toLowerCase()
let webdavData = {
data:json ,
data:{} ,
depth:ctx.get('depth'),
method:ctx.method.toLowerCase(),
method,
path: url,
basePath: this.path,
req:ctx.req
}

if( method == 'get' || method == 'propfind' ){
webdavData.data = await xml2js(await parser(ctx.req),{
explicitChildren:true,
explicitArray:false
})
}

let resp
try{
resp = await WebDAVResponse(webdavData, this.app)
Expand Down

0 comments on commit 1b9707c

Please sign in to comment.