mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-24 22:56:26 -08:00
uhhh...? can't test; not home. prolly doesn't work @Jack5079
This commit is contained in:
parent
4fdada5cc5
commit
70eace9de4
|
@ -69,27 +69,25 @@ export default function (files: Files) {
|
|||
}
|
||||
}
|
||||
|
||||
if (range) {
|
||||
ctx.status(206)
|
||||
ctx.header(
|
||||
"Content-Length",
|
||||
(range.end - range.start + 1).toString()
|
||||
)
|
||||
ctx.header(
|
||||
"Content-Range",
|
||||
`bytes ${range.start}-${range.end}/${file.sizeInBytes}`
|
||||
)
|
||||
}
|
||||
|
||||
if (ctx.req.method == "HEAD")
|
||||
return ctx.body(null)
|
||||
|
||||
return files
|
||||
.readFileStream(fileId, range)
|
||||
.then(async (stream) => {
|
||||
if (range) {
|
||||
ctx.status(206)
|
||||
ctx.header(
|
||||
"Content-Length",
|
||||
(range.end - range.start + 1).toString()
|
||||
)
|
||||
ctx.header(
|
||||
"Content-Range",
|
||||
`bytes ${range.start}-${range.end}/${file.sizeInBytes}`
|
||||
)
|
||||
}
|
||||
|
||||
return ctx.req.method == "HEAD" ? ctx.body(null) : startHonoStream(ctx, async (webStream) => {
|
||||
await webStream.pipe(Readable.toWeb(stream) as ReadableStream)
|
||||
}, async (err, webStream) => {
|
||||
console.error(err)
|
||||
await webStream.close()
|
||||
})
|
||||
return new Response(Readable.toWeb(stream) as ReadableStream, ctx.res)
|
||||
})
|
||||
.catch((err) => {
|
||||
return ServeError(ctx, err.status, err.message)
|
||||
|
|
Loading…
Reference in a new issue