Switch thumbnail server: spee.ch --> vanwanet
This commit is contained in:
parent
a021475128
commit
39a4cb3d77
4 changed files with 43 additions and 43 deletions
|
@ -1371,6 +1371,7 @@
|
||||||
"Are you sure you want to purchase %claim_title%?": "Are you sure you want to purchase %claim_title%?",
|
"Are you sure you want to purchase %claim_title%?": "Are you sure you want to purchase %claim_title%?",
|
||||||
"Discover": "Discover",
|
"Discover": "Discover",
|
||||||
"Thumbnail upload service may be down, try again later.": "Thumbnail upload service may be down, try again later.",
|
"Thumbnail upload service may be down, try again later.": "Thumbnail upload service may be down, try again later.",
|
||||||
|
"There was an error in the upload. The format or extension might not be supported.": "There was an error in the upload. The format or extension might not be supported.",
|
||||||
"You are currently editing your upload.": "You are currently editing your upload.",
|
"You are currently editing your upload.": "You are currently editing your upload.",
|
||||||
"You are currently editing this claim.": "You are currently editing this claim.",
|
"You are currently editing this claim.": "You are currently editing this claim.",
|
||||||
"My content for this post...": "My content for this post...",
|
"My content for this post...": "My content for this post...",
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import FileSelector from 'component/common/file-selector';
|
import FileSelector from 'component/common/file-selector';
|
||||||
import * as SPEECH_URLS from 'constants/speech_urls';
|
import { IMG_CDN_PUBLISH_URL } from 'constants/cdn_urls';
|
||||||
import { FormField, Form } from 'component/common/form';
|
import { FormField, Form } from 'component/common/form';
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
import Card from 'component/common/card';
|
import Card from 'component/common/card';
|
||||||
import { generateThumbnailName } from 'util/generate-thumbnail-name';
|
|
||||||
import usePersistedState from 'effects/use-persisted-state';
|
import usePersistedState from 'effects/use-persisted-state';
|
||||||
|
|
||||||
const accept = '.png, .jpg, .jpeg, .gif';
|
const accept = '.png, .jpg, .jpeg, .gif';
|
||||||
const SPEECH_READY = 'READY';
|
const STATUS = { READY: 'READY', UPLOADING: 'UPLOADING' };
|
||||||
const SPEECH_UPLOADING = 'UPLOADING';
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
assetName: string,
|
assetName: string,
|
||||||
|
@ -26,7 +24,7 @@ function SelectAsset(props: Props) {
|
||||||
const { onUpdate, onDone, assetName, currentValue, recommended, title, inline } = props;
|
const { onUpdate, onDone, assetName, currentValue, recommended, title, inline } = props;
|
||||||
const [pathSelected, setPathSelected] = React.useState('');
|
const [pathSelected, setPathSelected] = React.useState('');
|
||||||
const [fileSelected, setFileSelected] = React.useState<any>(null);
|
const [fileSelected, setFileSelected] = React.useState<any>(null);
|
||||||
const [uploadStatus, setUploadStatus] = React.useState(SPEECH_READY);
|
const [uploadStatus, setUploadStatus] = React.useState(STATUS.READY);
|
||||||
const [useUrl, setUseUrl] = usePersistedState('thumbnail-upload:mode', false);
|
const [useUrl, setUseUrl] = usePersistedState('thumbnail-upload:mode', false);
|
||||||
const [url, setUrl] = React.useState(currentValue);
|
const [url, setUrl] = React.useState(currentValue);
|
||||||
const [error, setError] = React.useState();
|
const [error, setError] = React.useState();
|
||||||
|
@ -37,7 +35,7 @@ function SelectAsset(props: Props) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSuccess = (thumbnailUrl) => {
|
const onSuccess = (thumbnailUrl) => {
|
||||||
setUploadStatus(SPEECH_READY);
|
setUploadStatus(STATUS.READY);
|
||||||
onUpdate(thumbnailUrl, !useUrl);
|
onUpdate(thumbnailUrl, !useUrl);
|
||||||
|
|
||||||
if (onDone) {
|
if (onDone) {
|
||||||
|
@ -45,22 +43,27 @@ function SelectAsset(props: Props) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
setUploadStatus(SPEECH_UPLOADING);
|
setUploadStatus(STATUS.UPLOADING);
|
||||||
|
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
const name = generateThumbnailName();
|
data.append('file-input', fileSelected);
|
||||||
data.append('name', name);
|
data.append('upload', 'Upload');
|
||||||
data.append('file', fileSelected);
|
|
||||||
|
|
||||||
return fetch(SPEECH_URLS.SPEECH_PUBLISH, {
|
return fetch(IMG_CDN_PUBLISH_URL, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: data,
|
body: data,
|
||||||
})
|
})
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((json) => (json.success ? onSuccess(`${json.data.serveUrl}`) : uploadError(json.message)))
|
.then((json) => {
|
||||||
|
return json.type === 'success'
|
||||||
|
? onSuccess(`${json.message}`)
|
||||||
|
: uploadError(
|
||||||
|
json.message || __('There was an error in the upload. The format or extension might not be supported.')
|
||||||
|
);
|
||||||
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
uploadError(err.message);
|
uploadError(err.message);
|
||||||
setUploadStatus(SPEECH_READY);
|
setUploadStatus(STATUS.READY);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +73,7 @@ function SelectAsset(props: Props) {
|
||||||
const selectedLabel = pathSelected ? __('URL Selected') : __('File Selected');
|
const selectedLabel = pathSelected ? __('URL Selected') : __('File Selected');
|
||||||
|
|
||||||
let fileSelectorLabel;
|
let fileSelectorLabel;
|
||||||
if (uploadStatus === SPEECH_UPLOADING) {
|
if (uploadStatus === STATUS.UPLOADING) {
|
||||||
fileSelectorLabel = __('Uploading...');
|
fileSelectorLabel = __('Uploading...');
|
||||||
} else {
|
} else {
|
||||||
// Include the same label/recommendation for both 'URL' and 'UPLOAD'.
|
// Include the same label/recommendation for both 'URL' and 'UPLOAD'.
|
||||||
|
@ -96,7 +99,7 @@ function SelectAsset(props: Props) {
|
||||||
) : (
|
) : (
|
||||||
<FileSelector
|
<FileSelector
|
||||||
autoFocus
|
autoFocus
|
||||||
disabled={uploadStatus === SPEECH_UPLOADING}
|
disabled={uploadStatus === STATUS.UPLOADING}
|
||||||
label={fileSelectorLabel}
|
label={fileSelectorLabel}
|
||||||
name="assetSelector"
|
name="assetSelector"
|
||||||
currentPath={pathSelected}
|
currentPath={pathSelected}
|
||||||
|
@ -119,7 +122,7 @@ function SelectAsset(props: Props) {
|
||||||
button="primary"
|
button="primary"
|
||||||
type="submit"
|
type="submit"
|
||||||
label={useUrl ? __('Done') : __('Upload')}
|
label={useUrl ? __('Done') : __('Upload')}
|
||||||
disabled={!useUrl && (uploadStatus === SPEECH_UPLOADING || !pathSelected || !fileSelected)}
|
disabled={!useUrl && (uploadStatus === STATUS.UPLOADING || !pathSelected || !fileSelected)}
|
||||||
onClick={() => doUploadAsset()}
|
onClick={() => doUploadAsset()}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
2
ui/constants/cdn_urls.js
Normal file
2
ui/constants/cdn_urls.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
export const IMG_CDN_PUBLISH_URL = 'https://thumbs.odycdn.com/upload.php';
|
||||||
|
export const IMG_CDN_STATUS_URL = 'https://thumbs.odycdn.com/status.php';
|
|
@ -18,7 +18,7 @@ import { push } from 'connected-react-router';
|
||||||
import analytics from 'analytics';
|
import analytics from 'analytics';
|
||||||
import { doOpenModal } from 'redux/actions/app';
|
import { doOpenModal } from 'redux/actions/app';
|
||||||
import { CC_LICENSES, COPYRIGHT, OTHER, NONE, PUBLIC_DOMAIN } from 'constants/licenses';
|
import { CC_LICENSES, COPYRIGHT, OTHER, NONE, PUBLIC_DOMAIN } from 'constants/licenses';
|
||||||
import { SPEECH_STATUS, SPEECH_PUBLISH } from 'constants/speech_urls';
|
import { IMG_CDN_PUBLISH_URL, IMG_CDN_STATUS_URL } from 'constants/cdn_urls';
|
||||||
import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses';
|
import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses';
|
||||||
import { creditsToString } from 'util/format-credits';
|
import { creditsToString } from 'util/format-credits';
|
||||||
import Lbry from 'lbry';
|
import Lbry from 'lbry';
|
||||||
|
@ -367,10 +367,10 @@ export const doResetThumbnailStatus = () => (dispatch: Dispatch) => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return fetch(SPEECH_STATUS)
|
return fetch(IMG_CDN_STATUS_URL)
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((status) => {
|
.then((json) => {
|
||||||
if (status.disabled) {
|
if (json.status !== 'online') {
|
||||||
throw Error();
|
throw Error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,16 +412,8 @@ export const doUploadThumbnail = (
|
||||||
path?: any,
|
path?: any,
|
||||||
cb?: (string) => void
|
cb?: (string) => void
|
||||||
) => (dispatch: Dispatch) => {
|
) => (dispatch: Dispatch) => {
|
||||||
const downMessage = __('Thumbnail upload service may be down, try again later.');
|
|
||||||
let thumbnail, fileExt, fileName, fileType;
|
let thumbnail, fileExt, fileName, fileType;
|
||||||
|
|
||||||
const makeid = () => {
|
|
||||||
let text = '';
|
|
||||||
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
||||||
for (let i = 0; i < 24; i += 1) text += possible.charAt(Math.floor(Math.random() * 62));
|
|
||||||
return text;
|
|
||||||
};
|
|
||||||
|
|
||||||
const uploadError = (error = '') => {
|
const uploadError = (error = '') => {
|
||||||
dispatch(
|
dispatch(
|
||||||
batchActions(
|
batchActions(
|
||||||
|
@ -440,28 +432,32 @@ export const doUploadThumbnail = (
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
||||||
data: {
|
data: { thumbnailError: undefined },
|
||||||
thumbnailError: undefined,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const doUpload = (data) => {
|
const doUpload = (data) => {
|
||||||
return fetch(SPEECH_PUBLISH, {
|
return fetch(IMG_CDN_PUBLISH_URL, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: data,
|
body: data,
|
||||||
})
|
})
|
||||||
.then((res) => res.text())
|
.then((res) => res.text())
|
||||||
.then((text) => (text.length ? JSON.parse(text) : {}))
|
.then((text) => (text.length ? JSON.parse(text) : {}))
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
if (!json.success) return uploadError(json.message || downMessage);
|
if (json.type !== 'success') {
|
||||||
if (cb) {
|
return uploadError(
|
||||||
cb(json.data.serveUrl);
|
json.message || __('There was an error in the upload. The format or extension might not be supported.')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cb) {
|
||||||
|
cb(json.message);
|
||||||
|
}
|
||||||
|
|
||||||
return dispatch({
|
return dispatch({
|
||||||
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
||||||
data: {
|
data: {
|
||||||
uploadThumbnailStatus: THUMBNAIL_STATUSES.COMPLETE,
|
uploadThumbnailStatus: THUMBNAIL_STATUSES.COMPLETE,
|
||||||
thumbnail: json.data.serveUrl,
|
thumbnail: json.message,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -470,7 +466,7 @@ export const doUploadThumbnail = (
|
||||||
|
|
||||||
// This sucks but ¯\_(ツ)_/¯
|
// This sucks but ¯\_(ツ)_/¯
|
||||||
if (message === 'Failed to fetch') {
|
if (message === 'Failed to fetch') {
|
||||||
message = downMessage;
|
message = __('Thumbnail upload service may be down, try again later.');
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadError(message);
|
uploadError(message);
|
||||||
|
@ -489,10 +485,9 @@ export const doUploadThumbnail = (
|
||||||
fileType = 'image/png';
|
fileType = 'image/png';
|
||||||
|
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
const name = makeid();
|
|
||||||
data.append('name', name);
|
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName });
|
data.append('file-input', { uri: 'file://' + filePath, type: fileType, name: fileName });
|
||||||
|
data.append('upload', 'Upload');
|
||||||
return doUpload(data);
|
return doUpload(data);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -510,11 +505,10 @@ export const doUploadThumbnail = (
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
const name = makeid();
|
|
||||||
const file = thumbnailBlob || (thumbnail && new File([thumbnail], fileName, { type: fileType }));
|
const file = thumbnailBlob || (thumbnail && new File([thumbnail], fileName, { type: fileType }));
|
||||||
data.append('name', name);
|
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
data.append('file', file);
|
data.append('file-input', file);
|
||||||
|
data.append('upload', 'Upload');
|
||||||
return doUpload(data);
|
return doUpload(data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue