Skip to content

Commit

Permalink
feat(http): support ctx.http.isError
Browse files Browse the repository at this point in the history
also fix file-type imports
  • Loading branch information
shigma committed May 11, 2024
1 parent 6ca21e9 commit f141278
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/adapter/node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fileURLToPath } from 'node:url'
import { basename } from 'node:path'
import { fromBuffer } from 'file-type'
import FileType from 'file-type'
import { FileResponse } from '../index.js'
import { readFile } from 'node:fs/promises'

Expand All @@ -9,7 +9,7 @@ export { lookup } from 'node:dns/promises'
export async function loadFile(url: string): Promise<FileResponse | undefined> {
if (url.startsWith('file://')) {
const data = await readFile(fileURLToPath(url))
const result = await fromBuffer(data)
const result = await FileType.fromBuffer(data)
// https://stackoverflow.com/questions/8609289/convert-a-binary-nodejs-buffer-to-javascript-arraybuffer#answer-31394257
const buffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)
return { mime: result?.mime, filename: basename(url), data: buffer }
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ export class HTTP extends Service<HTTP.Config> {
}
}

public isError = HTTPError.is

private _decoders: Dict = Object.create(null)

constructor(config?: HTTP.Config)
Expand Down

0 comments on commit f141278

Please sign in to comment.