Skip to content

Commit

Permalink
最新の main に対応
Browse files Browse the repository at this point in the history
  • Loading branch information
YutaUra committed Nov 15, 2023
1 parent 59dcddb commit b203f7e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions bench/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ bench: build

clean:
$(RM) ./bin/bench_darwin_amd64
$(RM) ./bin/bench_darwin_arm64
$(RM) ./bin/bench_linux_amd64
$(RM) ./bin/bench_linux_arm64
7 changes: 7 additions & 0 deletions webapp/node/src/bun.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { join } from 'node:path'
// eslint-disable-next-line import/no-unresolved
import { file } from 'bun'
import { createApp } from './create-app'
import { Deps } from './types/application'

Expand Down Expand Up @@ -28,6 +31,10 @@ const deps = {
comparePassword: async (password: string, hash: string) =>
Bun.password.verify(password, hash, 'bcrypt'),
uuid: () => crypto.randomUUID(),
fallbackUserIcon: file(
// eslint-disable-next-line unicorn/prefer-module
join(__dirname, '../../img/NoImage.jpg'),
).arrayBuffer(),
} satisfies Deps

const app = createApp(deps)
Expand Down
3 changes: 2 additions & 1 deletion webapp/node/src/handlers/livecomment-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,15 @@ livecommentHandler.post(
`
DELETE FROM livecomments
WHERE
id = ? AND
(SELECT COUNT(*)
FROM
(SELECT ? AS text) AS texts
INNER JOIN
(SELECT CONCAT('%', ?, '%') AS pattern) AS patterns
ON texts.text LIKE patterns.pattern) >= 1;
`,
[livecomment.comment, ngword.word],
[livecomment.id, livecomment.comment, ngword.word],
)
.catch(throwErrorWith('failed to delete livecomment'))
}
Expand Down
3 changes: 3 additions & 0 deletions webapp/node/src/handlers/user-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ userHandler.get(
)
.catch(throwErrorWith('failed to get icon'))
if (!icon) {
return c.body(await c.get('deps').fallbackUserIcon, 200, {
'Content-Type': 'image/jpeg',
})
await conn.rollback()
return c.text('not found icon', 404)
}
Expand Down
13 changes: 13 additions & 0 deletions webapp/node/src/node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { spawn } from 'node:child_process'
import { randomUUID } from 'node:crypto'
import { readFile } from 'node:fs/promises'
import { join } from 'node:path'
import { serve } from '@hono/node-server'
import { hash, compare } from 'bcrypt'
import { createApp } from './create-app'
Expand Down Expand Up @@ -29,6 +31,17 @@ const deps = {
comparePassword: async (password: string, hash: string) =>
compare(password, hash),
uuid: () => randomUUID(),
// eslint-disable-next-line unicorn/prefer-module, unicorn/prefer-top-level-await
fallbackUserIcon: readFile(join(__dirname, '../../img/NoImage.jpg')).then(
(v) => {
const buf = v.buffer
if (buf instanceof ArrayBuffer) {
return buf
} else {
throw new TypeError(`NoImage.jpg should be ArrayBuffer, but ${buf}`)
}
},
),
} satisfies Deps

const app = createApp(deps)
Expand Down
1 change: 1 addition & 0 deletions webapp/node/src/types/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface Deps {
comparePassword: (password: string, hash: string) => Promise<boolean>
// TODO: remove
uuid: () => string
fallbackUserIcon: Promise<Readonly<ArrayBuffer>>
}

export interface ApplicationDeps extends Deps {
Expand Down

0 comments on commit b203f7e

Please sign in to comment.