generated at
複数のGyazoの画像を削除するscript
複数のGyazoの画像を一括削除するscript
Gyazoのcaptures画面から選択して削除してもいいが、ポチポチ押すのが面倒なときはこれを使う

2023-03-13
18:50:35 deno-cliffyを導入した

$ deno run --allow-read --allow-net="api.gyazo.com" -r=https://scrapbox.io https://scrapbox.io/api/code/takker/複数のGyazoの画像を削除するscript/sample.ts ACCESS_TOKEN
$ deno check --remote -r=https://scrapbox.io https://scrapbox.io/api/code/takker/複数のGyazoの画像を削除するscript/sample.ts
sample.ts
import { deleteBulk } from "./mod.ts"; import { Command } from "https://deno.land/x/cliffy@v0.25.7/command/mod.ts"; import { toFileUrl, join } from "https://scrapbox.io/api/code/takker/deno_std%2Fpath/mod.ts"; const { args: [token, list] } = await new Command() .name("delete-gyazo") .description("複数のGyazoの画像を削除するツール") .version("v1.0.0") .arguments("<token:string> <list:string>") .parse(Deno.args); const res = await fetch(toFileUrl(join(Deno.cwd(), list))); const json = (await res.json()) as (string | null)[]; const imageList: string[] = json .flatMap((url) => url ? [url.slice("https://gyazo.com/".length)] : []); const accessToken = Deno.args[0]; let i = 0; for await (const result of deleteBulk(imageList, token)) { if (!result.success) { console.error(result.reason); } else { console.log(`[${i++}] Delete ${result.value}`); } }

mod.ts
import { deleteImage } from "../deno-gyazo/mod.ts"; import { pool, sort, Result } from "../async-lib/mod.ts"; //import { deleteImage } from "../deno-gyazo/mod.ts"; export async function* deleteBulk( imageIds: string[], accessToken: string, ): AsyncGenerator<Result<string>, void, unknown> { // access token取得 if (!accessToken) throw new Error("Could not get the access token"); const reader = pool( 5, Array(imageIds.length).keys(), async (index: number): Promise<string> => { const result = await deleteImage(imageIds[index], { accessToken, }); if (!result.ok) throw new Error(JSON.stringify(result.value)); return imageIds[index]; }, ); yield* sort([...reader]); };

#2023-03-13 18:48:45
#2022-07-27 08:25:22