Skip to content

Commit

Permalink
Merge pull request #66 from Ray-D-Song/refactor
Browse files Browse the repository at this point in the history
refactor: enable typescript strict mode for server
  • Loading branch information
Ray-D-Song authored Dec 13, 2024
2 parents e6cb743 + a9b0ff7 commit b3686f9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/server/src/api/folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ app.put(

return {
id: Number(value.id),
name: value.name as string | undefined,
name: value.name,
}
}),
async (c) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/server/src/api/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ app.get(
c.res.headers.set('Content-Type', 'image/webp')
c.res.headers.set('cache-control', 'private, max-age=31536000')

if (isNil(screenshot)) {
return c.body(null)
}

return c.body(await screenshot.arrayBuffer())
},
)
Expand Down
3 changes: 2 additions & 1 deletion packages/server/src/api/showcase.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isNotNil } from '@web-archive/shared/utils'
import { Hono } from 'hono'
import { validator } from 'hono/validator'
import type { HonoTypeUserInformation } from '~/constants/binding'
Expand Down Expand Up @@ -28,7 +29,7 @@ app.post(
const pages = await queryShowcase(c.env.DB, { pageNumber, pageSize })

pages.list = await Promise.all(pages.list.map(async (page) => {
const screenshot = await getBase64FileFromBucket(c.env.BUCKET, page.screenshotId, 'image/png')
const screenshot = isNotNil(page.screenshotId) && await getBase64FileFromBucket(c.env.BUCKET, page.screenshotId, 'image/png')
return {
...page,
screenshot,
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/model/folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function getFolderById(DB: D1Database, options: { id: number, isDeleted?:
WHERE id = ?
`
const folder = await DB.prepare(sql).bind(id).first<Folder>()
if (isNotNil(isDeleted) && folder.isDeleted !== Number(isDeleted)) {
if (isNotNil(isDeleted) && folder?.isDeleted !== Number(isDeleted)) {
return null
}
return folder
Expand All @@ -108,7 +108,7 @@ async function selectDeletedFolderTotalCount(DB: D1Database) {
WHERE isDeleted == 1
`
const sqlResult = await DB.prepare(sql).first<{ count: number }>()
return sqlResult.count
return sqlResult?.count ?? 0
}

async function restoreFolder(DB: D1Database, id: number) {
Expand Down
1 change: 1 addition & 0 deletions packages/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@cloudflare/workers-types",
"vite/client"
],
"strict": true,
"outDir": "./dist/server"
},
"include": ["*.ts", "./src/**/*.ts"]
Expand Down

0 comments on commit b3686f9

Please sign in to comment.