fix: generate compatible id with front app

This commit is contained in:
Kilian Decaderincourt 2021-09-10 18:52:42 +02:00
parent c3858e9466
commit aea414e072
2 changed files with 5 additions and 3 deletions

View File

@ -11,7 +11,7 @@ import {
import { Response } from 'express';
import { StorageNamespace, StorageService } from 'src/storage/storage.service';
import { Readable } from 'stream';
import { nanoid } from 'nanoid';
import { customAlphabet } from 'nanoid';
@Controller()
export class ScenesController {
@ -31,9 +31,11 @@ export class ScenesController {
@Post()
async create(@Body() payload: Buffer) {
// Excalidraw front-end only support numeric id, we can't use nanoid default alphabet
const nanoid = customAlphabet('0123456789', 16);
const id = nanoid();
// Nanoid has similar collision probability as uuid v4, so the following should *never* happen
// Check for collision
if (await this.storageService.get(id, this.namespace)) {
throw new InternalServerErrorException();
}

View File

@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import * as Keyv from 'keyv';
import * as Keyv from '@keyvhq/core';
@Injectable()
export class StorageService {