Skip to content

Commit

Permalink
feat: use ULID
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed May 16, 2024
1 parent 6330025 commit 06bdbc2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

ローカルマシンに直接インストールする

https://nodejs.org/ja/ の左ボタン、LTS をダウンロードしてインストール
https://nodejs.org/ の左ボタン、LTS をダウンロードしてインストール

### リポジトリのクローンと npm モジュールのインストール

Expand Down
6 changes: 3 additions & 3 deletions server/domain/task/model/taskMethod.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { TaskEntity, TaskUpdateVal } from 'api/@types/task';
import type { UserEntity } from 'api/@types/user';
import assert from 'assert';
import { randomUUID } from 'crypto';
import { deletableTaskIdParser, taskIdParser } from 'service/idParsers';
import { s3 } from 'service/s3Client';
import { ulid } from 'ulid';
import type { TaskCreateServerVal, TaskDeleteVal, TaskSaveVal } from './taskEntity';

export const taskMethod = {
create: async (user: UserEntity, val: TaskCreateServerVal): Promise<TaskSaveVal> => {
const task: TaskEntity = {
id: taskIdParser.parse(randomUUID()),
id: taskIdParser.parse(ulid()),
done: false,
label: val.label,
image: undefined,
Expand All @@ -19,7 +19,7 @@ export const taskMethod = {

if (val.image === undefined) return { task };

const s3Key = `tasks/images/${randomUUID()}.${val.image.filename.split('.').at(-1)}`;
const s3Key = `tasks/images/${ulid()}.${val.image.filename.split('.').at(-1)}`;
const url = await s3.getSignedUrl(s3Key);

return {
Expand Down
14 changes: 14 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"dotenv": "^16.4.5",
"fastify": "^4.26.2",
"firebase-admin": "^12.1.0",
"ulid": "^2.3.0",
"velona": "^0.8.0",
"zod": "^3.23.6"
},
Expand Down

0 comments on commit 06bdbc2

Please sign in to comment.