From 5ee22d42d6d976cf293e5cea55d866399e593c59 Mon Sep 17 00:00:00 2001 From: jessop Date: Mon, 30 Sep 2019 15:16:38 -0400 Subject: [PATCH 1/2] tv publish --- dist/bundle.es.js | 38 ++++++++++++++++++++++++++++++++---- dist/flow-typed/Lbry.js | 2 +- flow-typed/Lbry.js | 2 +- src/constants/headers.js | 1 + src/constants/speech_urls.js | 2 ++ src/index.js | 2 ++ src/lbry.js | 11 ++++++++++- src/redux/actions/publish.js | 7 ++++--- 8 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 src/constants/headers.js create mode 100644 src/constants/speech_urls.js diff --git a/dist/bundle.es.js b/dist/bundle.es.js index e31750c..e30f9b3 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -652,6 +652,12 @@ var transaction_list = /*#__PURE__*/Object.freeze({ PAGE_SIZE: PAGE_SIZE$1 }); +const AUTH_TOKEN = 'X-Lbry-Auth-Token'; + +var headers = /*#__PURE__*/Object.freeze({ + AUTH_TOKEN: AUTH_TOKEN +}); + const SEARCH_TYPES = { FILE: 'file', CHANNEL: 'channel', @@ -709,6 +715,7 @@ const Lbry = { setOverride: (methodName, newMethod) => { Lbry.overrides[methodName] = newMethod; }, + getApiRequestHeaders: () => Lbry.apiRequestHeaders, // Returns a human readable media type based on the content type or extension of a file that is returned by the sdk getMediaType: (contentType, fileName) => { @@ -744,7 +751,6 @@ const Lbry = { // Claim fetching and manipulation resolve: params => daemonCallWithResult('resolve', params), get: params => daemonCallWithResult('get', params), - publish: params => daemonCallWithResult('publish', params), claim_search: params => daemonCallWithResult('claim_search', params), claim_list: params => daemonCallWithResult('claim_list', params), channel_create: params => daemonCallWithResult('channel_create', params), @@ -814,6 +820,14 @@ const Lbry = { } }; +Lbry.publish = (params = {}) => new Promise((resolve, reject) => { + if (Lbry.overrides.publish) { + Lbry.overrides.publish(params).then(resolve, reject); + } else { + apiCall('publish', params, resolve, reject); + } +}); + function checkAndParse(response) { if (response.status >= 200 && response.status < 300) { return response.json(); @@ -1079,6 +1093,18 @@ 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.")); } @@ -3192,6 +3218,9 @@ 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 || {}; @@ -3289,7 +3318,7 @@ const doResetThumbnailStatus = () => dispatch => { } }); - return fetch('https://spee.ch/api/config/site/publishing').then(res => res.json()).then(status => { + return fetch(SPEECH_STATUS).then(res => res.json()).then(status => { if (status.disabled) { throw Error(); } @@ -3358,7 +3387,7 @@ const doUploadThumbnail = (filePath, thumbnailBuffer, fsAdapter, fs, path) => di // $FlowFixMe data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName }); - return fetch('https://spee.ch/api/claim/publish', { + return fetch(SPEECH_PUBLISH, { method: 'POST', body: data }).then(response => response.json()).then(json => json.success ? dispatch({ @@ -3390,7 +3419,7 @@ const doUploadThumbnail = (filePath, thumbnailBuffer, fsAdapter, fs, path) => di data.append('name', name); data.append('file', file); - return fetch('https://spee.ch/api/claim/publish', { + return fetch(SPEECH_PUBLISH, { method: 'POST', body: data }).then(response => response.json()).then(json => json.success ? dispatch({ @@ -5260,6 +5289,7 @@ 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; diff --git a/dist/flow-typed/Lbry.js b/dist/flow-typed/Lbry.js index 200acce..c38b59e 100644 --- a/dist/flow-typed/Lbry.js +++ b/dist/flow-typed/Lbry.js @@ -168,7 +168,7 @@ declare type LbryTypes = { version: () => Promise, resolve: (params: {}) => Promise, get: (params: {}) => Promise, - publish: (params: {}) => Promise, + publish?: (params: {}) => Promise, claim_search: (params: {}) => Promise, claim_list: (params?: {}) => Promise, diff --git a/flow-typed/Lbry.js b/flow-typed/Lbry.js index 200acce..c38b59e 100644 --- a/flow-typed/Lbry.js +++ b/flow-typed/Lbry.js @@ -168,7 +168,7 @@ declare type LbryTypes = { version: () => Promise, resolve: (params: {}) => Promise, get: (params: {}) => Promise, - publish: (params: {}) => Promise, + publish?: (params: {}) => Promise, claim_search: (params: {}) => Promise, claim_list: (params?: {}) => Promise, diff --git a/src/constants/headers.js b/src/constants/headers.js new file mode 100644 index 0000000..84aead8 --- /dev/null +++ b/src/constants/headers.js @@ -0,0 +1 @@ +export const AUTH_TOKEN = 'X-Lbry-Auth-Token'; diff --git a/src/constants/speech_urls.js b/src/constants/speech_urls.js new file mode 100644 index 0000000..d61abab --- /dev/null +++ b/src/constants/speech_urls.js @@ -0,0 +1,2 @@ +export const SPEECH_STATUS = 'https://spee.ch/api/config/site/publishing'; +export const SPEECH_PUBLISH = 'https://spee.ch/api/claim/publish'; diff --git a/src/index.js b/src/index.js index 59abad9..47f7022 100644 --- a/src/index.js +++ b/src/index.js @@ -7,6 +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 { SEARCH_TYPES, SEARCH_OPTIONS } from 'constants/search'; import { DEFAULT_KNOWN_TAGS, DEFAULT_FOLLOWED_TAGS, MATURE_TAGS } from 'constants/tags'; import Lbry from 'lbry'; @@ -28,6 +29,7 @@ export { DEFAULT_KNOWN_TAGS, DEFAULT_FOLLOWED_TAGS, MATURE_TAGS, + HEADERS, }; // common diff --git a/src/lbry.js b/src/lbry.js index 8761c72..f54ad42 100644 --- a/src/lbry.js +++ b/src/lbry.js @@ -30,6 +30,7 @@ const Lbry: LbryTypes = { setOverride: (methodName, newMethod) => { Lbry.overrides[methodName] = newMethod; }, + getApiRequestHeaders: () => Lbry.apiRequestHeaders, // Returns a human readable media type based on the content type or extension of a file that is returned by the sdk getMediaType: (contentType?: string, fileName: ?string) => { @@ -74,7 +75,6 @@ const Lbry: LbryTypes = { // Claim fetching and manipulation resolve: params => daemonCallWithResult('resolve', params), get: params => daemonCallWithResult('get', params), - publish: params => daemonCallWithResult('publish', params), claim_search: params => daemonCallWithResult('claim_search', params), claim_list: params => daemonCallWithResult('claim_list', params), channel_create: params => daemonCallWithResult('channel_create', params), @@ -146,6 +146,15 @@ const Lbry: LbryTypes = { }, }; +Lbry.publish = (params = {}) => + new Promise((resolve, reject) => { + if (Lbry.overrides.publish) { + Lbry.overrides.publish(params).then(resolve, reject); + } else { + apiCall('publish', params, resolve, reject); + } + }); + function checkAndParse(response) { if (response.status >= 200 && response.status < 300) { return response.json(); diff --git a/src/redux/actions/publish.js b/src/redux/actions/publish.js index e622cfb..a00aca0 100644 --- a/src/redux/actions/publish.js +++ b/src/redux/actions/publish.js @@ -1,5 +1,6 @@ // @flow import { CC_LICENSES, COPYRIGHT, OTHER, NONE, PUBLIC_DOMAIN } from 'constants/licenses'; +import { SPEECH_STATUS, SPEECH_PUBLISH } from 'constants/speech_urls'; import * as ACTIONS from 'constants/action_types'; import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses'; import Lbry from 'lbry'; @@ -22,7 +23,7 @@ export const doResetThumbnailStatus = () => (dispatch: Dispatch) => { }, }); - return fetch('https://spee.ch/api/config/site/publishing') + return fetch(SPEECH_STATUS) .then(res => res.json()) .then(status => { if (status.disabled) { @@ -110,7 +111,7 @@ export const doUploadThumbnail = ( // $FlowFixMe data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName }); - return fetch('https://spee.ch/api/claim/publish', { + return fetch(SPEECH_PUBLISH, { method: 'POST', body: data, }) @@ -149,7 +150,7 @@ export const doUploadThumbnail = ( data.append('name', name); data.append('file', file); - return fetch('https://spee.ch/api/claim/publish', { + return fetch(SPEECH_PUBLISH, { method: 'POST', body: data, }) From 4aa1f6f379061becf4485380416ec00faed3be6c Mon Sep 17 00:00:00 2001 From: jessop Date: Mon, 7 Oct 2019 12:33:06 -0400 Subject: [PATCH 2/2] doUploadThumbnail signature takes local path OR File() object --- dist/bundle.es.js | 40 ++++++++++++------------------------ src/constants/headers.js | 1 - src/index.js | 4 ++-- src/redux/actions/publish.js | 23 ++++++++++----------- 4 files changed, 26 insertions(+), 42 deletions(-) delete mode 100644 src/constants/headers.js diff --git a/dist/bundle.es.js b/dist/bundle.es.js index e30f9b3..dc02455 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -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; diff --git a/src/constants/headers.js b/src/constants/headers.js deleted file mode 100644 index 84aead8..0000000 --- a/src/constants/headers.js +++ /dev/null @@ -1 +0,0 @@ -export const AUTH_TOKEN = 'X-Lbry-Auth-Token'; diff --git a/src/index.js b/src/index.js index 47f7022..3543f5f 100644 --- a/src/index.js +++ b/src/index.js @@ -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 diff --git a/src/redux/actions/publish.js b/src/redux/actions/publish.js index a00aca0..78d6503 100644 --- a/src/redux/actions/publish.js +++ b/src/redux/actions/publish.js @@ -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);