fix: generate compatible id with front app
This commit is contained in:
parent
c3858e9466
commit
aea414e072
@ -11,7 +11,7 @@ import {
|
|||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { StorageNamespace, StorageService } from 'src/storage/storage.service';
|
import { StorageNamespace, StorageService } from 'src/storage/storage.service';
|
||||||
import { Readable } from 'stream';
|
import { Readable } from 'stream';
|
||||||
import { nanoid } from 'nanoid';
|
import { customAlphabet } from 'nanoid';
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class ScenesController {
|
export class ScenesController {
|
||||||
@ -31,9 +31,11 @@ export class ScenesController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
async create(@Body() payload: Buffer) {
|
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();
|
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)) {
|
if (await this.storageService.get(id, this.namespace)) {
|
||||||
throw new InternalServerErrorException();
|
throw new InternalServerErrorException();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
import * as Keyv from 'keyv';
|
import * as Keyv from '@keyvhq/core';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class StorageService {
|
export class StorageService {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user