Skip to content

Commit

Permalink
replace uuid with nanoid
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-sz committed Oct 26, 2023
1 parent 73976ba commit 44fa796
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 24 deletions.
3 changes: 1 addition & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"@filedrop/types": "*",
"@types/react": "^18.2.31",
"@types/react-dom": "^18.2.14",
"@types/uuid": "^9.0.3",
"base64-js": "^1.5.1",
"clsx": "^2.0.0",
"eslint-config-react-app": "^7.0.1",
Expand All @@ -27,6 +26,7 @@
"matcrypt": "^1.3.0",
"mobx": "^6.10.2",
"mobx-react-lite": "^4.0.5",
"nanoid": "^5.0.2",
"preact": "^10.18.1",
"preact-compat": "^3.19.0",
"pwanow": "^0.0.1",
Expand All @@ -38,7 +38,6 @@
"react-icons": "^4.11.0",
"sass": "^1.69.4",
"typesocket": "^1.0.2",
"uuid": "^9.0.0",
"vite-plugin-info": "^0.4.1",
"wouter": "^2.12.1"
},
Expand Down
4 changes: 2 additions & 2 deletions web/src/stores/ChatStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Message,
MessageType,
} from '@filedrop/types';
import { v4 } from 'uuid';
import { nanoid } from 'nanoid';

import type { Connection } from './Connection.js';
import { ChatItemModel } from '../types/Models.js';
Expand Down Expand Up @@ -108,7 +108,7 @@ export class ChatStore {

const array = this.channelItems.get(channel)!;
array.push({
id: v4(),
id: nanoid(),
date: new Date(),
clientId: senderId,
message,
Expand Down
4 changes: 2 additions & 2 deletions web/src/stores/Transfer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeAutoObservable, runInAction } from 'mobx';
import { v4 } from 'uuid';
import { nanoid } from 'nanoid';
import {
ActionMessageActionType,
ActionMessageModel,
Expand Down Expand Up @@ -36,7 +36,7 @@ export class Transfer {
public fileSize: number,
public fileType: string,
public preview?: string,
public transferId: string = v4(),
public transferId: string = nanoid(),
public receiving = false
) {
this.state = receiving ? TransferState.INCOMING : TransferState.OUTGOING;
Expand Down
3 changes: 1 addition & 2 deletions ws/__tests__/ClientManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from 'uuid';
import {
ActionMessageActionType,
TargetedMessageModel,
Expand Down Expand Up @@ -168,7 +167,7 @@ describe('ClientManager', () => {
type: MessageType.ACTION,
action: ActionMessageActionType.ACCEPT,
targetId: client2.clientId!,
transferId: uuid(),
transferId: 'ay3UIn8k4QsznfyHCt9mh',
};

clientManager.handleMessage(client1, targetedMessage);
Expand Down
2 changes: 0 additions & 2 deletions ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"@fastify/websocket": "^8.2.0",
"@filedrop/types": "*",
"@types/node": "^20.4.5",
"@types/uuid": "^9.0.3",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
Expand All @@ -19,7 +18,6 @@
"fastify": "^4.21.0",
"joi": "^17.6.0",
"tsx": "^3.12.8",
"uuid": "^9.0.0",
"ws": "^8.6.0"
},
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions ws/src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const chatMessageModelSchema = Joi.object({

const transferMessageModelSchema = Joi.object({
type: Joi.string().equal(MessageType.TRANSFER).required(),
transferId: Joi.string().uuid().required(),
transferId: Joi.string().max(36).required(),
targetId: Joi.string().hex().required(),
fileName: Joi.string().required(),
fileSize: Joi.number().required(),
Expand All @@ -59,7 +59,7 @@ const transferMessageModelSchema = Joi.object({
const validActions = Object.values(ActionMessageActionType);
const actionMessageModelSchema = Joi.object({
type: Joi.string().equal(MessageType.ACTION).required(),
transferId: Joi.string().uuid().required(),
transferId: Joi.string().max(36).required(),
targetId: Joi.string().hex().required(),
action: Joi.string()
.equal(...validActions)
Expand All @@ -68,7 +68,7 @@ const actionMessageModelSchema = Joi.object({

const rtcDescriptionMessageModelSchema = Joi.object({
type: Joi.string().equal(MessageType.RTC_DESCRIPTION).required(),
transferId: Joi.string().uuid().required(),
transferId: Joi.string().max(36).required(),
targetId: Joi.string().hex().required(),
data: Joi.object({
type: Joi.string().required(),
Expand All @@ -78,7 +78,7 @@ const rtcDescriptionMessageModelSchema = Joi.object({

const rtcCandidateMessageModelSchema = Joi.object({
type: Joi.string().equal(MessageType.RTC_CANDIDATE).required(),
transferId: Joi.string().uuid().required(),
transferId: Joi.string().max(36).required(),
targetId: Joi.string().hex().required(),
data: Joi.object().required(),
}).required();
Expand Down
15 changes: 5 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1719,11 +1719,6 @@
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.4.tgz#0a41252ad431c473158b22f9bfb9a63df7541cff"
integrity sha512-MMzuxN3GdFwskAnb6fz0orFvhfqi752yjaXylr0Rp4oDg5H0Zn1IuyRhDVvYOwAXoJirx2xuS16I3WjxnAIHiQ==

"@types/uuid@^9.0.3":
version "9.0.6"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.6.tgz#c91ae743d8344a54b2b0c691195f5ff5265f6dfb"
integrity sha512-BT2Krtx4xaO6iwzwMFUYvWBWkV2pr37zD68Vmp1CDV196MzczBRxuEpD6Pr395HAgebC/co7hOphs53r8V7jew==

"@types/ws@^8.5.3":
version "8.5.8"
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.8.tgz#13efec7bd439d0bdf2af93030804a94f163b1430"
Expand Down Expand Up @@ -4498,6 +4493,11 @@ nanoid@^3.3.6:
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c"
integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==

nanoid@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-5.0.2.tgz#97588ebc70166d0feaf73ccd2799bb4ceaebf692"
integrity sha512-2ustYUX1R2rL/Br5B/FMhi8d5/QzvkJ912rBYxskcpu0myTHzSZfTr1LAS2Sm7jxRUObRrSBFoyzwAhL49aVSg==

natural-compare-lite@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz#17b09581988979fddafe0201e931ba933c96cbb4"
Expand Down Expand Up @@ -5981,11 +5981,6 @@ util-deprecate@^1.0.1, util-deprecate@~1.0.1:
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==

uuid@^9.0.0:
version "9.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30"
integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==

[email protected]:
version "2.3.0"
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
Expand Down

0 comments on commit 44fa796

Please sign in to comment.