Skip to content

Latest commit

 

History

History
204 lines (156 loc) · 10.4 KB

fbstorage.js.md

File metadata and controls

204 lines (156 loc) · 10.4 KB

fbstorage

Interface to Google Cloud Storage in the security context of the authenticated user. Keep track of every file add/remove in firestore because firebase cloud storage does not allow listing/searching for files. Use the REST API directly because the node.js interface does not include storage.

After initialization the fbstorage module will contain 3 objects:

  • .file - file access limited to the current signed-in user
  • .app - file access limited to any user of this app but not other apps
  • .public - file access without restriction

See

Example

const { fbstorage } = require( 'electron-firebase' )
// get list of folders only accessible to the signed-in user
const fileFolderList = await fbstorage.file.folders()

initialize() ⏏

Firebase Storage interfaces are defined when your app starts (this function must be called after firestore is initialized).

Kind: Exported function

initialize~fileStore

Kind: inner class of initialize

new fileStore(firestoreRoot, storeName, setPrefix)

Create a new fileStore interface.

Param Type Description
firestoreRoot string a database object defined in firestore.js
storeName string just a moniker
setPrefix string the first two segments of the file path, e.g. user/userid

fileStore.find(filepath, queryMatch) ⇒ object

Search the storage records in the Firestore database for a file matching the specific filepath given. The newest document matching the search criteria will be returned.

Kind: instance method of fileStore
Returns: object - - metafile descriptor for the requested file

Param Type Default Description
filepath string Path and filename to store the file in the Cloud
queryMatch string "path" optional match parameter to query for something other than path

fileStore.list(folderpath, queryMatch) ⇒ object

Search the storage records in the Firestore database for all files where their folder matches the specific path given, and return an array with the metadata for each file.

Kind: instance method of fileStore
Returns: object - - metafile descriptor for the requested file

Param Type Default Description
folderpath string Path to query file storage
queryMatch string "folder" optional match parameter to query for something other than folder

fileStore.folders(filepath, content)

Return a list of all folders. Folders don't really exist, they are just a slash-separated path construct, the parent of the file path.

Kind: instance method of fileStore

Param Type
filepath *
content *

fileStore.upload(filepath, content) ⇒ object

Uploads local content and creates a file in Google Cloud Storage for Firebase, and a record of the file will be kept in the Cloud Firestore database, for easy reference and searching. Accepts contents as string, JSON string, object (serializable), array, or buffer. Returns a Promise containing file metadata, as:

Kind: instance method of fileStore
Returns: object - - metafile descriptor for the requested file

Param Type Description
filepath string Path and filename to store the file in the Cloud
content string | JSON | buffer | object | array File content to be written, objects must be serializable

Example

{ name: 'users/[user-id]/Test/FileTest',
  bucket: 'your-app-here.appspot.com',
  generation: '123456789123456',
  metageneration: '1',
  contentType: 'application/json',
  timeCreated: '2019-02-05T03:06:24.435Z',
  updated: '2019-02-05T03:06:24.435Z',
  storageClass: 'STANDARD',
  size: '1005',
  md5Hash: 'H3Anb534+vX2Y1HVwJxlyw==',
  contentEncoding: 'identity',
  contentDisposition: 'inline; filename*=utf-8\'\'FileTest',
  crc32c: 'yTf15w==',
  etag: 'AAAAAAA=',
  downloadTokens: '00000000' 
}

fileStore.update(filepath, metadata) ⇒ object

Change some metadata aspects of a stored file

Kind: instance method of fileStore
Returns: object - - metafile descriptor for the requested file

Param Type Description
filepath string Path and filename to update the file in the Cloud, relative to the current user
metadata One or more metadata parameters to change
metadata.cacheControl string https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
metadata.contentDisposition string https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/content-Disposition
metadata.contentEncoding string https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
metadata.contentLanguage string https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Language
metadata.contentType string https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type

fileStore.download(filepath) ⇒ string | JSON | buffer | object | array

Download a file from Firebase Storage

Kind: instance method of fileStore
Returns: string | JSON | buffer | object | array - - file content

Param Type Description
filepath string Path and filename to retreive the file

fileStore.about(filepath) ⇒ Promise

Gets meta information about the file, including a secure download URL that can be used anywhere

Kind: instance method of fileStore
Returns: Promise - A Promise object representing the meta information about the file

Param Type Description
filepath string Path and filename to find the file in the Cloud, relative to the current user

fileStore.delete(filepath) ⇒ null | string

Delete the file from Google Cloud Storage for Firebase and remove the file's record from Cloud Firestore

Kind: instance method of fileStore
Returns: null | string - - empty response unless there is an error

Param Type Description
filepath string Path and filename to delete the file in the Cloud, relative to the current user