doUploadThumbnail signature takes local path OR File() object

This commit is contained in:
jessop 2019-10-07 12:33:06 -04:00 committed by Sean Yesmunt
parent 5ee22d42d6
commit 4aa1f6f379
4 changed files with 26 additions and 42 deletions

40
dist/bundle.es.js vendored
View file

@ -652,10 +652,12 @@ var transaction_list = /*#__PURE__*/Object.freeze({
PAGE_SIZE: PAGE_SIZE$1
});
const AUTH_TOKEN = 'X-Lbry-Auth-Token';
const SPEECH_STATUS = 'https://spee.ch/api/config/site/publishing';
const SPEECH_PUBLISH = 'https://spee.ch/api/claim/publish';
var headers = /*#__PURE__*/Object.freeze({
AUTH_TOKEN: AUTH_TOKEN
var speech_urls = /*#__PURE__*/Object.freeze({
SPEECH_STATUS: SPEECH_STATUS,
SPEECH_PUBLISH: SPEECH_PUBLISH
});
const SEARCH_TYPES = {
@ -1093,18 +1095,6 @@ function buildURI(UrlObj, includeProto = true, protoDefault = 'lbry://') {
deprecatedParts = _objectWithoutProperties(UrlObj, ['streamName', 'streamClaimId', 'channelName', 'channelClaimId', 'primaryClaimSequence', 'primaryBidPosition', 'secondaryClaimSequence', 'secondaryBidPosition']);
const { claimId, claimName, contentName } = deprecatedParts;
{
if (claimId) {
console.error(__("'claimId' should no longer be used. Use 'streamClaimId' or 'channelClaimId' instead"));
}
if (claimName) {
console.error(__("'claimName' should no longer be used. Use 'streamClaimName' or 'channelClaimName' instead"));
}
if (contentName) {
console.error(__("'contentName' should no longer be used. Use 'streamName' instead"));
}
}
if (!claimName && !channelName && !streamName) {
console.error(__("'claimName', 'channelName', and 'streamName' are all empty. One must be present to build a url."));
}
@ -3218,9 +3208,6 @@ function doSetFileListSort(page, value) {
};
}
const SPEECH_STATUS = 'https://spee.ch/api/config/site/publishing';
const SPEECH_PUBLISH = 'https://spee.ch/api/claim/publish';
function _objectWithoutProperties$2(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
const selectState$5 = state => state.publish || {};
@ -3349,7 +3336,7 @@ const doUpdatePublishForm = publishFormValue => dispatch => dispatch({
data: _extends$5({}, publishFormValue)
});
const doUploadThumbnail = (filePath, thumbnailBuffer, fsAdapter, fs, path) => dispatch => {
const doUploadThumbnail = (filePath, thumbnailBlob, fsAdapter, fs, path) => dispatch => {
let thumbnail, fileExt, fileName, fileType;
const makeid = () => {
@ -3399,23 +3386,22 @@ const doUploadThumbnail = (filePath, thumbnailBuffer, fsAdapter, fs, path) => di
}) : uploadError(json.message)).catch(err => uploadError(err.message));
});
} else {
if (filePath) {
if (filePath && fs && path) {
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 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 = new File([thumbnail], fileName, { type: fileType });
const file = thumbnailBlob || thumbnail && new File([thumbnail], fileName, { type: fileType });
data.append('name', name);
data.append('file', file);
@ -5289,7 +5275,6 @@ exports.ACTIONS = action_types;
exports.CLAIM_VALUES = claim;
exports.DEFAULT_FOLLOWED_TAGS = DEFAULT_FOLLOWED_TAGS;
exports.DEFAULT_KNOWN_TAGS = DEFAULT_KNOWN_TAGS;
exports.HEADERS = headers;
exports.LICENSES = licenses;
exports.Lbry = lbryProxy;
exports.MATURE_TAGS = MATURE_TAGS;
@ -5298,6 +5283,7 @@ exports.SEARCH_OPTIONS = SEARCH_OPTIONS;
exports.SEARCH_TYPES = SEARCH_TYPES;
exports.SETTINGS = settings;
exports.SORT_OPTIONS = sort_options;
exports.SPEECH_URLS = speech_urls;
exports.THUMBNAIL_STATUSES = thumbnail_upload_statuses;
exports.TRANSACTIONS = transaction_types;
exports.TX_LIST = transaction_list;

View file

@ -1 +0,0 @@
export const AUTH_TOKEN = 'X-Lbry-Auth-Token';

View file

@ -7,7 +7,7 @@ import * as SORT_OPTIONS from 'constants/sort_options';
import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses';
import * as TRANSACTIONS from 'constants/transaction_types';
import * as TX_LIST from 'constants/transaction_list';
import * as HEADERS from 'constants/headers';
import * as SPEECH_URLS from 'constants/speech_urls';
import { SEARCH_TYPES, SEARCH_OPTIONS } from 'constants/search';
import { DEFAULT_KNOWN_TAGS, DEFAULT_FOLLOWED_TAGS, MATURE_TAGS } from 'constants/tags';
import Lbry from 'lbry';
@ -29,7 +29,7 @@ export {
DEFAULT_KNOWN_TAGS,
DEFAULT_FOLLOWED_TAGS,
MATURE_TAGS,
HEADERS,
SPEECH_URLS,
};
// common

View file

@ -63,11 +63,11 @@ export const doUpdatePublishForm = (publishFormValue: UpdatePublishFormData) =>
});
export const doUploadThumbnail = (
filePath: string,
thumbnailBuffer: Uint8Array,
fsAdapter: any,
fs: any,
path: any
filePath?: string,
thumbnailBlob?: File,
fsAdapter?: any,
fs?: any,
path?: any
) => (dispatch: Dispatch) => {
let thumbnail, fileExt, fileName, fileType;
@ -130,23 +130,22 @@ export const doUploadThumbnail = (
.catch(err => uploadError(err.message));
});
} else {
if (filePath) {
if (filePath && fs && path) {
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 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 = new File([thumbnail], fileName, { type: fileType });
const file = thumbnailBlob || (thumbnail && new File([thumbnail], fileName, { type: fileType }));
data.append('name', name);
data.append('file', file);