Skip to content

Commit

Permalink
docs: updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
Rezrazi committed Aug 17, 2024
1 parent 735f2d1 commit 9f8e16e
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,79 @@ npm i @oneduo/nestjs-flystorage
You may start using the module by importing it into your application.

```typescript
import { resolve } from 'path';
import { FileStorage } from '@flystorage/file-storage';
import { LocalStorageAdapter } from '@flystorage/local-fs';

const rootDirectory = resolve(process.cwd(), 'files');
const adapter = new LocalStorageAdapter(rootDirectory);
const storage = new FileStorage(adapter);

const DISK_NAME: DiskToken = 'disks:files';

const disks: Disk[] = [
{
token: DISK_NAME,
storage,
},
]

@Module({
imports: [FlyStorageModule.forRoot({
isGlobal: true,
disks,
})],
// ...
})
```

And then to inject the storage within your application:

```typescript
import { InjectStorage } from "@oneduo/nestjs-flystorage";

@Injectable()
export class AppService {
constructor(@InjectStorage(DISK_NAME) storage: FileStorage) {}
}
```

### Overriding disk for tests

Let's imagine you're using S3 or any other storage within your application, however you do not wish to implement mocks for your tests.
As Flystorage exposes a unified API that is adaptable to all supported storages, you can easily override the registered disk to use another adapter, such as the in-memory adapter.

```typescript
import { FileStorage } from "@flystorage/file-storage";
import { InMemoryStorageAdapter } from "@flystorage/in-memory";

const adapter = new InMemoryStorageAdapter();
const storage = new FileStorage(adapter);

describe("AppController", () => {
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
})
// add the following
.overrideProvider(DISK_NAME)
.useValue(storage)
.compile();
});
});
```

## Credits

- [duna-oss/flystorage](https://github.com/duna-oss/flystorage)

## Authors

- [Charaf Rezrazi](https://www.github.com/rezrazi)

See also the list of contributors who participated in this project.

## License

The MIT License (MIT). Please see [License](https://choosealicense.com/licenses/mit/) File for more information.

0 comments on commit 9f8e16e

Please sign in to comment.