Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added: http-driver #61

Closed
wants to merge 13 commits into from
53 changes: 53 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
on:
push:
branches:
- 'main'
name: Publish
jobs:
test:
name: Build & Test
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Cache node_modules
id: cache-modules
uses: actions/cache@v1
with:
path: node_modules
key: ${{ matrix.node-version }}-${{ runner.OS }}-build-${{ hashFiles('package.json') }}
- name: Build
if: steps.cache-modules.outputs.cache-hit != 'true'
run: npm install
- name: Test
run: npm_config_yes=true npx best-test@latest
publish:
name: Publish
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push' && ( github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' )
steps:
- uses: actions/checkout@v2
- name: Cache node_modules
id: cache-modules
uses: actions/cache@v1
with:
path: node_modules
key: 12.x-${{ runner.OS }}-build-${{ hashFiles('package.json') }}
- name: Build
if: steps.cache-modules.outputs.cache-hit != 'true'
run: npm install
- name: Test
run: npm_config_yes=true npx best-test@latest

- name: Publish
uses: mikeal/merge-release@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
66 changes: 0 additions & 66 deletions .github/workflows/release.yml

This file was deleted.

43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type FS
====

The single way to manipulate files in NodeJS. With Type FS you can define multiple disk locations over common protocols such as file, s3 etc. and then use the the disk manager to manipulate files in those disks.
The single way to manipulate files in NodeJS. With Type FS you can define multiple disk locations across common protocols such as **file://** or **s3://**. Use the disk manager to manipulate files located in disks.

## Project Status

Expand Down Expand Up @@ -31,6 +31,47 @@ Please refer to the [roadmap](https://github.com/daniel-samson/typefs/projects?q
- [S3 Driver](https://typefs.io/docs/drivers/s3)
- [Disk Driver API](https://typefs.io/docs/api/disk-driver)

## Example

```typescript
// index.ts
import { Storage, Configuration } from 'typefs;

Storage.config: Configuration = {
default: 'assets',
disks: {
tmp: {
driver: 'file',
root: '/tmp/',
jail: true,
}
app: {
driver: 'file',
root: '/app/',
jail: true,
}
assets: {
driver: 'file',
root: '/app/public/assets/'
jail: true,
}
s3: {
driver: 's3',
root: '/'
jail: true,
"bucket": process.env.S3_BUCKET || 'my-s3-bucket',
"endPoint": process.env.S3_ENDPOINT || 's3.amazonaws.com',
"accessKey": process.env.S3_ACCESS_KEY || 'minio-access-key',
"secretKey": process.env.S3_SECRET_KEY || 'minio-secret-key',
}
}
}


const logoPng: Buffer = await Storage.disk().read('logo.png');

```

## Contribute

- [Ask a question](https://github.com/daniel-samson/typefs/issues/new?assignees=&labels=question&template=question.md&title=Question%3A+)
Expand Down
11 changes: 8 additions & 3 deletions lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { URL } from 'url';
import { WebDAVClientOptions } from 'webdav';

/**
* The types of available Drivers (note: some are note implemented yet)
Expand Down Expand Up @@ -42,11 +43,15 @@ export interface FileDisk {
/**
* WebDav storage
*/
export interface HttpDisk {
export interface HttpDisk extends WebDAVClientOptions {
/**
* The URL of the http service
* Defines where paths are relative to
*/
root: string,
/**
* Dont allow paths outside root
*/
endPoint: URL;
jail: boolean
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/drivers/disk-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export abstract class DiskDriver {
*
* @param {string} path relative to root of disk
* @param {ListDirectoryOptions} options eg. set recursive to true
* @returns {Promise<void>}
* @returns {Promise<string>}
* @throws Error when path is outside root directory and
* configuration.jail is set to true
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/drivers/file-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class FileDriver extends DiskDriver {
*
* @param {string} path relative to root of disk
* @param {ListDirectoryOptions} options eg. set recursive to true
* @returns {Promise<void>}
* @returns {Promise<string>}
* @throws Error when path is outside root directory and
* configuration.jail is set to true
*/
Expand Down
Loading