Publishing #158
2 changed files with 131 additions and 75 deletions
70
dist/bundle.es.js
vendored
70
dist/bundle.es.js
vendored
|
@ -2610,9 +2610,55 @@ const doUpdatePublishForm = publishFormValue => dispatch => dispatch({
|
|||
data: _extends$4({}, publishFormValue)
|
||||
});
|
||||
|
||||
const doUploadThumbnail = (filePath, thumbnailBuffer) => dispatch => {
|
||||
const doUploadThumbnail = (filePath, thumbnailBuffer, fsAdapter) => dispatch => {
|
||||
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({
|
||||
type: UPDATE_PUBLISH_FORM,
|
||||
data: {
|
||||
uploadThumbnailStatus: READY,
|
||||
thumbnail: '',
|
||||
nsfw: false
|
||||
}
|
||||
}, doError(error)));
|
||||
};
|
||||
|
||||
dispatch({
|
||||
type: UPDATE_PUBLISH_FORM,
|
||||
data: { uploadThumbnailStatus: 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);
|
||||
data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName });
|
||||
|
||||
return fetch('https://spee.ch/api/claim/publish', {
|
||||
method: 'POST',
|
||||
body: data
|
||||
}).then(response => response.json()).then(json => json.success ? dispatch({
|
||||
type: UPDATE_PUBLISH_FORM,
|
||||
data: {
|
||||
uploadThumbnailStatus: COMPLETE,
|
||||
thumbnail: `${json.data.url}${fileExt}`
|
||||
}
|
||||
}) : uploadError(json.message)).catch(err => uploadError(err.message));
|
||||
});
|
||||
} else {
|
||||
if (filePath) {
|
||||
thumbnail = fs.readFileSync(filePath);
|
||||
fileExt = path.extname(filePath);
|
||||
|
@ -2627,27 +2673,6 @@ const doUploadThumbnail = (filePath, thumbnailBuffer) => dispatch => {
|
|||
return null;
|
||||
}
|
||||
|
||||
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({
|
||||
type: UPDATE_PUBLISH_FORM,
|
||||
data: {
|
||||
uploadThumbnailStatus: READY,
|
||||
thumbnail: '',
|
||||
nsfw: false
|
||||
}
|
||||
}, doError(error)));
|
||||
|
||||
dispatch({
|
||||
type: UPDATE_PUBLISH_FORM,
|
||||
data: { uploadThumbnailStatus: IN_PROGRESS }
|
||||
});
|
||||
|
||||
const data = new FormData();
|
||||
const name = makeid();
|
||||
const file = new File([thumbnail], fileName, { type: fileType });
|
||||
|
@ -2664,6 +2689,7 @@ const doUploadThumbnail = (filePath, thumbnailBuffer) => dispatch => {
|
|||
thumbnail: `${json.data.url}${fileExt}`
|
||||
}
|
||||
}) : uploadError(json.message)).catch(err => uploadError(err.message));
|
||||
}
|
||||
};
|
||||
|
||||
const doPrepareEdit = (claim, uri, fileInfo) => dispatch => {
|
||||
|
|
|
@ -60,23 +60,9 @@ export const doUpdatePublishForm = (publishFormValue: UpdatePublishFormData) =>
|
|||
data: { ...publishFormValue },
|
||||
});
|
||||
|
||||
export const doUploadThumbnail = (filePath: string, thumbnailBuffer: Uint8Array) => (dispatch: Dispatch) => {
|
||||
export const doUploadThumbnail = (filePath: string, thumbnailBuffer: Uint8Array, fsAdapter: any) => (dispatch: Dispatch) => {
|
||||
let thumbnail, fileExt, fileName, fileType;
|
||||
|
||||
if (filePath) {
|
||||
thumbnail = fs.readFileSync(filePath);
|
||||
fileExt = path.extname(filePath);
|
||||
fileName = path.basename(filePath);
|
||||
fileType = `image/${fileExt.slice(1)}`;
|
||||
} else if (thumbnailBuffer) {
|
||||
thumbnail = thumbnailBuffer;
|
||||
fileExt = '.png';
|
||||
fileName = 'thumbnail.png';
|
||||
fileType = 'image/png';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
const makeid = () => {
|
||||
let text = '';
|
||||
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
|
@ -84,7 +70,7 @@ export const doUploadThumbnail = (filePath: string, thumbnailBuffer: Uint8Array)
|
|||
return text;
|
||||
};
|
||||
|
||||
const uploadError = (error = '') =>
|
||||
const uploadError = (error = '') => {
|
||||
dispatch(
|
||||
batchActions(
|
||||
{
|
||||
|
@ -98,12 +84,55 @@ export const doUploadThumbnail = (filePath: string, thumbnailBuffer: Uint8Array)
|
|||
doError(error)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName });
|
||||
|
||||
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: {
|
||||
uploadThumbnailStatus: THUMBNAIL_STATUSES.COMPLETE,
|
||||
thumbnail: `${json.data.url}${fileExt}`,
|
||||
},
|
||||
})
|
||||
: uploadError(json.message)
|
||||
)
|
||||
.catch(err => uploadError(err.message));
|
||||
});
|
||||
} else {
|
||||
if (filePath) {
|
||||
thumbnail = fs.readFileSync(filePath);
|
||||
fileExt = path.extname(filePath);
|
||||
fileName = path.basename(filePath);
|
||||
fileType = `image/${fileExt.slice(1)}`;
|
||||
} else if (thumbnailBuffer) {
|
||||
thumbnail = thumbnailBuffer;
|
||||
fileExt = '.png';
|
||||
fileName = 'thumbnail.png';
|
||||
fileType = 'image/png';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
const data = new FormData();
|
||||
const name = makeid();
|
||||
const file = new File([thumbnail], fileName, { type: fileType });
|
||||
|
@ -127,6 +156,7 @@ export const doUploadThumbnail = (filePath: string, thumbnailBuffer: Uint8Array)
|
|||
: uploadError(json.message)
|
||||
)
|
||||
.catch(err => uploadError(err.message));
|
||||
}
|
||||
};
|
||||
|
||||
export const doPrepareEdit = (claim: StreamClaim, uri: string, fileInfo: FileListItem) => (dispatch: Dispatch) => {
|
||||
|
|
Loading…
Reference in a new issue