From f27f24b2723fb7d991521109c3e9b7e3eccef396 Mon Sep 17 00:00:00 2001 From: kamecha Date: Fri, 30 Aug 2024 23:31:38 +0900 Subject: [PATCH 1/3] =?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 | 16 ++++++++++++++++ denops/traqvim/model.ts | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/denops/traqvim/main.ts b/denops/traqvim/main.ts index 2d16118..1997cb8 100644 --- a/denops/traqvim/main.ts +++ b/denops/traqvim/main.ts @@ -4,6 +4,7 @@ import { channelsRecursive, channelTimeline, channelUUID, + downloadFile, getStamp, getUser, homeChannelId, @@ -44,6 +45,21 @@ export async function main(denops: Denops) { // oauthの仮オブジェクト let oauth: OAuth; denops.dispatcher = { + async getFile(fileId: unknown): Promise { + assert(fileId, is.String); + const file: Uint8Array = await downloadFile(fileId); + // denops-sixel-view.vimのsixel_viewがUint8Arrayを受け取れる必要がある + const sixel = await denops.dispatch("sixel_view", "img2sixel", file); + assert( + sixel, + is.ObjectOf({ + data: is.String, + height: is.Number, + width: is.Number, + }), + ); + return sixel; + }, setupOAuth(): Promise { helper.echo(denops, "setup..."); // OAuthの設定を行う diff --git a/denops/traqvim/model.ts b/denops/traqvim/model.ts index af14171..3462cae 100644 --- a/denops/traqvim/model.ts +++ b/denops/traqvim/model.ts @@ -369,3 +369,20 @@ export const getStamp = async ( } return stamp; }; + +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(); +}; From 74fd6bf288aa660d0626c6e9aa3fded1b00f0235 Mon Sep 17 00:00:00 2001 From: kamecha Date: Sat, 13 Jul 2024 13:39:41 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=BE=8B=E3=81=AE?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E3=82=92doc=E3=81=AB=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/traqvim.jax | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/doc/traqvim.jax b/doc/traqvim.jax index 7679ee8..e5cbf8b 100644 --- a/doc/traqvim.jax +++ b/doc/traqvim.jax @@ -257,6 +257,38 @@ type (string) Default: "all" +============================================================================== +FAQ *traqvim-faq* + + +FAQ 1: |traqvim-faq-1| + How to display image with sixel? + +------------------------------------------------------------------------------ + *traqvim-faq-1* +Q: How to display image with sixel? + +A: install `denops-sixel-view.vim` plugin. and you have to set function like +bellow. + +https://github.com/gw31415/denops-sixel-view.vim + +> + function s:preview_img(fileId) abort + let file = denops#request("traqvim", "getFile", [a:fileId]) + call sixel_view#view_sixel(file['data'], 0, 0) + endfunction + + function s:preview_cursor_img() abort + let cursor_url = getline('.') + let fileId = matchstr(cursor_url, 'https://q.trap.jp/files/\zs.*') + call s:preview_img(fileId) + endfunction + + nnoremap K + \ call preview_cursor_img() +< + ============================================================================== TODO *traqvim-todo* From 1fcd5bc39adedbd3ca66e6fdae02934be7f7f2c5 Mon Sep 17 00:00:00 2001 From: kamecha Date: Fri, 30 Aug 2024 22:58:21 +0900 Subject: [PATCH 3/3] update doc --- doc/traqvim.jax | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/doc/traqvim.jax b/doc/traqvim.jax index e5cbf8b..73bb4b1 100644 --- a/doc/traqvim.jax +++ b/doc/traqvim.jax @@ -274,19 +274,31 @@ bellow. https://github.com/gw31415/denops-sixel-view.vim > + " Clear the image like + function s:clear() abort + call sixel_view#clear() + endfunction + function s:preview_img(fileId) abort - let file = denops#request("traqvim", "getFile", [a:fileId]) - call sixel_view#view_sixel(file['data'], 0, 0) + " download the file and convert it to sixel data + let sixel = denops#request("traqvim", "getFile", [a:fileId]) + call sixel_view#view_sixel(sixel['data'], 0, 0) endfunction function s:preview_cursor_img() abort let cursor_url = getline('.') let fileId = matchstr(cursor_url, 'https://q.trap.jp/files/\zs.*') call s:preview_img(fileId) + " Close the image by moving the cursor + autocmd CursorMoved,BufLeave ++once call s:clear() + endfunction + + function s:traqvim_setting() + nnoremap K + \ call preview_cursor_img() endfunction - nnoremap K - \ call preview_cursor_img() + autocmd FileType traqvim call s:traqvim_setting() < ==============================================================================