diff options
| author | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-06-03 07:31:19 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-03 07:31:19 +0900 |
| commit | 3bc81522c65d724de121cbe6265c60e48a8f8ae7 (patch) | |
| tree | 1d526c17f19ec0209d2a4b179cb6756e25b2b916 /packages/frontend/src/utility | |
| parent | [skip ci] Update CHANGELOG.md (prepend template) (diff) | |
| download | misskey-3bc81522c65d724de121cbe6265c60e48a8f8ae7.tar.gz misskey-3bc81522c65d724de121cbe6265c60e48a8f8ae7.tar.bz2 misskey-3bc81522c65d724de121cbe6265c60e48a8f8ae7.zip | |
enhance(frontend): IDにUUIDを使うのをやめる (#16138)
* wip
* Update flash-edit.vue
Diffstat (limited to 'packages/frontend/src/utility')
| -rw-r--r-- | packages/frontend/src/utility/get-embed-code.ts | 4 | ||||
| -rw-r--r-- | packages/frontend/src/utility/id.ts | 25 | ||||
| -rw-r--r-- | packages/frontend/src/utility/theme-editor.ts | 4 |
3 files changed, 29 insertions, 4 deletions
diff --git a/packages/frontend/src/utility/get-embed-code.ts b/packages/frontend/src/utility/get-embed-code.ts index de36314ac2..5ccd46cfe2 100644 --- a/packages/frontend/src/utility/get-embed-code.ts +++ b/packages/frontend/src/utility/get-embed-code.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-only */ import { defineAsyncComponent } from 'vue'; -import { v4 as uuid } from 'uuid'; +import { genId } from '@/utility/id.js'; import { url } from '@@/js/config.js'; import { defaultEmbedParams, embedRouteWithScrollbar } from '@@/js/embed-page.js'; import type { EmbedParams, EmbeddableEntity } from '@@/js/embed-page.js'; @@ -44,7 +44,7 @@ export function normalizeEmbedParams(params: EmbedParams): Record<string, string * 埋め込みコードを生成(iframe IDの発番もやる) */ export function getEmbedCode(path: string, params?: EmbedParams): string { - const iframeId = 'v1_' + uuid(); // 将来embed.jsのバージョンが上がったとき用にv1_を付けておく + const iframeId = 'v1_' + genId(); // 将来embed.jsのバージョンが上がったとき用にv1_を付けておく let paramString = ''; if (params) { diff --git a/packages/frontend/src/utility/id.ts b/packages/frontend/src/utility/id.ts new file mode 100644 index 0000000000..63a7f7d74c --- /dev/null +++ b/packages/frontend/src/utility/id.ts @@ -0,0 +1,25 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +// ランダムな文字列が生成できればなんでも良い(時系列でソートできるなら尚良)が、とりあえずaidの実装を拝借 + +const TIME2000 = 946684800000; +let counter = Math.floor(Math.random() * 10000); + +function getTime(time: number): string { + time = time - TIME2000; + if (time < 0) time = 0; + + return time.toString(36).padStart(8, '0'); +} + +function getNoise(): string { + return counter.toString(36).padStart(2, '0').slice(-2); +} + +export function genId(): string { + counter++; + return getTime(Date.now()) + getNoise(); +} diff --git a/packages/frontend/src/utility/theme-editor.ts b/packages/frontend/src/utility/theme-editor.ts index ea07e5f2ff..74175703c3 100644 --- a/packages/frontend/src/utility/theme-editor.ts +++ b/packages/frontend/src/utility/theme-editor.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { v4 as uuid } from 'uuid'; +import { genId } from '@/utility/id.js'; import type { Theme } from '@/theme.js'; import { themeProps } from '@/theme.js'; @@ -66,7 +66,7 @@ export const convertToMisskeyTheme = (vm: ThemeViewModel, name: string, desc: st } return { - id: uuid(), + id: genId(), name, desc, author, props, base, }; }; |