From 96a84c53ff2a20fce708bad7893e9ed3eb92f2e2 Mon Sep 17 00:00:00 2001 From: kamecha Date: Sat, 13 Jul 2024 13:39:23 +0900 Subject: [PATCH] =?UTF-8?q?=E6=8C=87=E5=AE=9A=E3=81=97=E3=81=9FfileId?= =?UTF-8?q?=E3=81=AE=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E3=81=97=E3=81=A6Uint8Array=E3=81=A7=E8=BF=94?= =?UTF-8?q?=E3=81=99=E9=96=A2=E6=95=B0=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- denops/traqvim/main.ts | 10 ++++++++++ denops/traqvim/model.ts | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/denops/traqvim/main.ts b/denops/traqvim/main.ts index 2e971a7..af2e54a 100644 --- a/denops/traqvim/main.ts +++ b/denops/traqvim/main.ts @@ -2,6 +2,7 @@ import { OAuth } from "./oauth.ts"; import { channelMessageOptions, channelTimeline, + downloadFile, homeChannelId, homeChannelPath, sendMessage, @@ -11,6 +12,7 @@ import { Denops, ensureArray, ensureNumber, + ensureObject, ensureString, fn, helper, @@ -38,6 +40,14 @@ export async function main(denops: Denops) { // oauthの仮オブジェクト let oauth: OAuth; denops.dispatcher = { + async getFile(fileId: unknown): Promise { + ensureString(fileId); + const file: Uint8Array = await downloadFile(fileId); + // denops-sixel-view.vimのsixel_viewがUint8Arrayを受け取れる必要がある + const sixel = denops.dispatch("sixel_view", "img2sixel", file); + ensureObject<{ data: string; height: number; width: number }>(sixel); + return sixel; + }, setupOAuth(): Promise { helper.echo(denops, "setup..."); // OAuthの設定を行う diff --git a/denops/traqvim/model.ts b/denops/traqvim/model.ts index 7478397..6329c42 100644 --- a/denops/traqvim/model.ts +++ b/denops/traqvim/model.ts @@ -292,3 +292,20 @@ export const removePin = async ( console.error(e); } }; + +export const downloadFile = async ( + fileId: string, +): Promise => { + try { + const fileRes = await api.fetchWithToken( + "GET", + "/files/" + fileId, + {}, + ); + const blob = await fileRes.blob(); + return new Uint8Array(await blob.arrayBuffer()); + } catch (e) { + console.error(e); + } + return new Uint8Array(); +};