Skip to content

Commit

Permalink
chore: add paths support for driver
Browse files Browse the repository at this point in the history
  • Loading branch information
reruin committed Aug 27, 2021
1 parent a7dc525 commit e4b46cc
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/sharelist-core/lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,19 @@ module.exports = (app) => {
return ret
}

const get = async ({ id }) => {
const get = async ({ paths = [], id }) => {
if (!id && paths) {
if (paths.length == 0) {
return {
id: 'root:https://sharelist', name: 'Sharelist', type: 'folder', size: 0, ctime: Date.now(), mtime: Date.now()
}
} else {
id = await getIdFromPath(paths)
}
}

if (!id) return { error: { code: 404, message: `can't find file in this paths: ${paths.join('/')}` } }

const [protocol, fid] = parseProtocol(id)

let driver = app.getDriver(protocol)
Expand All @@ -55,6 +67,16 @@ module.exports = (app) => {
return data
}

const getIdFromPath = async (paths) => {
let parentPath = paths.slice(0, paths.length - 1)
let filename = paths[paths.length - 1]
let parent = await forwardTrack(parentPath)

if (parent.error) return undefined

return parent?.files.find(i => i.name == filename)?.id
}

const getStream = async (id, options) => {
let data = await get({ id })

Expand Down

0 comments on commit e4b46cc

Please sign in to comment.