diff --git a/index.js b/index.js index 49bcb3d..8e29528 100644 --- a/index.js +++ b/index.js @@ -99,6 +99,7 @@ module.exports = class ServeDrive extends ReadyResource { const pathname = unixPathResolve('/', path) const params = [] + if (opts.key) params.push('roomKey=' + opts.roomKey) if (opts.key) params.push('key=' + opts.key) if (opts.version) params.push('version=' + opts.version) const query = params.length ? ('?' + params.join('&')) : '' @@ -200,6 +201,7 @@ module.exports = class ServeDrive extends ReadyResource { const { pathname, searchParams } = parseURL(req.url) const filename = decodePathName(pathname) let key = searchParams.get('key') || null + let roomKey = searchParams.get('roomKey') || null const version = parseInt(searchParams.get('version') || 0, 10) if (key !== null) { @@ -213,6 +215,17 @@ module.exports = class ServeDrive extends ReadyResource { } } + if (roomKey !== null) { + try { + roomKey = HypercoreId.decode(roomKey) + } catch (err) { + safetyCatch(err) + res.writeHead(400) + res.end() + return + } + } + if (Number.isNaN(version)) { res.writeHead(400) res.end() @@ -229,7 +242,7 @@ module.exports = class ServeDrive extends ReadyResource { let error = null try { - drive = await this._getDrive({ key, filename, version }) + drive = await this._getDrive({ roomKey, key, filename, version }) if (!this.closing) { await this._driveToRequest(req, res, key, drive, filename, version)