Trying to fix picture uploads.
authorDessalines <tyhou13@gmx.com>
Fri, 11 Sep 2020 03:19:43 +0000 (22:19 -0500)
committerDessalines <tyhou13@gmx.com>
Fri, 11 Sep 2020 03:19:43 +0000 (22:19 -0500)
src/shared/components/image-upload-form.tsx
src/shared/components/markdown-textarea.tsx
src/shared/components/post-form.tsx
src/shared/env.ts

index 98206f17610610e7afb9f9bf4a3f847798574d6c..c9ffea416c24e9afc4f0932b541cbc78d300e146 100644 (file)
@@ -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);
index c566c2ef8839b07e1fe3e6ce4abe5e60cb2f7f04..a14ca5cc3c2df6ada6c6d9e4c3a490632b16d184 100644 (file)
@@ -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;
index dd5d5495a66092050820dff05f5947997fd91769..6137f53a6f2c62c72a3ea864f9d1162520141592 100644 (file)
@@ -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<PostFormProps, PostFormState> {
       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<PostFormProps, PostFormState> {
         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);
index da4bb1051a4238b1d156b2ea7cffbfa0a6fe6fb4..3d5533deee47b0ca4f24a38bfec588dd64a2c719 100644 (file)
@@ -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`;