@omegajs/serve-drive
v1.0.0
Published
HTTP drive server for entries delivery. Auto detects types like video, images, etc
Downloads
2
Readme
Serve Omega Drives
@omegajs/serve-drive
HTTP Omega Drive server for entries delivery. Auto detects types like video, images, etc
Install Via L1FE's NPM
npm config set registry https://npm.l1fe.tech
npm install @omegajs/serve-drive
Install Via L1FE's Git Repository
git clone https://lab.l1fe.tech/omega/serve-drive.git
cd serve-drive
npm install
Usage
Single drive:
const ServeDrive = require('@omegajs/serve-drive')
const Localdrive = require('@omegajs/local-drive')
const drive = new Localdrive('./my-folder')
await drive.put('/index.html', Buffer.from('hi'))
const serve = new ServeDrive({ get: ({ key, filename, version }) => drive })
await serve.ready()
console.log('Listening on http://localhost:' + serve.address().port)
// Try visiting http://localhost:49833/index.html
Multiple drives:
const Localdrive = require('@omegajs/local-drive')
const Drive = require('@omegajs/drive')
const Keeper = require('@omegajs/keeper')
const drive1 = new Localdrive('./my-folder-a')
const drive2 = new Drive(new Keeper('./vault1'))
await drive1.put('/index.html', Buffer.from('a'))
await drive2.put('/index.html', Buffer.from('b'))
const serve = new ServeDrive({
get ({ key, filename, version }) {
if (key === null) return drive1 // Default
if (key.equals(drive2.key)) return drive2
return null
}
})
await serve.ready()
console.log('Listening on http://localhost:' + serve.address().port)
// Try visiting http://localhost:49833/index.html?key=<id-or-key>
API
const serve = new ServeDrive([options])
Creates a HTTP server that serves entries from a Drive
or Localdrive
.
Available query params:
key
to select which drive to use i.e./filename?key=<id-or-key>
.version
to checkout into a specific point i.e./filename?version=<v>
.
Available options
:
{
async get ({ key, filename, version }) {}, // Return the drive or null
async release ({ key, drive }) {}, // Called after finishing a request to optionally release the drive
port: 49833,
host: '0.0.0.0',
anyPort: true,
server: null
}
serve.getLink(filename, [options])
Generates the full API link to a file.
options
includes:
{
https: false, // Set it to true to use https (default is false)
host: '', // Custom host + port (default is localhost:server-port)
key: '', // Drive id or key
version: 0 // Checkout the drive into a previous point
}
await serve.suspend()
Let the instance know you wanna suspend so it can make relevant changes.
await serve.resume()
Let the instance know you wanna resume from suspension. Will rebind the server etc.
License
Apache-2.0