mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-22 12:21:13 +00:00
Trying to fix picture uploads.
This commit is contained in:
parent
8d6b75a45f
commit
fce2d73958
4 changed files with 12 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
||||||
import { Component, linkEvent } from 'inferno';
|
import { Component, linkEvent } from 'inferno';
|
||||||
|
import { pictrsUri } from '../env';
|
||||||
import { UserService } from '../services';
|
import { UserService } from '../services';
|
||||||
import { toast, randomStr } from '../utils';
|
import { toast, randomStr } from '../utils';
|
||||||
|
|
||||||
|
@ -71,14 +72,13 @@ export class ImageUploadForm extends Component<
|
||||||
handleImageUpload(i: ImageUploadForm, event: any) {
|
handleImageUpload(i: ImageUploadForm, event: any) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let file = event.target.files[0];
|
let file = event.target.files[0];
|
||||||
const imageUploadUrl = `/pictrs/image`;
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('images[]', file);
|
formData.append('images[]', file);
|
||||||
|
|
||||||
i.state.loading = true;
|
i.state.loading = true;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
|
|
||||||
fetch(imageUploadUrl, {
|
fetch(pictrsUri, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
})
|
})
|
||||||
|
@ -88,7 +88,7 @@ export class ImageUploadForm extends Component<
|
||||||
console.log(res);
|
console.log(res);
|
||||||
if (res.msg == 'ok') {
|
if (res.msg == 'ok') {
|
||||||
let hash = res.files[0].file;
|
let hash = res.files[0].file;
|
||||||
let url = `${window.location.origin}/pictrs/image/${hash}`;
|
let url = `${pictrsUri}/${hash}`;
|
||||||
i.state.loading = false;
|
i.state.loading = false;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
i.props.onUpload(url);
|
i.props.onUpload(url);
|
||||||
|
|
|
@ -13,6 +13,7 @@ import {
|
||||||
import { UserService } from '../services';
|
import { UserService } from '../services';
|
||||||
import autosize from 'autosize';
|
import autosize from 'autosize';
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
|
import { pictrsUri } from '../env';
|
||||||
|
|
||||||
interface MarkdownTextAreaProps {
|
interface MarkdownTextAreaProps {
|
||||||
initialContent: string;
|
initialContent: string;
|
||||||
|
@ -334,14 +335,13 @@ export class MarkdownTextArea extends Component<
|
||||||
file = event;
|
file = event;
|
||||||
}
|
}
|
||||||
|
|
||||||
const imageUploadUrl = `/pictrs/image`;
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('images[]', file);
|
formData.append('images[]', file);
|
||||||
|
|
||||||
i.state.imageLoading = true;
|
i.state.imageLoading = true;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
|
|
||||||
fetch(imageUploadUrl, {
|
fetch(pictrsUri, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
})
|
})
|
||||||
|
@ -351,9 +351,9 @@ export class MarkdownTextArea extends Component<
|
||||||
console.log(res);
|
console.log(res);
|
||||||
if (res.msg == 'ok') {
|
if (res.msg == 'ok') {
|
||||||
let hash = res.files[0].file;
|
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 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 imageMarkdown = `![](${url})`;
|
||||||
let content = i.state.content;
|
let content = i.state.content;
|
||||||
content = content ? `${content}\n${imageMarkdown}` : imageMarkdown;
|
content = content ? `${content}\n${imageMarkdown}` : imageMarkdown;
|
||||||
|
|
|
@ -41,6 +41,7 @@ if (isBrowser()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
|
import { pictrsUri } from '../env';
|
||||||
|
|
||||||
const MAX_POST_TITLE_LENGTH = 200;
|
const MAX_POST_TITLE_LENGTH = 200;
|
||||||
|
|
||||||
|
@ -482,14 +483,13 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
file = event;
|
file = event;
|
||||||
}
|
}
|
||||||
|
|
||||||
const imageUploadUrl = `/pictrs/image`;
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('images[]', file);
|
formData.append('images[]', file);
|
||||||
|
|
||||||
i.state.imageLoading = true;
|
i.state.imageLoading = true;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
|
|
||||||
fetch(imageUploadUrl, {
|
fetch(pictrsUri, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
})
|
})
|
||||||
|
@ -499,9 +499,9 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
if (res.msg == 'ok') {
|
if (res.msg == 'ok') {
|
||||||
let hash = res.files[0].file;
|
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 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.postForm.url = url;
|
||||||
i.state.imageLoading = false;
|
i.state.imageLoading = false;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
|
|
|
@ -12,3 +12,4 @@ const endpoint = `${host}:${port}`;
|
||||||
|
|
||||||
export const wsUri = `ws${secure}://${endpoint}/api/v1/ws`;
|
export const wsUri = `ws${secure}://${endpoint}/api/v1/ws`;
|
||||||
export const httpUri = `http${secure}://${endpoint}/api/v1`;
|
export const httpUri = `http${secure}://${endpoint}/api/v1`;
|
||||||
|
export const pictrsUri = `http${secure}://${endpoint}/pictrs/image`;
|
||||||
|
|
Loading…
Reference in a new issue