Revert "Switch thumbnail server: spee.ch --> vanwanet"

This reverts commit 1a0a62058c.
This commit is contained in:
infinite-persistence 2021-12-16 16:16:22 +08:00
parent 7d9e8bffae
commit 50d1d062ad
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
4 changed files with 42 additions and 42 deletions

View file

@ -1358,7 +1358,6 @@
"Are you sure you want to purchase %claim_title%?": "Are you sure you want to purchase %claim_title%?",
"Discover": "Discover",
"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 this claim.": "You are currently editing this claim.",
"My content for this post...": "My content for this post...",

View file

@ -1,14 +1,16 @@
// @flow
import React from 'react';
import FileSelector from 'component/common/file-selector';
import { IMG_CDN_PUBLISH_URL } from 'constants/cdn_urls';
import * as SPEECH_URLS from 'constants/speech_urls';
import { FormField, Form } from 'component/common/form';
import Button from 'component/button';
import Card from 'component/common/card';
import { generateThumbnailName } from 'util/generate-thumbnail-name';
import usePersistedState from 'effects/use-persisted-state';
const accept = '.png, .jpg, .jpeg, .gif';
const STATUS = { READY: 'READY', UPLOADING: 'UPLOADING' };
const SPEECH_READY = 'READY';
const SPEECH_UPLOADING = 'UPLOADING';
type Props = {
assetName: string,
@ -24,7 +26,7 @@ function SelectAsset(props: Props) {
const { onUpdate, onDone, assetName, currentValue, recommended, title, inline } = props;
const [pathSelected, setPathSelected] = React.useState('');
const [fileSelected, setFileSelected] = React.useState<any>(null);
const [uploadStatus, setUploadStatus] = React.useState(STATUS.READY);
const [uploadStatus, setUploadStatus] = React.useState(SPEECH_READY);
const [useUrl, setUseUrl] = usePersistedState('thumbnail-upload:mode', false);
const [url, setUrl] = React.useState(currentValue);
const [error, setError] = React.useState();
@ -35,7 +37,7 @@ function SelectAsset(props: Props) {
};
const onSuccess = (thumbnailUrl) => {
setUploadStatus(STATUS.READY);
setUploadStatus(SPEECH_READY);
onUpdate(thumbnailUrl, !useUrl);
if (onDone) {
@ -43,27 +45,22 @@ function SelectAsset(props: Props) {
}
};
setUploadStatus(STATUS.UPLOADING);
setUploadStatus(SPEECH_UPLOADING);
const data = new FormData();
data.append('file-input', fileSelected);
data.append('upload', 'Upload');
const name = generateThumbnailName();
data.append('name', name);
data.append('file', fileSelected);
return fetch(IMG_CDN_PUBLISH_URL, {
return fetch(SPEECH_URLS.SPEECH_PUBLISH, {
method: 'POST',
body: data,
})
.then((response) => response.json())
.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.')
);
})
.then((json) => (json.success ? onSuccess(`${json.data.serveUrl}`) : uploadError(json.message)))
.catch((err) => {
uploadError(err.message);
setUploadStatus(STATUS.READY);
setUploadStatus(SPEECH_READY);
});
}
@ -73,7 +70,7 @@ function SelectAsset(props: Props) {
const selectedLabel = pathSelected ? __('URL Selected') : __('File Selected');
let fileSelectorLabel;
if (uploadStatus === STATUS.UPLOADING) {
if (uploadStatus === SPEECH_UPLOADING) {
fileSelectorLabel = __('Uploading...');
} else {
// Include the same label/recommendation for both 'URL' and 'UPLOAD'.
@ -99,7 +96,7 @@ function SelectAsset(props: Props) {
) : (
<FileSelector
autoFocus
disabled={uploadStatus === STATUS.UPLOADING}
disabled={uploadStatus === SPEECH_UPLOADING}
label={fileSelectorLabel}
name="assetSelector"
currentPath={pathSelected}
@ -122,7 +119,7 @@ function SelectAsset(props: Props) {
button="primary"
type="submit"
label={useUrl ? __('Done') : __('Upload')}
disabled={!useUrl && (uploadStatus === STATUS.UPLOADING || !pathSelected || !fileSelected)}
disabled={!useUrl && (uploadStatus === SPEECH_UPLOADING || !pathSelected || !fileSelected)}
onClick={() => doUploadAsset()}
/>
)}

View file

@ -1,2 +0,0 @@
export const IMG_CDN_PUBLISH_URL = 'https://thumbs.odycdn.com/upload.php';
export const IMG_CDN_STATUS_URL = 'https://thumbs.odycdn.com/status.php';

View file

@ -18,7 +18,7 @@ import { push } from 'connected-react-router';
import analytics from 'analytics';
import { doOpenModal } from 'redux/actions/app';
import { CC_LICENSES, COPYRIGHT, OTHER, NONE, PUBLIC_DOMAIN } from 'constants/licenses';
import { IMG_CDN_PUBLISH_URL, IMG_CDN_STATUS_URL } from 'constants/cdn_urls';
import { SPEECH_STATUS, SPEECH_PUBLISH } from 'constants/speech_urls';
import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses';
import { creditsToString } from 'util/format-credits';
import Lbry from 'lbry';
@ -355,10 +355,10 @@ export const doResetThumbnailStatus = () => (dispatch: Dispatch) => {
},
});
return fetch(IMG_CDN_STATUS_URL)
return fetch(SPEECH_STATUS)
.then((res) => res.json())
.then((json) => {
if (json.status !== 'online') {
.then((status) => {
if (status.disabled) {
throw Error();
}
@ -400,8 +400,16 @@ export const doUploadThumbnail = (
path?: any,
cb?: (string) => void
) => (dispatch: Dispatch) => {
const downMessage = __('Thumbnail upload service may be down, try again later.');
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 = '') => {
dispatch(
batchActions(
@ -420,32 +428,28 @@ export const doUploadThumbnail = (
dispatch({
type: ACTIONS.UPDATE_PUBLISH_FORM,
data: { thumbnailError: undefined },
data: {
thumbnailError: undefined,
},
});
const doUpload = (data) => {
return fetch(IMG_CDN_PUBLISH_URL, {
return fetch(SPEECH_PUBLISH, {
method: 'POST',
body: data,
})
.then((res) => res.text())
.then((text) => (text.length ? JSON.parse(text) : {}))
.then((json) => {
if (json.type !== 'success') {
return uploadError(
json.message || __('There was an error in the upload. The format or extension might not be supported.')
);
}
if (!json.success) return uploadError(json.message || downMessage);
if (cb) {
cb(json.message);
cb(json.data.serveUrl);
}
return dispatch({
type: ACTIONS.UPDATE_PUBLISH_FORM,
data: {
uploadThumbnailStatus: THUMBNAIL_STATUSES.COMPLETE,
thumbnail: json.message,
thumbnail: json.data.serveUrl,
},
});
})
@ -454,7 +458,7 @@ export const doUploadThumbnail = (
// This sucks but ¯\_(ツ)_/¯
if (message === 'Failed to fetch') {
message = __('Thumbnail upload service may be down, try again later.');
message = downMessage;
}
uploadError(message);
@ -473,9 +477,10 @@ export const doUploadThumbnail = (
fileType = 'image/png';
const data = new FormData();
const name = makeid();
data.append('name', name);
// $FlowFixMe
data.append('file-input', { uri: 'file://' + filePath, type: fileType, name: fileName });
data.append('upload', 'Upload');
data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName });
return doUpload(data);
});
} else {
@ -493,10 +498,11 @@ export const doUploadThumbnail = (
}
const data = new FormData();
const name = makeid();
const file = thumbnailBlob || (thumbnail && new File([thumbnail], fileName, { type: fileType }));
data.append('name', name);
// $FlowFixMe
data.append('file-input', file);
data.append('upload', 'Upload');
data.append('file', file);
return doUpload(data);
}
};