Allow only images in modal image uploader. #7672
6 changed files with 305 additions and 323 deletions
|
@ -11,7 +11,7 @@ import Icon from 'component/common/icon';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
modal: { id: string, modalProps: {} },
|
modal: { id: string, modalProps: {} },
|
||||||
filePath: string | File,
|
filePath: File,
|
||||||
clearPublish: () => void,
|
clearPublish: () => void,
|
||||||
updatePublishForm: ({}) => void,
|
updatePublishForm: ({}) => void,
|
||||||
openModal: (id: string, { files: Array<File> }) => void,
|
openModal: (id: string, { files: Array<File> }) => void,
|
||||||
|
|
|
@ -6,7 +6,7 @@ type Props = {
|
||||||
uri: ?string,
|
uri: ?string,
|
||||||
label: ?string,
|
label: ?string,
|
||||||
disabled: ?boolean,
|
disabled: ?boolean,
|
||||||
filePath: string | File,
|
filePath: File,
|
||||||
fileText: ?string,
|
fileText: ?string,
|
||||||
fileMimeType: ?string,
|
fileMimeType: ?string,
|
||||||
streamingUrl: ?string,
|
streamingUrl: ?string,
|
||||||
|
|
|
@ -19,7 +19,7 @@ type Props = {
|
||||||
mode: ?string,
|
mode: ?string,
|
||||||
name: ?string,
|
name: ?string,
|
||||||
title: ?string,
|
title: ?string,
|
||||||
filePath: string | File,
|
filePath: ?File,
|
||||||
fileMimeType: ?string,
|
fileMimeType: ?string,
|
||||||
isStillEditing: boolean,
|
isStillEditing: boolean,
|
||||||
balance: number,
|
balance: number,
|
||||||
|
@ -86,16 +86,16 @@ function PublishFile(props: Props) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (mode === PUBLISH_MODES.POST) {
|
if (mode === PUBLISH_MODES.POST) {
|
||||||
if (currentFileType !== 'text/markdown' && !isStillEditing) {
|
if (currentFileType !== 'text/markdown' && !isStillEditing) {
|
||||||
updatePublishForm({ filePath: '' });
|
updatePublishForm({ filePath: undefined });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [currentFileType, mode, isStillEditing, updatePublishForm]);
|
}, [currentFileType, mode, isStillEditing, updatePublishForm]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!filePath || filePath === '') {
|
if (!filePath) {
|
||||||
setCurrentFile('');
|
setCurrentFile('');
|
||||||
updateFileInfo(0, 0, false);
|
updateFileInfo(0, 0, false);
|
||||||
} else if (typeof filePath !== 'string') {
|
} else {
|
||||||
// Update currentFile file
|
// Update currentFile file
|
||||||
if (filePath.name !== currentFile) {
|
if (filePath.name !== currentFile) {
|
||||||
handleFileChange({ file: filePath, path: filePath.name });
|
handleFileChange({ file: filePath, path: filePath.name });
|
||||||
|
@ -215,9 +215,9 @@ function PublishFile(props: Props) {
|
||||||
// select file, start to select a new one, then cancel
|
// select file, start to select a new one, then cancel
|
||||||
if (!fileWithPath) {
|
if (!fileWithPath) {
|
||||||
if (isStillEditing || !clearName) {
|
if (isStillEditing || !clearName) {
|
||||||
updatePublishForm({ filePath: '' });
|
updatePublishForm({ filePath: undefined });
|
||||||
} else {
|
} else {
|
||||||
updatePublishForm({ filePath: '', name: '' });
|
updatePublishForm({ filePath: undefined, name: '' });
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -271,10 +271,8 @@ function PublishFile(props: Props) {
|
||||||
setPublishMode(PUBLISH_MODES.FILE);
|
setPublishMode(PUBLISH_MODES.FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
const publishFormParams: { filePath: string | File, name?: string, optimize?: boolean } = {
|
const publishFormParams: { filePath: File, name?: string, optimize?: boolean } = {
|
||||||
// if electron, we'll set filePath to the path string because SDK is handling publishing.
|
filePath: file,
|
||||||
// File.path will be undefined from web due to browser security, so it will default to the File Object.
|
|
||||||
filePath: fileWithPath.path || file,
|
|
||||||
};
|
};
|
||||||
// Strip off extention and replace invalid characters
|
// Strip off extention and replace invalid characters
|
||||||
let fileName = name || (file.name && file.name.substring(0, file.name.lastIndexOf('.'))) || '';
|
let fileName = name || (file.name && file.name.substring(0, file.name.lastIndexOf('.'))) || '';
|
||||||
|
|
|
@ -35,8 +35,8 @@ import tempy from 'tempy';
|
||||||
type Props = {
|
type Props = {
|
||||||
disabled: boolean,
|
disabled: boolean,
|
||||||
tags: Array<Tag>,
|
tags: Array<Tag>,
|
||||||
publish: (source?: string | File, ?boolean) => void,
|
publish: (source: ?File, ?boolean) => void,
|
||||||
filePath: string | File,
|
filePath: ?File,
|
||||||
fileText: string,
|
fileText: string,
|
||||||
bid: ?number,
|
bid: ?number,
|
||||||
bidError: ?string,
|
bidError: ?string,
|
||||||
|
@ -373,9 +373,6 @@ function PublishForm(props: Props) {
|
||||||
if (!output || output === '') {
|
if (!output || output === '') {
|
||||||
// Generate a temporary file:
|
// Generate a temporary file:
|
||||||
output = tempy.file({ name: 'post.md' });
|
output = tempy.file({ name: 'post.md' });
|
||||||
} else if (typeof filePath === 'string') {
|
|
||||||
// Use current file
|
|
||||||
output = filePath;
|
|
||||||
}
|
}
|
||||||
// Create a temporary file and save file changes
|
// Create a temporary file and save file changes
|
||||||
if (output && output !== '') {
|
if (output && output !== '') {
|
||||||
|
@ -447,7 +444,7 @@ function PublishForm(props: Props) {
|
||||||
// with other properties such as name, title, etc.) for security reasons.
|
// with other properties such as name, title, etc.) for security reasons.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (mode === PUBLISH_MODES.FILE) {
|
if (mode === PUBLISH_MODES.FILE) {
|
||||||
updatePublishForm({ filePath: '', fileDur: 0, fileSize: 0 });
|
updatePublishForm({ filePath: undefined, fileDur: 0, fileSize: 0 });
|
||||||
}
|
}
|
||||||
}, [mode, updatePublishForm]);
|
}, [mode, updatePublishForm]);
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import Icon from 'component/common/icon';
|
||||||
import { NO_FILE } from 'redux/actions/publish';
|
import { NO_FILE } from 'redux/actions/publish';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
filePath: string | File,
|
filePath: ?File,
|
||||||
isMarkdownPost: boolean,
|
isMarkdownPost: boolean,
|
||||||
optimize: boolean,
|
optimize: boolean,
|
||||||
title: ?string,
|
title: ?string,
|
||||||
|
@ -104,16 +104,11 @@ const ModalPublishPreview = (props: Props) => {
|
||||||
// @endif
|
// @endif
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFilePathName(filePath: string | File) {
|
function getFilePathName(filePath: ?File) {
|
||||||
if (!filePath) {
|
if (!filePath) {
|
||||||
return NO_FILE;
|
return NO_FILE;
|
||||||
}
|
}
|
||||||
|
return filePath.name;
|
||||||
if (typeof filePath === 'string') {
|
|
||||||
return filePath;
|
|
||||||
} else {
|
|
||||||
return filePath.name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRow(label: string, value: any) {
|
function createRow(label: string, value: any) {
|
||||||
|
@ -127,7 +122,7 @@ const ModalPublishPreview = (props: Props) => {
|
||||||
|
|
||||||
const txFee = previewResponse ? previewResponse['total_fee'] : null;
|
const txFee = previewResponse ? previewResponse['total_fee'] : null;
|
||||||
// $FlowFixMe add outputs[0] etc to PublishResponse type
|
// $FlowFixMe add outputs[0] etc to PublishResponse type
|
||||||
const isOptimizeAvail = filePath && filePath !== '' && isVid && ffmpegStatus.available;
|
const isOptimizeAvail = filePath && isVid && ffmpegStatus.available;
|
||||||
let modalTitle;
|
let modalTitle;
|
||||||
if (isStillEditing) {
|
if (isStillEditing) {
|
||||||
modalTitle = __('Confirm Edit');
|
modalTitle = __('Confirm Edit');
|
||||||
|
|
|
@ -18,7 +18,7 @@ import Lbry from 'lbry';
|
||||||
import { isClaimNsfw } from 'util/claim';
|
import { isClaimNsfw } from 'util/claim';
|
||||||
|
|
||||||
export const NO_FILE = '---';
|
export const NO_FILE = '---';
|
||||||
export const doPublishDesktop = (filePath: string, preview?: boolean) => (dispatch: Dispatch, getState: () => {}) => {
|
export const doPublishDesktop = (filePath: ?File, preview?: boolean) => (dispatch: Dispatch, getState: () => {}) => {
|
||||||
const publishPreview = (previewResponse) => {
|
const publishPreview = (previewResponse) => {
|
||||||
dispatch(
|
dispatch(
|
||||||
doOpenModal(MODALS.PUBLISH_PREVIEW, {
|
doOpenModal(MODALS.PUBLISH_PREVIEW, {
|
||||||
|
@ -138,335 +138,327 @@ export const doUpdatePublishForm = (publishFormValue: UpdatePublishFormData) =>
|
||||||
data: { ...publishFormValue },
|
data: { ...publishFormValue },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const doUploadThumbnail = (
|
export const doUploadThumbnail =
|
||||||
filePath?: string,
|
(filePath?: string, thumbnailBlob?: File, fsAdapter?: any, fs?: any, path?: any, cb?: (string) => void) =>
|
||||||
thumbnailBlob?: File,
|
(dispatch: Dispatch) => {
|
||||||
fsAdapter?: any,
|
const downMessage = __('Thumbnail upload service may be down, try again later.');
|
||||||
fs?: any,
|
let thumbnail, fileExt, fileName, fileType;
|
||||||
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 = () => {
|
const makeid = () => {
|
||||||
let text = '';
|
let text = '';
|
||||||
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
for (let i = 0; i < 24; i += 1) text += possible.charAt(Math.floor(Math.random() * 62));
|
for (let i = 0; i < 24; i += 1) text += possible.charAt(Math.floor(Math.random() * 62));
|
||||||
return text;
|
return text;
|
||||||
};
|
};
|
||||||
|
|
||||||
const uploadError = (error = '') => {
|
const uploadError = (error = '') => {
|
||||||
dispatch(
|
dispatch(
|
||||||
batchActions(
|
batchActions(
|
||||||
{
|
{
|
||||||
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
||||||
data: {
|
data: {
|
||||||
uploadThumbnailStatus: THUMBNAIL_STATUSES.READY,
|
uploadThumbnailStatus: THUMBNAIL_STATUSES.READY,
|
||||||
thumbnail: '',
|
thumbnail: '',
|
||||||
nsfw: false,
|
nsfw: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
doError(error)
|
||||||
doError(error)
|
)
|
||||||
)
|
);
|
||||||
);
|
};
|
||||||
};
|
|
||||||
|
|
||||||
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(SPEECH_PUBLISH, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: data,
|
body: data,
|
||||||
})
|
|
||||||
.then((res) => res.text())
|
|
||||||
.then((text) => (text.length ? JSON.parse(text) : {}))
|
|
||||||
.then((json) => {
|
|
||||||
if (!json.success) return uploadError(json.message || downMessage);
|
|
||||||
if (cb) {
|
|
||||||
cb(json.data.serveUrl);
|
|
||||||
}
|
|
||||||
return dispatch({
|
|
||||||
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
|
||||||
data: {
|
|
||||||
uploadThumbnailStatus: THUMBNAIL_STATUSES.COMPLETE,
|
|
||||||
thumbnail: json.data.serveUrl,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.then((res) => res.text())
|
||||||
let message = err.message;
|
.then((text) => (text.length ? JSON.parse(text) : {}))
|
||||||
|
.then((json) => {
|
||||||
|
if (!json.success) return uploadError(json.message || downMessage);
|
||||||
|
if (cb) {
|
||||||
|
cb(json.data.serveUrl);
|
||||||
|
}
|
||||||
|
return dispatch({
|
||||||
|
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
||||||
|
data: {
|
||||||
|
uploadThumbnailStatus: THUMBNAIL_STATUSES.COMPLETE,
|
||||||
|
thumbnail: json.data.serveUrl,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
let message = err.message;
|
||||||
|
|
||||||
// This sucks but ¯\_(ツ)_/¯
|
// This sucks but ¯\_(ツ)_/¯
|
||||||
if (message === 'Failed to fetch') {
|
if (message === 'Failed to fetch') {
|
||||||
message = downMessage;
|
message = downMessage;
|
||||||
}
|
}
|
||||||
const userInput = [fileName, fileExt, fileType, thumbnail];
|
const userInput = [fileName, fileExt, fileType, thumbnail];
|
||||||
uploadError(`${message}\nUser input: ${userInput.join(', ')}`);
|
uploadError(`${message}\nUser input: ${userInput.join(', ')}`);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
||||||
|
data: { uploadThumbnailStatus: THUMBNAIL_STATUSES.IN_PROGRESS },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (fsAdapter && fsAdapter.readFile && filePath) {
|
||||||
|
fsAdapter.readFile(filePath, 'base64').then((base64Image) => {
|
||||||
|
fileExt = 'png';
|
||||||
|
fileName = 'thumbnail.png';
|
||||||
|
fileType = 'image/png';
|
||||||
|
|
||||||
|
const data = new FormData();
|
||||||
|
const name = makeid();
|
||||||
|
data.append('name', name);
|
||||||
|
// $FlowFixMe
|
||||||
|
data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName });
|
||||||
|
return doUpload(data);
|
||||||
});
|
});
|
||||||
};
|
} else {
|
||||||
|
if (filePath && fs && path) {
|
||||||
dispatch({
|
thumbnail = fs.readFileSync(filePath);
|
||||||
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
fileExt = path.extname(filePath);
|
||||||
data: { uploadThumbnailStatus: THUMBNAIL_STATUSES.IN_PROGRESS },
|
fileName = path.basename(filePath);
|
||||||
});
|
fileType = `image/${fileExt.slice(1)}`;
|
||||||
|
} else if (thumbnailBlob) {
|
||||||
if (fsAdapter && fsAdapter.readFile && filePath) {
|
fileExt = `.${thumbnailBlob.type && thumbnailBlob.type.split('/')[1]}`;
|
||||||
fsAdapter.readFile(filePath, 'base64').then((base64Image) => {
|
fileName = thumbnailBlob.name;
|
||||||
fileExt = 'png';
|
fileType = thumbnailBlob.type;
|
||||||
fileName = 'thumbnail.png';
|
} else {
|
||||||
fileType = 'image/png';
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
const name = makeid();
|
const name = makeid();
|
||||||
|
const file = thumbnailBlob || (thumbnail && new File([thumbnail], fileName, { type: fileType }));
|
||||||
data.append('name', name);
|
data.append('name', name);
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName });
|
data.append('file', file);
|
||||||
return doUpload(data);
|
return doUpload(data);
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (filePath && fs && path) {
|
|
||||||
thumbnail = fs.readFileSync(filePath);
|
|
||||||
fileExt = path.extname(filePath);
|
|
||||||
fileName = path.basename(filePath);
|
|
||||||
fileType = `image/${fileExt.slice(1)}`;
|
|
||||||
} else if (thumbnailBlob) {
|
|
||||||
fileExt = `.${thumbnailBlob.type && thumbnailBlob.type.split('/')[1]}`;
|
|
||||||
fileName = thumbnailBlob.name;
|
|
||||||
fileType = thumbnailBlob.type;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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', file);
|
|
||||||
return doUpload(data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const doPrepareEdit = (claim: StreamClaim, uri: string, fileInfo: FileListItem, fs: any) => (
|
|
||||||
dispatch: Dispatch
|
|
||||||
) => {
|
|
||||||
const { name, amount, value = {} } = claim;
|
|
||||||
const channelName = (claim && claim.signing_channel && claim.signing_channel.name) || null;
|
|
||||||
const {
|
|
||||||
author,
|
|
||||||
description,
|
|
||||||
// use same values as default state
|
|
||||||
// fee will be undefined for free content
|
|
||||||
fee = {
|
|
||||||
amount: '0',
|
|
||||||
currency: 'LBC',
|
|
||||||
},
|
|
||||||
languages,
|
|
||||||
release_time,
|
|
||||||
license,
|
|
||||||
license_url: licenseUrl,
|
|
||||||
thumbnail,
|
|
||||||
title,
|
|
||||||
tags,
|
|
||||||
} = value;
|
|
||||||
|
|
||||||
const publishData: UpdatePublishFormData = {
|
|
||||||
name,
|
|
||||||
bid: Number(amount),
|
|
||||||
contentIsFree: fee.amount === '0',
|
|
||||||
author,
|
|
||||||
description,
|
|
||||||
fee,
|
|
||||||
languages,
|
|
||||||
releaseTime: release_time,
|
|
||||||
releaseTimeEdited: undefined,
|
|
||||||
thumbnail: thumbnail ? thumbnail.url : null,
|
|
||||||
title,
|
|
||||||
uri,
|
|
||||||
uploadThumbnailStatus: thumbnail ? THUMBNAIL_STATUSES.MANUAL : undefined,
|
|
||||||
licenseUrl,
|
|
||||||
nsfw: isClaimNsfw(claim),
|
|
||||||
tags: tags ? tags.map((tag) => ({ name: tag })) : [],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Make sure custom licenses are mapped properly
|
export const doPrepareEdit =
|
||||||
// If the license isn't one of the standard licenses, map the custom license and description/url
|
(claim: StreamClaim, uri: string, fileInfo: FileListItem, fs: any) => (dispatch: Dispatch) => {
|
||||||
if (!CC_LICENSES.some(({ value }) => value === license)) {
|
const { name, amount, value = {} } = claim;
|
||||||
if (!license || license === NONE || license === PUBLIC_DOMAIN) {
|
const channelName = (claim && claim.signing_channel && claim.signing_channel.name) || null;
|
||||||
|
const {
|
||||||
|
author,
|
||||||
|
description,
|
||||||
|
// use same values as default state
|
||||||
|
// fee will be undefined for free content
|
||||||
|
fee = {
|
||||||
|
amount: '0',
|
||||||
|
currency: 'LBC',
|
||||||
|
},
|
||||||
|
languages,
|
||||||
|
release_time,
|
||||||
|
license,
|
||||||
|
license_url: licenseUrl,
|
||||||
|
thumbnail,
|
||||||
|
title,
|
||||||
|
tags,
|
||||||
|
} = value;
|
||||||
|
|
||||||
|
const publishData: UpdatePublishFormData = {
|
||||||
|
name,
|
||||||
|
bid: Number(amount),
|
||||||
|
contentIsFree: fee.amount === '0',
|
||||||
|
author,
|
||||||
|
description,
|
||||||
|
fee,
|
||||||
|
languages,
|
||||||
|
releaseTime: release_time,
|
||||||
|
releaseTimeEdited: undefined,
|
||||||
|
thumbnail: thumbnail ? thumbnail.url : null,
|
||||||
|
title,
|
||||||
|
uri,
|
||||||
|
uploadThumbnailStatus: thumbnail ? THUMBNAIL_STATUSES.MANUAL : undefined,
|
||||||
|
licenseUrl,
|
||||||
|
nsfw: isClaimNsfw(claim),
|
||||||
|
tags: tags ? tags.map((tag) => ({ name: tag })) : [],
|
||||||
|
};
|
||||||
|
|
||||||
|
// Make sure custom licenses are mapped properly
|
||||||
|
// If the license isn't one of the standard licenses, map the custom license and description/url
|
||||||
|
if (!CC_LICENSES.some(({ value }) => value === license)) {
|
||||||
|
if (!license || license === NONE || license === PUBLIC_DOMAIN) {
|
||||||
|
publishData.licenseType = license;
|
||||||
|
} else if (license && !licenseUrl && license !== NONE) {
|
||||||
|
publishData.licenseType = COPYRIGHT;
|
||||||
|
} else {
|
||||||
|
publishData.licenseType = OTHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
publishData.otherLicenseDescription = license;
|
||||||
|
} else {
|
||||||
publishData.licenseType = license;
|
publishData.licenseType = license;
|
||||||
} else if (license && !licenseUrl && license !== NONE) {
|
}
|
||||||
publishData.licenseType = COPYRIGHT;
|
if (channelName) {
|
||||||
} else {
|
publishData['channel'] = channelName;
|
||||||
publishData.licenseType = OTHER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
publishData.otherLicenseDescription = license;
|
dispatch({ type: ACTIONS.DO_PREPARE_EDIT, data: publishData });
|
||||||
} else {
|
|
||||||
publishData.licenseType = license;
|
|
||||||
}
|
|
||||||
if (channelName) {
|
|
||||||
publishData['channel'] = channelName;
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch({ type: ACTIONS.DO_PREPARE_EDIT, data: publishData });
|
|
||||||
};
|
|
||||||
|
|
||||||
export const doPublish = (success: Function, fail: Function, preview: Function) => (
|
|
||||||
dispatch: Dispatch,
|
|
||||||
getState: () => {}
|
|
||||||
) => {
|
|
||||||
if (!preview) {
|
|
||||||
dispatch({ type: ACTIONS.PUBLISH_START });
|
|
||||||
}
|
|
||||||
|
|
||||||
const state = getState();
|
|
||||||
const myClaimForUri = selectMyClaimForUri(state);
|
|
||||||
const myChannels = selectMyChannelClaims(state);
|
|
||||||
// const myClaims = selectMyClaimsWithoutChannels(state);
|
|
||||||
// get redux publish form
|
|
||||||
const publishData = selectPublishFormValues(state);
|
|
||||||
|
|
||||||
// destructure the data values
|
|
||||||
const {
|
|
||||||
name,
|
|
||||||
bid,
|
|
||||||
filePath,
|
|
||||||
description,
|
|
||||||
language,
|
|
||||||
releaseTimeEdited,
|
|
||||||
// license,
|
|
||||||
licenseUrl,
|
|
||||||
useLBRYUploader,
|
|
||||||
licenseType,
|
|
||||||
otherLicenseDescription,
|
|
||||||
thumbnail,
|
|
||||||
channel,
|
|
||||||
title,
|
|
||||||
contentIsFree,
|
|
||||||
fee,
|
|
||||||
tags,
|
|
||||||
// locations,
|
|
||||||
optimize,
|
|
||||||
} = publishData;
|
|
||||||
|
|
||||||
// Handle scenario where we have a claim that has the same name as a channel we are publishing with.
|
|
||||||
const myClaimForUriEditing = myClaimForUri && myClaimForUri.name === name ? myClaimForUri : null;
|
|
||||||
|
|
||||||
let publishingLicense;
|
|
||||||
switch (licenseType) {
|
|
||||||
case COPYRIGHT:
|
|
||||||
case OTHER:
|
|
||||||
publishingLicense = otherLicenseDescription;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
publishingLicense = licenseType;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the claim id from the channel name, we will use that instead
|
|
||||||
const namedChannelClaim = myChannels ? myChannels.find((myChannel) => myChannel.name === channel) : null;
|
|
||||||
const channelId = namedChannelClaim ? namedChannelClaim.claim_id : '';
|
|
||||||
|
|
||||||
const publishPayload: {
|
|
||||||
name: ?string,
|
|
||||||
bid: string,
|
|
||||||
description?: string,
|
|
||||||
channel_id?: string,
|
|
||||||
file_path?: string,
|
|
||||||
license_url?: string,
|
|
||||||
license?: string,
|
|
||||||
thumbnail_url?: string,
|
|
||||||
release_time?: number,
|
|
||||||
fee_currency?: string,
|
|
||||||
fee_amount?: string,
|
|
||||||
languages?: Array<string>,
|
|
||||||
tags: Array<string>,
|
|
||||||
locations?: Array<any>,
|
|
||||||
blocking: boolean,
|
|
||||||
optimize_file?: boolean,
|
|
||||||
preview?: boolean,
|
|
||||||
remote_url?: string,
|
|
||||||
} = {
|
|
||||||
name,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
locations: [],
|
|
||||||
bid: creditsToString(bid),
|
|
||||||
languages: [language],
|
|
||||||
tags: tags && tags.map((tag) => tag.name),
|
|
||||||
thumbnail_url: thumbnail,
|
|
||||||
blocking: true,
|
|
||||||
preview: false,
|
|
||||||
};
|
};
|
||||||
// Temporary solution to keep the same publish flow with the new tags api
|
|
||||||
// Eventually we will allow users to enter their own tags on publish
|
|
||||||
|
|
||||||
if (publishingLicense) {
|
export const doPublish =
|
||||||
publishPayload.license = publishingLicense;
|
(success: Function, fail: Function, preview: Function) => (dispatch: Dispatch, getState: () => {}) => {
|
||||||
}
|
if (!preview) {
|
||||||
|
dispatch({ type: ACTIONS.PUBLISH_START });
|
||||||
|
}
|
||||||
|
|
||||||
if (licenseUrl) {
|
const state = getState();
|
||||||
publishPayload.license_url = licenseUrl;
|
const myClaimForUri = selectMyClaimForUri(state);
|
||||||
}
|
const myChannels = selectMyChannelClaims(state);
|
||||||
|
// const myClaims = selectMyClaimsWithoutChannels(state);
|
||||||
|
// get redux publish form
|
||||||
|
const publishData = selectPublishFormValues(state);
|
||||||
|
|
||||||
if (thumbnail) {
|
// destructure the data values
|
||||||
publishPayload.thumbnail_url = thumbnail;
|
const {
|
||||||
}
|
name,
|
||||||
|
bid,
|
||||||
|
filePath,
|
||||||
|
description,
|
||||||
|
language,
|
||||||
|
releaseTimeEdited,
|
||||||
|
// license,
|
||||||
|
licenseUrl,
|
||||||
|
useLBRYUploader,
|
||||||
|
licenseType,
|
||||||
|
otherLicenseDescription,
|
||||||
|
thumbnail,
|
||||||
|
channel,
|
||||||
|
title,
|
||||||
|
contentIsFree,
|
||||||
|
fee,
|
||||||
|
tags,
|
||||||
|
// locations,
|
||||||
|
optimize,
|
||||||
|
} = publishData;
|
||||||
|
|
||||||
if (useLBRYUploader) {
|
// Handle scenario where we have a claim that has the same name as a channel we are publishing with.
|
||||||
publishPayload.tags.push('lbry-first');
|
const myClaimForUriEditing = myClaimForUri && myClaimForUri.name === name ? myClaimForUri : null;
|
||||||
}
|
|
||||||
|
|
||||||
// Set release time to curret date. On edits, keep original release/transaction time as release_time
|
let publishingLicense;
|
||||||
if (releaseTimeEdited) {
|
switch (licenseType) {
|
||||||
publishPayload.release_time = releaseTimeEdited;
|
case COPYRIGHT:
|
||||||
} else if (myClaimForUriEditing && myClaimForUriEditing.value.release_time) {
|
case OTHER:
|
||||||
publishPayload.release_time = Number(myClaimForUri.value.release_time);
|
publishingLicense = otherLicenseDescription;
|
||||||
} else if (myClaimForUriEditing && myClaimForUriEditing.timestamp) {
|
break;
|
||||||
publishPayload.release_time = Number(myClaimForUriEditing.timestamp);
|
default:
|
||||||
} else {
|
publishingLicense = licenseType;
|
||||||
publishPayload.release_time = Number(Math.round(Date.now() / 1000));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (channelId) {
|
// get the claim id from the channel name, we will use that instead
|
||||||
publishPayload.channel_id = channelId;
|
const namedChannelClaim = myChannels ? myChannels.find((myChannel) => myChannel.name === channel) : null;
|
||||||
}
|
const channelId = namedChannelClaim ? namedChannelClaim.claim_id : '';
|
||||||
|
|
||||||
if (myClaimForUriEditing && myClaimForUriEditing.value && myClaimForUriEditing.value.locations) {
|
const publishPayload: {
|
||||||
publishPayload.locations = myClaimForUriEditing.value.locations;
|
name: ?string,
|
||||||
}
|
bid: string,
|
||||||
|
description?: string,
|
||||||
|
channel_id?: string,
|
||||||
|
file_path?: string,
|
||||||
|
license_url?: string,
|
||||||
|
license?: string,
|
||||||
|
thumbnail_url?: string,
|
||||||
|
release_time?: number,
|
||||||
|
fee_currency?: string,
|
||||||
|
fee_amount?: string,
|
||||||
|
languages?: Array<string>,
|
||||||
|
tags: Array<string>,
|
||||||
|
locations?: Array<any>,
|
||||||
|
blocking: boolean,
|
||||||
|
optimize_file?: boolean,
|
||||||
|
preview?: boolean,
|
||||||
|
remote_url?: string,
|
||||||
|
} = {
|
||||||
|
name,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
locations: [],
|
||||||
|
bid: creditsToString(bid),
|
||||||
|
languages: [language],
|
||||||
|
tags: tags && tags.map((tag) => tag.name),
|
||||||
|
thumbnail_url: thumbnail,
|
||||||
|
blocking: true,
|
||||||
|
preview: false,
|
||||||
|
};
|
||||||
|
// Temporary solution to keep the same publish flow with the new tags api
|
||||||
|
// Eventually we will allow users to enter their own tags on publish
|
||||||
|
|
||||||
if (!contentIsFree && fee && fee.currency && Number(fee.amount) > 0) {
|
if (publishingLicense) {
|
||||||
publishPayload.fee_currency = fee.currency;
|
publishPayload.license = publishingLicense;
|
||||||
publishPayload.fee_amount = creditsToString(fee.amount);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (optimize) {
|
if (licenseUrl) {
|
||||||
publishPayload.optimize_file = true;
|
publishPayload.license_url = licenseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only pass file on new uploads, not metadata only edits.
|
if (thumbnail) {
|
||||||
// The sdk will figure it out
|
publishPayload.thumbnail_url = thumbnail;
|
||||||
if (filePath) publishPayload.file_path = filePath;
|
}
|
||||||
|
|
||||||
if (preview) {
|
if (useLBRYUploader) {
|
||||||
publishPayload.preview = true;
|
publishPayload.tags.push('lbry-first');
|
||||||
publishPayload.optimize_file = false;
|
}
|
||||||
|
|
||||||
return Lbry.publish(publishPayload).then((previewResponse: PublishResponse) => {
|
// Set release time to curret date. On edits, keep original release/transaction time as release_time
|
||||||
return preview(previewResponse);
|
if (releaseTimeEdited) {
|
||||||
|
publishPayload.release_time = releaseTimeEdited;
|
||||||
|
} else if (myClaimForUriEditing && myClaimForUriEditing.value.release_time) {
|
||||||
|
publishPayload.release_time = Number(myClaimForUri.value.release_time);
|
||||||
|
} else if (myClaimForUriEditing && myClaimForUriEditing.timestamp) {
|
||||||
|
publishPayload.release_time = Number(myClaimForUriEditing.timestamp);
|
||||||
|
} else {
|
||||||
|
publishPayload.release_time = Number(Math.round(Date.now() / 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (channelId) {
|
||||||
|
publishPayload.channel_id = channelId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (myClaimForUriEditing && myClaimForUriEditing.value && myClaimForUriEditing.value.locations) {
|
||||||
|
publishPayload.locations = myClaimForUriEditing.value.locations;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!contentIsFree && fee && fee.currency && Number(fee.amount) > 0) {
|
||||||
|
publishPayload.fee_currency = fee.currency;
|
||||||
|
publishPayload.fee_amount = creditsToString(fee.amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optimize) {
|
||||||
|
publishPayload.optimize_file = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only pass file on new uploads, not metadata only edits.
|
||||||
|
// The sdk will figure it out
|
||||||
|
if (filePath) publishPayload.file_path = filePath;
|
||||||
|
|
||||||
|
if (preview) {
|
||||||
|
publishPayload.preview = true;
|
||||||
|
publishPayload.optimize_file = false;
|
||||||
|
|
||||||
|
return Lbry.publish(publishPayload).then((previewResponse: PublishResponse) => {
|
||||||
|
return preview(previewResponse);
|
||||||
|
}, fail);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Lbry.publish(publishPayload).then((response: PublishResponse) => {
|
||||||
|
return success(response);
|
||||||
}, fail);
|
}, fail);
|
||||||
}
|
};
|
||||||
|
|
||||||
return Lbry.publish(publishPayload).then((response: PublishResponse) => {
|
|
||||||
return success(response);
|
|
||||||
}, fail);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Calls file_list until any reflecting files are done
|
// Calls file_list until any reflecting files are done
|
||||||
export const doCheckReflectingFiles = () => (dispatch: Dispatch, getState: GetState) => {
|
export const doCheckReflectingFiles = () => (dispatch: Dispatch, getState: GetState) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue