mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-25 07:06:25 -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
|
return files
|
||||||
.readFileStream(fileId, range)
|
.readFileStream(fileId, range)
|
||||||
.then(async (stream) => {
|
.then(async (stream) => {
|
||||||
if (range) {
|
return new Response(Readable.toWeb(stream) as ReadableStream, ctx.res)
|
||||||
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()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
return ServeError(ctx, err.status, err.message)
|
return ServeError(ctx, err.status, err.message)
|
||||||
|
|
Loading…
Reference in a new issue