feat: add support for collabs room
This commit is contained in:
parent
3fcd00e9ca
commit
6b525d0f64
@ -8,11 +8,11 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "80:80"
|
||||||
environment:
|
environment:
|
||||||
BACKEND_V1_GET_URL: ' '
|
BACKEND_V2_GET_URL: http://localhost:8080/api/v2/scenes/
|
||||||
BACKEND_V2_GET_URL: http://localhost:8080/api/v2/
|
BACKEND_V2_POST_URL: http://localhost:8080/api/v2/scenes/
|
||||||
BACKEND_V2_POST_URL: http://localhost:8080/api/v2/
|
|
||||||
SOCKET_SERVER_URL: http://localhost:5000/
|
SOCKET_SERVER_URL: http://localhost:5000/
|
||||||
|
STORAGE_BACKEND: "http"
|
||||||
|
HTTP_STORAGE_BACKEND_URL: "http://localhost:8080/api/v2"
|
||||||
excalidraw-storage-backend:
|
excalidraw-storage-backend:
|
||||||
build: .
|
build: .
|
||||||
ports:
|
ports:
|
||||||
|
@ -2,10 +2,11 @@ import { MiddlewareConsumer, Module } from '@nestjs/common';
|
|||||||
import { RawParserMiddleware } from './raw-parser.middleware';
|
import { RawParserMiddleware } from './raw-parser.middleware';
|
||||||
import { ScenesController } from './scenes/scenes.controller';
|
import { ScenesController } from './scenes/scenes.controller';
|
||||||
import { StorageService } from './storage/storage.service';
|
import { StorageService } from './storage/storage.service';
|
||||||
|
import { RoomsController } from './rooms/rooms.controller';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [],
|
imports: [],
|
||||||
controllers: [ScenesController],
|
controllers: [ScenesController, RoomsController],
|
||||||
providers: [StorageService],
|
providers: [StorageService],
|
||||||
})
|
})
|
||||||
export class AppModule {
|
export class AppModule {
|
||||||
|
@ -9,7 +9,7 @@ function isLogLevel(value: any): value is LogLevel {
|
|||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const logLevel = isLogLevel(process.env.LOG_LEVEL)
|
const logLevel = isLogLevel(process.env.LOG_LEVEL)
|
||||||
? process.env.LOG_LEVEL
|
? process.env.LOG_LEVEL
|
||||||
: 'debug';
|
: 'log';
|
||||||
|
|
||||||
const app = await NestFactory.create(AppModule, {
|
const app = await NestFactory.create(AppModule, {
|
||||||
cors: true,
|
cors: true,
|
||||||
|
@ -2,7 +2,7 @@ import { Injectable, NestMiddleware } from '@nestjs/common';
|
|||||||
import { raw } from 'express';
|
import { raw } from 'express';
|
||||||
import { hasBody } from 'type-is';
|
import { hasBody } from 'type-is';
|
||||||
|
|
||||||
// Excalidraw Front end doesn't send a Content Type Header
|
// Excalidraw Front end doesn't send a Content Type Header
|
||||||
// so we tell raw parser to check if there is a body
|
// so we tell raw parser to check if there is a body
|
||||||
const rawParserMiddleware = raw({ type: hasBody });
|
const rawParserMiddleware = raw({ type: hasBody });
|
||||||
|
|
||||||
|
18
src/rooms/rooms.controller.spec.ts
Normal file
18
src/rooms/rooms.controller.spec.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { RoomsController } from './rooms.controller';
|
||||||
|
|
||||||
|
describe('RoomsController', () => {
|
||||||
|
let controller: RoomsController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [RoomsController],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
controller = module.get<RoomsController>(RoomsController);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(controller).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
49
src/rooms/rooms.controller.ts
Normal file
49
src/rooms/rooms.controller.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
Header,
|
||||||
|
Logger,
|
||||||
|
NotFoundException,
|
||||||
|
Param,
|
||||||
|
Put,
|
||||||
|
Res,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { Response } from 'express';
|
||||||
|
import { StorageNamespace, StorageService } from 'src/storage/storage.service';
|
||||||
|
import { Readable } from 'stream';
|
||||||
|
|
||||||
|
@Controller('rooms')
|
||||||
|
export class RoomsController {
|
||||||
|
private readonly logger = new Logger(RoomsController.name);
|
||||||
|
namespace = StorageNamespace.ROOMS;
|
||||||
|
|
||||||
|
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.get(params.id, this.namespace);
|
||||||
|
this.logger.debug(`Get room ${params.id}`);
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
const stream = new Readable();
|
||||||
|
stream.push(data);
|
||||||
|
stream.push(null);
|
||||||
|
stream.pipe(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put(':id')
|
||||||
|
async create(@Param() params, @Body() payload: Buffer) {
|
||||||
|
const id = params.id;
|
||||||
|
await this.storageService.set(id, payload, this.namespace);
|
||||||
|
this.logger.debug(`Created scene ${id}`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import {
|
|||||||
Header,
|
Header,
|
||||||
InternalServerErrorException,
|
InternalServerErrorException,
|
||||||
Logger,
|
Logger,
|
||||||
|
NotFoundException,
|
||||||
Param,
|
Param,
|
||||||
Post,
|
Post,
|
||||||
Res,
|
Res,
|
||||||
@ -14,7 +15,7 @@ import { StorageNamespace, StorageService } from 'src/storage/storage.service';
|
|||||||
import { Readable } from 'stream';
|
import { Readable } from 'stream';
|
||||||
import { customAlphabet } from 'nanoid';
|
import { customAlphabet } from 'nanoid';
|
||||||
|
|
||||||
@Controller()
|
@Controller('scenes')
|
||||||
export class ScenesController {
|
export class ScenesController {
|
||||||
private readonly logger = new Logger(ScenesController.name);
|
private readonly logger = new Logger(ScenesController.name);
|
||||||
namespace = StorageNamespace.SCENES;
|
namespace = StorageNamespace.SCENES;
|
||||||
@ -26,6 +27,10 @@ export class ScenesController {
|
|||||||
const data = await this.storageService.get(params.id, this.namespace);
|
const data = await this.storageService.get(params.id, this.namespace);
|
||||||
this.logger.debug(`Get scene ${params.id}`);
|
this.logger.debug(`Get scene ${params.id}`);
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
const stream = new Readable();
|
const stream = new Readable();
|
||||||
stream.push(data);
|
stream.push(data);
|
||||||
stream.push(null);
|
stream.push(null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user