add doResetThumbnailStatus and doUploadThumbnail actions
This commit is contained in:
parent
e32a597c38
commit
9a658d41a8
1 changed files with 75 additions and 9 deletions
|
@ -6,6 +6,7 @@ import {
|
||||||
doNotify,
|
doNotify,
|
||||||
MODALS,
|
MODALS,
|
||||||
selectMyChannelClaims,
|
selectMyChannelClaims,
|
||||||
|
STATUSES
|
||||||
} from 'lbry-redux';
|
} from 'lbry-redux';
|
||||||
import { selectPendingPublishes } from 'redux/selectors/publish';
|
import { selectPendingPublishes } from 'redux/selectors/publish';
|
||||||
import type {
|
import type {
|
||||||
|
@ -13,6 +14,8 @@ import type {
|
||||||
UpdatePublishFormAction,
|
UpdatePublishFormAction,
|
||||||
PublishParams,
|
PublishParams,
|
||||||
} from 'redux/reducers/publish';
|
} from 'redux/reducers/publish';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
type Action = UpdatePublishFormAction | { type: ACTIONS.CLEAR_PUBLISH };
|
type Action = UpdatePublishFormAction | { type: ACTIONS.CLEAR_PUBLISH };
|
||||||
type PromiseAction = Promise<Action>;
|
type PromiseAction = Promise<Action>;
|
||||||
|
@ -30,15 +33,78 @@ export const doUpdatePublishForm = (publishFormValue: UpdatePublishFormData) =>
|
||||||
data: { ...publishFormValue },
|
data: { ...publishFormValue },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const doPrepareEdit = (claim: any, uri: string) => (dispatch: Dispatch) => {
|
export const doResetThumbnailStatus = () => (dispatch: Dispatch): Action =>
|
||||||
const {
|
fetch('https://spee.ch/api/channel/availability/@testing')
|
||||||
name,
|
.then(() =>
|
||||||
amount,
|
dispatch({
|
||||||
channel_name: channelName,
|
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
||||||
value: {
|
data: { thumbnailStatus: STATUSES.READY },
|
||||||
stream: { metadata },
|
})
|
||||||
},
|
)
|
||||||
} = claim;
|
.catch(() =>
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
||||||
|
data: { thumbnailStatus: STATUSES.DOWN },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
export const doUploadThumbnail = (filePath: string, nsfw: boolean) => (dispatch: Dispatch) => {
|
||||||
|
const thumbnail = fs.readFileSync(filePath);
|
||||||
|
const fileExt = path.extname(filePath);
|
||||||
|
|
||||||
|
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: string = '') =>
|
||||||
|
dispatch(
|
||||||
|
batchActions(
|
||||||
|
{
|
||||||
|
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
||||||
|
data: { thumbnailStatus: STATUSES.DOWN },
|
||||||
|
},
|
||||||
|
doAlertError(error)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
||||||
|
data: { thumbnailStatus: STATUSES.IN_PROGRESS },
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = new FormData();
|
||||||
|
const name = makeid();
|
||||||
|
const blob = new Blob([thumbnail], { type: `image/${fileExt.slice(1)}` });
|
||||||
|
data.append('name', name);
|
||||||
|
data.append('file', blob);
|
||||||
|
data.append('nsfw', nsfw.toString());
|
||||||
|
return fetch('https://spee.ch/api/claim/publish', {
|
||||||
|
method: 'POST',
|
||||||
|
body: data,
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(
|
||||||
|
json =>
|
||||||
|
json.success
|
||||||
|
? dispatch({
|
||||||
|
type: ACTIONS.UPDATE_PUBLISH_FORM,
|
||||||
|
data: {
|
||||||
|
thumbnailStatus: STATUSES.COMPLETE,
|
||||||
|
thumbnailUrl: `${json.data.url}${fileExt}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
: uploadError()
|
||||||
|
)
|
||||||
|
.catch(() => uploadError());
|
||||||
|
};
|
||||||
|
|
||||||
|
export const doPrepareEdit = (claim: any) => (dispatch: Dispatch) => {
|
||||||
|
const { name, amount, channel_name: channelName, value: { stream: { metadata } } } = claim;
|
||||||
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
author,
|
author,
|
||||||
description,
|
description,
|
||||||
|
|
Loading…
Add table
Reference in a new issue