From 8d39283d46cfb34b638b085f85761d681dd50605 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 19 Apr 2020 09:05:20 +0900 Subject: [PATCH] Resolve #6276 --- locales/ja-JP.yml | 2 ++ src/client/components/page/page.post.vue | 34 ++++++++++++++++++- .../page-editor/els/page-editor.el.post.vue | 10 ++++-- src/client/scripts/aoiscript/evaluator.ts | 10 +++--- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 90b5a0d8c..787b2e8ee 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -778,6 +778,8 @@ _pages: post: "投稿フォーム" _post: text: "内容" + attachCanvasImage: "キャンバスの画像を添付する" + canvasId: "キャンバスID" textInput: "テキスト入力" _textInput: diff --git a/src/client/components/page/page.post.vue b/src/client/components/page/page.post.vue index 92a9d653f..4a04ba522 100644 --- a/src/client/components/page/page.post.vue +++ b/src/client/components/page/page.post.vue @@ -10,6 +10,7 @@ import Vue from 'vue'; import i18n from '../../i18n'; import MkTextarea from '../ui/textarea.vue'; import MkButton from '../ui/button.vue'; +import { apiUrl } from '../../config'; export default Vue.extend({ i18n, @@ -41,10 +42,39 @@ export default Vue.extend({ } }, methods: { - post() { + upload() { + return new Promise((ok) => { + const dialog = this.$root.dialog({ + type: 'waiting', + text: this.$t('uploading') + '...', + showOkButton: false, + showCancelButton: false, + cancelableByBgClick: false + }); + const canvas = this.script.aoiScript.canvases[this.value.canvasId]; + canvas.toBlob(blob => { + const data = new FormData(); + data.append('file', blob); + data.append('i', this.$store.state.i.token); + + fetch(apiUrl + '/drive/files/create', { + method: 'POST', + body: data + }) + .then(response => response.json()) + .then(f => { + dialog.close(); + ok(f); + }) + }); + }); + }, + async post() { this.posting = true; + const file = this.value.attachCanvasImage ? await this.upload() : null; this.$root.api('notes/create', { text: this.text, + fileIds: file ? [file.id] : undefined, }).then(() => { this.posted = true; this.$root.dialog({ @@ -59,9 +89,11 @@ export default Vue.extend({