Tv publish api #209

Merged
jessopb merged 2 commits from tvPublishAPI into master 2019-10-22 22:33:57 +02:00
7 changed files with 59 additions and 30 deletions

40
dist/bundle.es.js vendored
View file

@ -652,6 +652,14 @@ var transaction_list = /*#__PURE__*/Object.freeze({
PAGE_SIZE: PAGE_SIZE$1 PAGE_SIZE: PAGE_SIZE$1
}); });
const SPEECH_STATUS = 'https://spee.ch/api/config/site/publishing';
const SPEECH_PUBLISH = 'https://spee.ch/api/claim/publish';
var speech_urls = /*#__PURE__*/Object.freeze({
SPEECH_STATUS: SPEECH_STATUS,
SPEECH_PUBLISH: SPEECH_PUBLISH
});
const SEARCH_TYPES = { const SEARCH_TYPES = {
FILE: 'file', FILE: 'file',
CHANNEL: 'channel', CHANNEL: 'channel',
@ -709,6 +717,7 @@ const Lbry = {
setOverride: (methodName, newMethod) => { setOverride: (methodName, newMethod) => {
Lbry.overrides[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 // 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) => { getMediaType: (contentType, fileName) => {
@ -744,7 +753,6 @@ const Lbry = {
// Claim fetching and manipulation // Claim fetching and manipulation
resolve: params => daemonCallWithResult('resolve', params), resolve: params => daemonCallWithResult('resolve', params),
get: params => daemonCallWithResult('get', params), get: params => daemonCallWithResult('get', params),
publish: params => daemonCallWithResult('publish', params),
claim_search: params => daemonCallWithResult('claim_search', params), claim_search: params => daemonCallWithResult('claim_search', params),
claim_list: params => daemonCallWithResult('claim_list', params), claim_list: params => daemonCallWithResult('claim_list', params),
channel_create: params => daemonCallWithResult('channel_create', params), channel_create: params => daemonCallWithResult('channel_create', params),
@ -814,6 +822,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) { function checkAndParse(response) {
if (response.status >= 200 && response.status < 300) { if (response.status >= 200 && response.status < 300) {
return response.json(); return response.json();
@ -3289,7 +3305,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) { if (status.disabled) {
throw Error(); throw Error();
} }
@ -3320,7 +3336,7 @@ const doUpdatePublishForm = publishFormValue => dispatch => dispatch({
data: _extends$5({}, publishFormValue) 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; let thumbnail, fileExt, fileName, fileType;
const makeid = () => { const makeid = () => {
@ -3358,7 +3374,7 @@ const doUploadThumbnail = (filePath, thumbnailBuffer, fsAdapter, fs, path) => di
// $FlowFixMe // $FlowFixMe
data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName }); data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName });
return fetch('https://spee.ch/api/claim/publish', { return fetch(SPEECH_PUBLISH, {
method: 'POST', method: 'POST',
body: data body: data
}).then(response => response.json()).then(json => json.success ? dispatch({ }).then(response => response.json()).then(json => json.success ? dispatch({
@ -3370,27 +3386,26 @@ const doUploadThumbnail = (filePath, thumbnailBuffer, fsAdapter, fs, path) => di
}) : uploadError(json.message)).catch(err => uploadError(err.message)); }) : uploadError(json.message)).catch(err => uploadError(err.message));
}); });
} else { } else {
if (filePath) { if (filePath && fs && path) {
thumbnail = fs.readFileSync(filePath); thumbnail = fs.readFileSync(filePath);
fileExt = path.extname(filePath); fileExt = path.extname(filePath);
fileName = path.basename(filePath); fileName = path.basename(filePath);
fileType = `image/${fileExt.slice(1)}`; fileType = `image/${fileExt.slice(1)}`;
} else if (thumbnailBuffer) { } else if (thumbnailBlob) {
thumbnail = thumbnailBuffer; fileExt = `.${thumbnailBlob.type && thumbnailBlob.type.split('/')[1]}`;
fileExt = '.png'; fileName = thumbnailBlob.name;
fileName = 'thumbnail.png'; fileType = thumbnailBlob.type;
fileType = 'image/png';
} else { } else {
return null; return null;
} }
const data = new FormData(); const data = new FormData();
const name = makeid(); 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('name', name);
data.append('file', file); data.append('file', file);
return fetch('https://spee.ch/api/claim/publish', { return fetch(SPEECH_PUBLISH, {
method: 'POST', method: 'POST',
body: data body: data
}).then(response => response.json()).then(json => json.success ? dispatch({ }).then(response => response.json()).then(json => json.success ? dispatch({
@ -5268,6 +5283,7 @@ exports.SEARCH_OPTIONS = SEARCH_OPTIONS;
exports.SEARCH_TYPES = SEARCH_TYPES; exports.SEARCH_TYPES = SEARCH_TYPES;
exports.SETTINGS = settings; exports.SETTINGS = settings;
exports.SORT_OPTIONS = sort_options; exports.SORT_OPTIONS = sort_options;
exports.SPEECH_URLS = speech_urls;
exports.THUMBNAIL_STATUSES = thumbnail_upload_statuses; exports.THUMBNAIL_STATUSES = thumbnail_upload_statuses;
exports.TRANSACTIONS = transaction_types; exports.TRANSACTIONS = transaction_types;
exports.TX_LIST = transaction_list; exports.TX_LIST = transaction_list;

View file

@ -168,7 +168,7 @@ declare type LbryTypes = {
version: () => Promise<VersionResponse>, version: () => Promise<VersionResponse>,
resolve: (params: {}) => Promise<ResolveResponse>, resolve: (params: {}) => Promise<ResolveResponse>,
get: (params: {}) => Promise<GetResponse>, get: (params: {}) => Promise<GetResponse>,
publish: (params: {}) => Promise<PublishResponse>, publish?: (params: {}) => Promise<PublishResponse>,
claim_search: (params: {}) => Promise<ClaimSearchResponse>, claim_search: (params: {}) => Promise<ClaimSearchResponse>,
claim_list: (params?: {}) => Promise<ClaimListResponse>, claim_list: (params?: {}) => Promise<ClaimListResponse>,

2
flow-typed/Lbry.js vendored
View file

@ -168,7 +168,7 @@ declare type LbryTypes = {
version: () => Promise<VersionResponse>, version: () => Promise<VersionResponse>,
resolve: (params: {}) => Promise<ResolveResponse>, resolve: (params: {}) => Promise<ResolveResponse>,
get: (params: {}) => Promise<GetResponse>, get: (params: {}) => Promise<GetResponse>,
publish: (params: {}) => Promise<PublishResponse>, publish?: (params: {}) => Promise<PublishResponse>,
claim_search: (params: {}) => Promise<ClaimSearchResponse>, claim_search: (params: {}) => Promise<ClaimSearchResponse>,
claim_list: (params?: {}) => Promise<ClaimListResponse>, claim_list: (params?: {}) => Promise<ClaimListResponse>,

View file

@ -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';
kauffj commented 2019-09-27 19:20:32 +02:00 (Migrated from github.com)
Review

👏 good change

:clap: good change

View file

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

View file

@ -30,6 +30,7 @@ const Lbry: LbryTypes = {
setOverride: (methodName, newMethod) => { setOverride: (methodName, newMethod) => {
Lbry.overrides[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 // 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) => { getMediaType: (contentType?: string, fileName: ?string) => {
@ -74,7 +75,6 @@ const Lbry: LbryTypes = {
// Claim fetching and manipulation // Claim fetching and manipulation
resolve: params => daemonCallWithResult('resolve', params), resolve: params => daemonCallWithResult('resolve', params),
get: params => daemonCallWithResult('get', params), get: params => daemonCallWithResult('get', params),
publish: params => daemonCallWithResult('publish', params),
claim_search: params => daemonCallWithResult('claim_search', params), claim_search: params => daemonCallWithResult('claim_search', params),
claim_list: params => daemonCallWithResult('claim_list', params), claim_list: params => daemonCallWithResult('claim_list', params),
channel_create: params => daemonCallWithResult('channel_create', 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) { function checkAndParse(response) {
if (response.status >= 200 && response.status < 300) { if (response.status >= 200 && response.status < 300) {
kauffj commented 2019-09-27 19:24:49 +02:00 (Migrated from github.com)
Review

lbry-redux should not know about lbry.tv

I would find any of the following preferable:

  • A distinct method call for publishing, separate from apiCall, that has a parameter for local vs. remote (or a boolean for whether to post the file, or equivalent).
  • An @if TARGET statement by-passing the traditional publish call to so something special for lbry.tv directly in lbry-desktop
lbry-redux should not know about lbry.tv I would find any of the following preferable: - A distinct method call for publishing, separate from `apiCall`, that has a parameter for local vs. remote (or a boolean for whether to post the file, or equivalent). - An `@if TARGET` statement by-passing the traditional publish call to so something special for lbry.tv directly in `lbry-desktop`
kauffj commented 2019-09-27 19:25:20 +02:00 (Migrated from github.com)
Review

this is a magic condition

this is a magic condition
kauffj commented 2019-09-27 19:25:41 +02:00 (Migrated from github.com)
Review

I believe x-lbry-auth-token should not be allowed in lbry-redux

I believe `x-lbry-auth-token` should not be allowed in lbry-redux
return response.json(); return response.json();

View file

@ -1,5 +1,6 @@
// @flow // @flow
import { CC_LICENSES, COPYRIGHT, OTHER, NONE, PUBLIC_DOMAIN } from 'constants/licenses'; 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 ACTIONS from 'constants/action_types';
import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses'; import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses';
import Lbry from 'lbry'; 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(res => res.json())
.then(status => { .then(status => {
if (status.disabled) { if (status.disabled) {
@ -62,11 +63,11 @@ export const doUpdatePublishForm = (publishFormValue: UpdatePublishFormData) =>
}); });
export const doUploadThumbnail = ( export const doUploadThumbnail = (
filePath: string, filePath?: string,
thumbnailBuffer: Uint8Array, thumbnailBlob?: File,
fsAdapter: any, fsAdapter?: any,
fs: any, fs?: any,
path: any path?: any
) => (dispatch: Dispatch) => { ) => (dispatch: Dispatch) => {
let thumbnail, fileExt, fileName, fileType; let thumbnail, fileExt, fileName, fileType;
@ -110,7 +111,7 @@ export const doUploadThumbnail = (
// $FlowFixMe // $FlowFixMe
data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName }); data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName });
return fetch('https://spee.ch/api/claim/publish', { return fetch(SPEECH_PUBLISH, {
method: 'POST', method: 'POST',
body: data, body: data,
}) })
@ -129,27 +130,26 @@ export const doUploadThumbnail = (
.catch(err => uploadError(err.message)); .catch(err => uploadError(err.message));
}); });
} else { } else {
if (filePath) { if (filePath && fs && path) {
thumbnail = fs.readFileSync(filePath); thumbnail = fs.readFileSync(filePath);
fileExt = path.extname(filePath); fileExt = path.extname(filePath);
fileName = path.basename(filePath); fileName = path.basename(filePath);
fileType = `image/${fileExt.slice(1)}`; fileType = `image/${fileExt.slice(1)}`;
} else if (thumbnailBuffer) { } else if (thumbnailBlob) {
thumbnail = thumbnailBuffer; fileExt = `.${thumbnailBlob.type && thumbnailBlob.type.split('/')[1]}`;
fileExt = '.png'; fileName = thumbnailBlob.name;
fileName = 'thumbnail.png'; fileType = thumbnailBlob.type;
fileType = 'image/png';
} else { } else {
return null; return null;
} }
const data = new FormData(); const data = new FormData();
const name = makeid(); 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('name', name);
data.append('file', file); data.append('file', file);
return fetch('https://spee.ch/api/claim/publish', { return fetch(SPEECH_PUBLISH, {
method: 'POST', method: 'POST',
body: data, body: data,
}) })