refactor: move readline
parent
1afdbd0bc6
commit
94e6ed33ba
15
src/env.ts
15
src/env.ts
|
|
@ -1,17 +1,4 @@
|
||||||
import { CookieJar, CookieOptions, wrapFetch } from "../deps.ts";
|
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 = {
|
export type Fetcher = {
|
||||||
get(opts: { url: string; headers?: HeadersInit }): Promise<Response>;
|
get(opts: { url: string; headers?: HeadersInit }): Promise<Response>;
|
||||||
|
|
@ -29,7 +16,6 @@ export type Logger = {
|
||||||
|
|
||||||
export type Env = {
|
export type Env = {
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
readline: () => Promise<string>;
|
|
||||||
newFetcher: (opts?: { cookies?: CookieOptions[] }) => Fetcher;
|
newFetcher: (opts?: { cookies?: CookieOptions[] }) => Fetcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -40,7 +26,6 @@ export const DEFAULT_ENV: Env = {
|
||||||
warn: console.warn,
|
warn: console.warn,
|
||||||
error: console.error,
|
error: console.error,
|
||||||
},
|
},
|
||||||
readline,
|
|
||||||
newFetcher: ({ cookies } = {}) => {
|
newFetcher: ({ cookies } = {}) => {
|
||||||
const cookieJar = new CookieJar(cookies);
|
const cookieJar = new CookieJar(cookies);
|
||||||
const fetch = wrapFetch({ cookieJar });
|
const fetch = wrapFetch({ cookieJar });
|
||||||
|
|
|
||||||
13
src/utils.ts
13
src/utils.ts
|
|
@ -2,6 +2,19 @@ import { APIError } from "./APIError.ts";
|
||||||
import { S3S_NAMESPACE } from "./constant.ts";
|
import { S3S_NAMESPACE } from "./constant.ts";
|
||||||
import { base64, uuid } from "../deps.ts";
|
import { base64, uuid } from "../deps.ts";
|
||||||
import { Env } from "./env.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) {
|
export function urlBase64Encode(data: ArrayBuffer) {
|
||||||
return base64.encode(data)
|
return base64.encode(data)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue