summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-09-14 12:37:18 +0200
committerCarl Schwan <carl@carlschwan.eu>2022-09-14 12:37:18 +0200
commite037394a50297cbcffc5dc3a2d3adad7f26fcd4d (patch)
tree3d266d5a1c451a2767b367ad7e16c6a5cfb55411 /src
parentb423ac536c10ff93c56d58f4e3dad0f5f40a1ee9 (diff)
Make uploading files work
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'src')
-rw-r--r--src/components/Composer/Composer.vue27
-rw-r--r--src/store/timeline.js22
2 files changed, 26 insertions, 23 deletions
diff --git a/src/components/Composer/Composer.vue b/src/components/Composer/Composer.vue
index 6134591a..5def1bc7 100644
--- a/src/components/Composer/Composer.vue
+++ b/src/components/Composer/Composer.vue
@@ -458,19 +458,20 @@ export default {
let content = contentHtml.replace(/<(?!\/div)[^>]+>/gi, '').replace(/<\/div>/gi, '\n').trim()
content = he.decode(content)
- let data = {
- content: content,
- to: to,
- hashtags: hashtags,
- type: this.type,
- attachments: this.previewUrls.map(preview => preview.result), // TODO send the summary and other props too
+ let formData = new FormData()
+ formData.append('content', content)
+ formData.append('to', to)
+ formData.append('hashtags', hashtags)
+ formData.append('type', this.type)
+ for (const preview of this.previewUrls) {
+ // TODO send the summary and other props too
+ formData.append('attachments', preview.result)
}
-
if (this.replyTo) {
- data.replyTo = this.replyTo.id
+ formData.append('replyTo', this.replyTo.id)
}
- return data
+ return formData
},
keyup(event) {
if (event.shiftKey || event.ctrlKey) {
@@ -487,7 +488,7 @@ export default {
// Trick to validate last mention when the user directly clicks on the "post" button without validating it.
let regex = /@([-\w]+)$/
- let lastMention = postData.content.match(regex)
+ let lastMention = postData.get('content').match(regex)
if (lastMention) {
// Ask the server for matching accounts, and wait for the results
@@ -495,13 +496,13 @@ export default {
// Validate the last mention only when it matches a single account
if (result.data.result.accounts.length === 1) {
- postData.content = postData.content.replace(regex, '@' + result.data.result.accounts[0].account)
- postData.to.push(result.data.result.accounts[0].account)
+ postData.set('content', postData.get('content').replace(regex, '@' + result.data.result.accounts[0].account))
+ postData.set('to', postData.get('to').push(result.data.result.accounts[0].account))
}
}
// Abort if the post is a direct message and no valid mentions were found
- // if (this.type === 'direct' && postData.to.length === 0) {
+ // if (this.type === 'direct' && postData.get('to').length === 0) {
// OC.Notification.showTemporary(t('social', 'Error while trying to post your message: Could not find any valid recipients.'), { type: 'error' })
// return
// }
diff --git a/src/store/timeline.js b/src/store/timeline.js
index 031f3306..f80b72b0 100644
--- a/src/store/timeline.js
+++ b/src/store/timeline.js
@@ -144,17 +144,19 @@ const actions = {
context.commit('setTimelineType', 'account')
context.commit('setAccount', account)
},
- post(context, post) {
- return new Promise((resolve, reject) => {
- axios.post(generateUrl('apps/social/api/v1/post'), { data: post }).then((response) => {
- Logger.info('Post created with token ' + response.data.result.token)
- resolve(response)
- }).catch((error) => {
- OC.Notification.showTemporary('Failed to create a post')
- Logger.error('Failed to create a post', { 'error': error.response })
- reject(error)
+ async post(context, post) {
+ try {
+ const { data } = axios.post(generateUrl('apps/social/api/v1/post'), post, {
+ headers: {
+ 'Content-Type': 'multipart/form-data'
+ }
})
- })
+ Logger.info('Post created with token ' + data.result.token)
+ } catch (error) {
+ OC.Notification.showTemporary('Failed to create a post')
+ console.error(error)
+ Logger.error('Failed to create a post', { 'error': error.response })
+ }
},
postDelete(context, post) {
return axios.delete(generateUrl(`apps/social/api/v1/post?id=${post.id}`)).then((response) => {