From 1523bbd33fa215bedebc15bbf2b71a3f7c837a5b Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Tue, 7 Jul 2020 18:06:59 -0400 Subject: [PATCH] add 'lbry-first' tag to lbry-first publishes --- dist/bundle.es.js | 24 +++++++++++++++--------- flow-typed/LbryFirst.js | 10 +++++----- src/lbry-first.js | 33 +++++++++++++++++++++------------ src/redux/actions/publish.js | 19 +++++++++++-------- 4 files changed, 52 insertions(+), 34 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 2ee2b36..2f9771f 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -1261,14 +1261,17 @@ const LbryFirst = { upload: (params = {}) => { // Only upload when originally publishing for now if (!params.file_path) { - return {}; + return new Promise(); } - const uploadParams = {}; - uploadParams.Title = params.title; - uploadParams.Description = params.description; - uploadParams.FilePath = params.file_path; - uploadParams.Category = ''; - uploadParams.Keywords = ''; + + const uploadParams = { + Title: params.title, + Description: params.description, + FilePath: params.file_path, + Category: '', + Keywords: '' + }; + return lbryFirstCallWithResult('youtube.Upload', uploadParams); }, @@ -1350,7 +1353,6 @@ function apiCall$1(method, params, resolve, reject) { } function lbryFirstCallWithResult(name, params = {}) { - console.log(`LbryFirst: calling ${name}`); return new Promise((resolve, reject) => { apiCall$1(name, params, result => { resolve(result); @@ -4681,6 +4683,10 @@ const doPublish = (success, fail) => (dispatch, getState) => { publishPayload.thumbnail_url = thumbnail; } + if (useLBRYUploader) { + publishPayload.tags.push('lbry-first'); + } + // Set release time to curret date. On edits, keep original release/transaction time as release_time if (myClaimForUriEditing && myClaimForUriEditing.value.release_time) { publishPayload.release_time = Number(myClaimForUri.value.release_time); @@ -4710,7 +4716,7 @@ const doPublish = (success, fail) => (dispatch, getState) => { // Only pass file on new uploads, not metadata only edits. // The sdk will figure it out if (filePath) publishPayload.file_path = filePath; - // if (useLBRYUploader) return LbryFirst.upload(publishPayload); + return lbryProxy.publish(publishPayload).then(response => { if (!useLBRYUploader) { return success(response); diff --git a/flow-typed/LbryFirst.js b/flow-typed/LbryFirst.js index 3cad4dc..850fa88 100644 --- a/flow-typed/LbryFirst.js +++ b/flow-typed/LbryFirst.js @@ -71,9 +71,9 @@ declare type UploadResponse = { declare type HasYTAuthResponse = { HashAuth: boolean, -} +}; -declare type YTSignupResponse = {} +declare type YTSignupResponse = {}; // // Types used in the generic LbryFirst object that is exported @@ -93,7 +93,7 @@ declare type LbryFirstTypes = { stop: () => Promise, status: () => Promise, version: () => Promise, - upload: (params: {}) => Promise, - hasYTAuth: () =>Promise, - ytSignup: () =>Promise, + upload: any => Promise, + hasYTAuth: () => Promise, + ytSignup: () => Promise, }; diff --git a/src/lbry-first.js b/src/lbry-first.js index 0a467d6..d0e9f3b 100644 --- a/src/lbry-first.js +++ b/src/lbry-first.js @@ -23,7 +23,8 @@ const LbryFirst: LbryFirstTypes = { }, unsetApiHeader: key => { - Object.keys(LbryFirst.apiRequestHeaders).includes(key) && delete LbryFirst.apiRequestHeaders['key']; + Object.keys(LbryFirst.apiRequestHeaders).includes(key) && + delete LbryFirst.apiRequestHeaders['key']; }, // Allow overriding Lbry methods overrides: {}, @@ -40,17 +41,26 @@ const LbryFirst: LbryFirstTypes = { version: () => lbryFirstCallWithResult('version', {}), // Upload to youtube - upload: (params = {}) => { + upload: (params: { title: string, description: string, file_path: ?string } = {}) => { // Only upload when originally publishing for now if (!params.file_path) { - return {}; + return Promise.resolve(); } - const uploadParams = {}; - uploadParams.Title = params.title; - uploadParams.Description = params.description; - uploadParams.FilePath = params.file_path; - uploadParams.Category = ''; - uploadParams.Keywords = ''; + + const uploadParams: { + Title: string, + Description: string, + FilePath: string, + Category: string, + Keywords: string, + } = { + Title: params.title, + Description: params.description, + FilePath: params.file_path, + Category: '', + Keywords: '', + }; + return lbryFirstCallWithResult('youtube.Upload', uploadParams); }, @@ -111,14 +121,14 @@ function checkAndParse(response) { export function apiCall(method: string, params: ?{}, resolve: Function, reject: Function) { const counter = new Date().getTime(); - params = [params]; + const paramsArray = [params]; const options = { method: 'POST', headers: LbryFirst.apiRequestHeaders, body: JSON.stringify({ jsonrpc: '2.0', method, - params, + params: paramsArray, id: counter, }), }; @@ -137,7 +147,6 @@ export function apiCall(method: string, params: ?{}, resolve: Function, reject: } function lbryFirstCallWithResult(name: string, params: ?{} = {}) { - console.log(`LbryFirst: calling ${name}`); return new Promise((resolve, reject) => { apiCall( name, diff --git a/src/redux/actions/publish.js b/src/redux/actions/publish.js index 6d56e1f..b5364e5 100644 --- a/src/redux/actions/publish.js +++ b/src/redux/actions/publish.js @@ -323,6 +323,10 @@ export const doPublish = (success: Function, fail: Function) => ( publishPayload.thumbnail_url = thumbnail; } + if (useLBRYUploader) { + publishPayload.tags.push('lbry-first'); + } + // Set release time to curret date. On edits, keep original release/transaction time as release_time if (myClaimForUriEditing && myClaimForUriEditing.value.release_time) { publishPayload.release_time = Number(myClaimForUri.value.release_time); @@ -352,14 +356,13 @@ export const doPublish = (success: Function, fail: Function) => ( // Only pass file on new uploads, not metadata only edits. // The sdk will figure it out if (filePath) publishPayload.file_path = filePath; - // if (useLBRYUploader) return LbryFirst.upload(publishPayload); - return Lbry.publish(publishPayload) - .then((response) => { - if (!useLBRYUploader) { - return success(response); - } - return LbryFirst.upload(publishPayload).then(success(response), success(response)); - }, fail); + + return Lbry.publish(publishPayload).then(response => { + if (!useLBRYUploader) { + return success(response); + } + return LbryFirst.upload(publishPayload).then(success(response), success(response)); + }, fail); }; // Calls file_list until any reflecting files are done