feat: support multiple database

This commit is contained in:
Kilian Decaderincourt
2021-09-08 15:31:02 +02:00
parent 1de829e192
commit 6e6dbb7959
10 changed files with 1302 additions and 46 deletions

View File

@ -8,17 +8,19 @@ import {
Res,
} from '@nestjs/common';
import { Response } from 'express';
import { MemoryService } from 'src/storages/memory.service';
import { StorageNamespace, StorageService } from 'src/storage/storage.service';
import { hash, hexadecimalToDecimal } from 'src/utils';
import { Readable } from 'stream';
@Controller()
export class ScenesController {
constructor(private storageService: MemoryService) {}
namespace = StorageNamespace.SCENES;
constructor(private storageService: StorageService) {}
@Get(':id')
@Header('content-type', 'application/octet-stream')
async findOne(@Param() params, @Res() res: Response): Promise<void> {
const data = await this.storageService.load(params.id);
const data = await this.storageService.get(params.id, this.namespace);
const stream = new Readable();
stream.push(data);
@ -28,11 +30,10 @@ export class ScenesController {
@Post()
async create(@Body() payload: Buffer) {
const drawingHash = hash(payload);
const id = hexadecimalToDecimal(drawingHash);
await this.storageService.save(id, payload);
await this.storageService.set(id, payload, this.namespace);
return {
id,