Publishing #158

Merged
akinwale merged 5 commits from publishing into master 2019-07-01 21:49:51 +02:00
2 changed files with 131 additions and 75 deletions
Showing only changes of commit d955f36801 - Show all commits

100
dist/bundle.es.js vendored
View file

@ -2610,23 +2610,9 @@ const doUpdatePublishForm = publishFormValue => dispatch => dispatch({
data: _extends$4({}, publishFormValue) data: _extends$4({}, publishFormValue)
}); });
const doUploadThumbnail = (filePath, thumbnailBuffer) => dispatch => { const doUploadThumbnail = (filePath, thumbnailBuffer, fsAdapter) => dispatch => {
let thumbnail, fileExt, fileName, fileType; 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 = () => { const makeid = () => {
let text = ''; let text = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
@ -2634,36 +2620,76 @@ const doUploadThumbnail = (filePath, thumbnailBuffer) => dispatch => {
return text; return text;
}; };
const uploadError = (error = '') => dispatch(batchActions({ const uploadError = (error = '') => {
type: UPDATE_PUBLISH_FORM, dispatch(batchActions({
data: { type: UPDATE_PUBLISH_FORM,
uploadThumbnailStatus: READY, data: {
thumbnail: '', uploadThumbnailStatus: READY,
nsfw: false thumbnail: '',
} nsfw: false
}, doError(error))); }
}, doError(error)));
};
dispatch({ dispatch({
type: UPDATE_PUBLISH_FORM, type: UPDATE_PUBLISH_FORM,
data: { uploadThumbnailStatus: IN_PROGRESS } data: { uploadThumbnailStatus: IN_PROGRESS }
}); });
const data = new FormData(); if (fsAdapter && fsAdapter.readFile && filePath) {
const name = makeid(); fsAdapter.readFile(filePath, 'base64').then(base64Image => {
const file = new File([thumbnail], fileName, { type: fileType }); fileExt = 'png';
data.append('name', name); fileName = 'thumbnail.png';
data.append('file', file); fileType = 'image/png';
return fetch('https://spee.ch/api/claim/publish', { const data = new FormData();
method: 'POST', const name = makeid();
body: data data.append('name', name);
}).then(response => response.json()).then(json => json.success ? dispatch({ data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName });
type: UPDATE_PUBLISH_FORM,
data: { return fetch('https://spee.ch/api/claim/publish', {
uploadThumbnailStatus: COMPLETE, method: 'POST',
thumbnail: `${json.data.url}${fileExt}` 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);
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;
} }
}) : uploadError(json.message)).catch(err => uploadError(err.message));
const data = new FormData();
const name = makeid();
const file = new File([thumbnail], fileName, { type: fileType });
data.append('name', name);
data.append('file', file);
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));
}
}; };
const doPrepareEdit = (claim, uri, fileInfo) => dispatch => { const doPrepareEdit = (claim, uri, fileInfo) => dispatch => {

View file

@ -60,23 +60,9 @@ export const doUpdatePublishForm = (publishFormValue: UpdatePublishFormData) =>
data: { ...publishFormValue }, 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; 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 = () => { const makeid = () => {
let text = ''; let text = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
@ -84,7 +70,7 @@ export const doUploadThumbnail = (filePath: string, thumbnailBuffer: Uint8Array)
return text; return text;
}; };
const uploadError = (error = '') => const uploadError = (error = '') => {
dispatch( dispatch(
batchActions( batchActions(
{ {
@ -98,35 +84,79 @@ export const doUploadThumbnail = (filePath: string, thumbnailBuffer: Uint8Array)
doError(error) doError(error)
) )
); );
}
dispatch({ dispatch({
type: ACTIONS.UPDATE_PUBLISH_FORM, type: ACTIONS.UPDATE_PUBLISH_FORM,
data: { uploadThumbnailStatus: THUMBNAIL_STATUSES.IN_PROGRESS }, data: { uploadThumbnailStatus: THUMBNAIL_STATUSES.IN_PROGRESS },
}); });
const data = new FormData(); if (fsAdapter && fsAdapter.readFile && filePath) {
const name = makeid(); fsAdapter.readFile(filePath, 'base64').then(base64Image => {
const file = new File([thumbnail], fileName, { type: fileType }); fileExt = 'png';
data.append('name', name); fileName = 'thumbnail.png';
data.append('file', file); fileType = 'image/png';
return fetch('https://spee.ch/api/claim/publish', { const data = new FormData();
method: 'POST', const name = makeid();
body: data, data.append('name', name);
}) data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName });
.then(response => response.json())
.then(json => return fetch('https://spee.ch/api/claim/publish', {
json.success method: 'POST',
? dispatch({ body: data
type: ACTIONS.UPDATE_PUBLISH_FORM, }).then(response => response.json())
data: { .then(json => json.success
uploadThumbnailStatus: THUMBNAIL_STATUSES.COMPLETE, ? dispatch({
thumbnail: `${json.data.url}${fileExt}`, type: ACTIONS.UPDATE_PUBLISH_FORM,
}, data: {
}) uploadThumbnailStatus: THUMBNAIL_STATUSES.COMPLETE,
: uploadError(json.message) thumbnail: `${json.data.url}${fileExt}`,
) },
.catch(err => uploadError(err.message)); })
: 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 });
data.append('name', name);
data.append('file', file);
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));
}
}; };
export const doPrepareEdit = (claim: StreamClaim, uri: string, fileInfo: FileListItem) => (dispatch: Dispatch) => { export const doPrepareEdit = (claim: StreamClaim, uri: string, fileInfo: FileListItem) => (dispatch: Dispatch) => {