複数のGyazoの画像を削除するscript
Gyazoのcaptures画面から選択して削除してもいいが、ポチポチ押すのが面倒なときはこれを使う 2023-03-13
code:sample.ts
import { deleteBulk } from "./mod.ts";
.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
const accessToken = Deno.args0; 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});
}
}
code: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(imageIdsindex, { accessToken,
});
if (!result.ok) throw new Error(JSON.stringify(result.value));
},
);
};