Added a very complicated AsyncIterableReader class.
The class was already implemented in "https://deno.land/std@0.144.0/streams/conversion.ts". So, I litterally lost 1 day of work! I hate myself.
This commit is contained in:
1 parent
17a1b4bed3
commit
0d627c9051
125 files changed
+26943
-83
No files matched your search
+14
-3
@@ -2,7 +2,9 @@ import { Context, Router } from "https://deno.land/x/oak/mod.ts";
|
||||
import { FileService } from "./fileservice.ts";
|
||||
import { readerFromStreamReader } from "https://deno.land/std@0.189.0/streams/mod.ts";
|
||||
import { asyncIterableToArray } from "./utils.ts";
|
||||
|
||||
import { StringReader } from "https://deno.land/std@0.178.0/io/string_reader.ts";
|
||||
import { isReader } from "https://deno.land/x/oak@v12.5.0/util.ts";
|
||||
import { createMockNext } from "https://deno.land/x/oak@v12.1.0/testing.ts";
|
||||
|
||||
|
||||
type Handler = (ctx: Context) => void;
|
||||
@@ -30,10 +32,19 @@ function createFileHandlerFactory(fileService: FileService): Handler {
|
||||
|
||||
|
||||
function getFileHandlerFactory(fileService: FileService): Handler {
|
||||
return (ctx: Context) => {
|
||||
return async (ctx: Context) => {
|
||||
const untypedCtx: any = ctx;
|
||||
const fileId = untypedCtx.params.file_id;
|
||||
// ctx.response.body = await fileService.getRawBodyByPath()
|
||||
const reader = await fileService.getBodyAsReader(fileId);
|
||||
if(reader == null){
|
||||
ctx.response.status = 404;
|
||||
return;
|
||||
}
|
||||
ctx.response.status = 200;
|
||||
ctx.response.body = reader;
|
||||
ctx.response.type = "text/plain";
|
||||
// ctx.send(reader)
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user