Skip to content

Commit

Permalink
permission stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmywarting committed Sep 23, 2021
1 parent 8a5393c commit df68e69
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
34 changes: 24 additions & 10 deletions src/FileSystemHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,34 @@ class FileSystemHandle {
this[kAdapter] = adapter
}

async queryPermission (options = {}) {
if (options.readable) return 'granted'
async queryPermission ({mode = 'read'} = {}) {
const handle = this[kAdapter]
return handle.queryPermission ?
await handle.queryPermission(options) :
handle.writable
? 'granted'
: 'denied'
if (handle.queryPermission) {
return handle.queryPermission({mode})
}

if (mode === 'read') {
return 'granted'
} else if (mode === 'readwrite') {
return handle.writable ? 'granted' : 'denied'
} else {
throw new TypeError(`Mode ${mode} must be 'read' or 'readwrite'`)
}
}

async requestPermission (options = {}) {
if (options.readable) return 'granted'
async requestPermission ({mode = 'read'} = {}) {
const handle = this[kAdapter]
return handle.writable ? 'granted' : 'denied'
if (handle.requestPermission) {
return handle.requestPermission({mode})
}

if (mode === 'read') {
return 'granted'
} else if (mode === 'readwrite') {
return handle.writable ? 'granted' : 'denied'
} else {
throw new TypeError(`Mode ${mode} must be 'read' or 'readwrite'`)
}
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/adapters/node.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import fs from 'fs/promises'
import { errors } from '../util.js'
import { join } from 'path'
import fs from 'node:fs/promises'
import { join } from 'node:path'
import 'node-domexception'
import Blob from 'fetch-blob'
import { fileFrom } from 'fetch-blob/from.js'
import DOMException from 'node-domexception'

import { errors } from '../util.js'
// import mime from 'mime-types'

const { INVALID, GONE, MISMATCH, MOD_ERR, SYNTAX } = errors
Expand Down

0 comments on commit df68e69

Please sign in to comment.