From: Dessalines Date: Fri, 11 Sep 2020 03:19:43 +0000 (-0500) Subject: Trying to fix picture uploads. X-Git-Url: http://these/git/%22%7Burl%7D/%7B%60%24%7BghostArchiveUrl%7D/static/git-favicon.png?a=commitdiff_plain;h=fce2d739585982d016d9c3ff7f95ea2b531f9ba1;p=lemmy-ui.git Trying to fix picture uploads. --- diff --git a/src/shared/components/image-upload-form.tsx b/src/shared/components/image-upload-form.tsx index 98206f1..c9ffea4 100644 --- a/src/shared/components/image-upload-form.tsx +++ b/src/shared/components/image-upload-form.tsx @@ -1,4 +1,5 @@ import { Component, linkEvent } from 'inferno'; +import { pictrsUri } from '../env'; import { UserService } from '../services'; import { toast, randomStr } from '../utils'; @@ -71,14 +72,13 @@ export class ImageUploadForm extends Component< handleImageUpload(i: ImageUploadForm, event: any) { event.preventDefault(); let file = event.target.files[0]; - const imageUploadUrl = `/pictrs/image`; const formData = new FormData(); formData.append('images[]', file); i.state.loading = true; i.setState(i.state); - fetch(imageUploadUrl, { + fetch(pictrsUri, { method: 'POST', body: formData, }) @@ -88,7 +88,7 @@ export class ImageUploadForm extends Component< console.log(res); if (res.msg == 'ok') { let hash = res.files[0].file; - let url = `${window.location.origin}/pictrs/image/${hash}`; + let url = `${pictrsUri}/${hash}`; i.state.loading = false; i.setState(i.state); i.props.onUpload(url); diff --git a/src/shared/components/markdown-textarea.tsx b/src/shared/components/markdown-textarea.tsx index c566c2e..a14ca5c 100644 --- a/src/shared/components/markdown-textarea.tsx +++ b/src/shared/components/markdown-textarea.tsx @@ -13,6 +13,7 @@ import { import { UserService } from '../services'; import autosize from 'autosize'; import { i18n } from '../i18next'; +import { pictrsUri } from '../env'; interface MarkdownTextAreaProps { initialContent: string; @@ -334,14 +335,13 @@ export class MarkdownTextArea extends Component< file = event; } - const imageUploadUrl = `/pictrs/image`; const formData = new FormData(); formData.append('images[]', file); i.state.imageLoading = true; i.setState(i.state); - fetch(imageUploadUrl, { + fetch(pictrsUri, { method: 'POST', body: formData, }) @@ -351,9 +351,9 @@ export class MarkdownTextArea extends Component< console.log(res); if (res.msg == 'ok') { let hash = res.files[0].file; - let url = `${window.location.origin}/pictrs/image/${hash}`; + let url = `${pictrsUri}/${hash}`; let deleteToken = res.files[0].delete_token; - let deleteUrl = `${window.location.origin}/pictrs/image/delete/${deleteToken}/${hash}`; + let deleteUrl = `${pictrsUri}/delete/${deleteToken}/${hash}`; let imageMarkdown = `![](${url})`; let content = i.state.content; content = content ? `${content}\n${imageMarkdown}` : imageMarkdown; diff --git a/src/shared/components/post-form.tsx b/src/shared/components/post-form.tsx index dd5d549..6137f53 100644 --- a/src/shared/components/post-form.tsx +++ b/src/shared/components/post-form.tsx @@ -41,6 +41,7 @@ if (isBrowser()) { } import { i18n } from '../i18next'; +import { pictrsUri } from '../env'; const MAX_POST_TITLE_LENGTH = 200; @@ -482,14 +483,13 @@ export class PostForm extends Component { file = event; } - const imageUploadUrl = `/pictrs/image`; const formData = new FormData(); formData.append('images[]', file); i.state.imageLoading = true; i.setState(i.state); - fetch(imageUploadUrl, { + fetch(pictrsUri, { method: 'POST', body: formData, }) @@ -499,9 +499,9 @@ export class PostForm extends Component { console.log(res); if (res.msg == 'ok') { let hash = res.files[0].file; - let url = `${window.location.origin}/pictrs/image/${hash}`; + let url = `${pictrsUri}/${hash}`; let deleteToken = res.files[0].delete_token; - let deleteUrl = `${window.location.origin}/pictrs/image/delete/${deleteToken}/${hash}`; + let deleteUrl = `${pictrsUri}/delete/${deleteToken}/${hash}`; i.state.postForm.url = url; i.state.imageLoading = false; i.setState(i.state); diff --git a/src/shared/env.ts b/src/shared/env.ts index da4bb10..3d5533d 100644 --- a/src/shared/env.ts +++ b/src/shared/env.ts @@ -12,3 +12,4 @@ const endpoint = `${host}:${port}`; export const wsUri = `ws${secure}://${endpoint}/api/v1/ws`; export const httpUri = `http${secure}://${endpoint}/api/v1`; +export const pictrsUri = `http${secure}://${endpoint}/pictrs/image`;