refactor: move readline

main
spacemeowx2 2022-11-18 20:02:15 +08:00 committed by imspace
parent 1afdbd0bc6
commit 94e6ed33ba
2 changed files with 13 additions and 15 deletions

View File

@ -1,17 +1,4 @@
import { CookieJar, CookieOptions, wrapFetch } from "../deps.ts";
import { io } from "../deps.ts";
const stdinLines = io.readLines(Deno.stdin);
export async function readline(
{ skipEmpty = true }: { skipEmpty?: boolean } = {},
) {
for await (const line of stdinLines) {
if (!skipEmpty || line !== "") {
return line;
}
}
throw new Error("EOF");
}
export type Fetcher = {
get(opts: { url: string; headers?: HeadersInit }): Promise<Response>;
@ -29,7 +16,6 @@ export type Logger = {
export type Env = {
logger: Logger;
readline: () => Promise<string>;
newFetcher: (opts?: { cookies?: CookieOptions[] }) => Fetcher;
};
@ -40,7 +26,6 @@ export const DEFAULT_ENV: Env = {
warn: console.warn,
error: console.error,
},
readline,
newFetcher: ({ cookies } = {}) => {
const cookieJar = new CookieJar(cookies);
const fetch = wrapFetch({ cookieJar });

View File

@ -2,6 +2,19 @@ import { APIError } from "./APIError.ts";
import { S3S_NAMESPACE } from "./constant.ts";
import { base64, uuid } from "../deps.ts";
import { Env } from "./env.ts";
import { io } from "../deps.ts";
const stdinLines = io.readLines(Deno.stdin);
export async function readline(
{ skipEmpty = true }: { skipEmpty?: boolean } = {},
) {
for await (const line of stdinLines) {
if (!skipEmpty || line !== "") {
return line;
}
}
throw new Error("EOF");
}
export function urlBase64Encode(data: ArrayBuffer) {
return base64.encode(data)