add oEmbed support #546

Merged
bones7242 merged 16 commits from 358-oEmbed into master 2018-07-31 19:38:16 +02:00
16 changed files with 318 additions and 16 deletions

View file

@ -80,3 +80,21 @@ Issues with lbry (e.g. the spee.ch wallet, lbrynet configuration, etc.) that req
* client
* [react](https://reactjs.org/)
### URL formats
Below is a list of all possible urls for the content on spee.ch
* controlling, free `LBRY` claim
* spee.ch/claim (show)
* spee.ch/claim.ext (serve)
* specific `LBRY` claim
* spee.ch/claim_id/claim
* spee.ch/claim_id/claim.ext
* all free contents for the controlling `LBRY` channel
* spee.ch/@channel
* a specific `LBRY` channel
* spee.ch/@channel:channel_id
* a specific claim within the controlling `LBRY` channel
* spee.ch/@channel/claim (show)
* spee.ch/@channel/claim.ext (serve)
* a specific claim within a specific `LBRY` channel
* spee.ch/@channel:channel_id/claim
* spee.ch/@channel:channel_id/claim.ext

View file

@ -11,10 +11,14 @@ var _reactHelmet = _interopRequireDefault(require("react-helmet"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _siteConfig = _interopRequireDefault(require("@config/siteConfig.json"));
var _createPageTitle = _interopRequireDefault(require("../../utils/createPageTitle"));
var _createMetaTags = _interopRequireDefault(require("../../utils/createMetaTags"));
var _oEmbed = _interopRequireDefault(require("../../utils/oEmbed.js"));
var _createCanonicalLink = _interopRequireDefault(require("../../utils/createCanonicalLink"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@ -37,6 +41,8 @@ function _assertThisInitialized(self) { if (self === void 0) { throw new Referen
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); }
var host = _siteConfig.default.details.host;
var SEO =
/*#__PURE__*/
function (_React$Component) {
@ -61,15 +67,15 @@ function (_React$Component) {
asset: asset,
channel: channel
});
var canonicalLink = (0, _createCanonicalLink.default)(asset, channel, pageUri); // render results
var cannonicalLink = (0, _createCanonicalLink.default)(asset, channel, pageUri); // render results
return _react.default.createElement(_reactHelmet.default, {
title: pageTitle,
meta: metaTags,
link: [{
rel: 'canonical',
href: canonicalLink
}]
href: cannonicalLink
}, _oEmbed.default.json(host, cannonicalLink)]
});
}
}]);
@ -79,7 +85,6 @@ function (_React$Component) {
return SEO;
}(_react.default.Component);
;
SEO.propTypes = {
pageTitle: _propTypes.default.string,
pageUri: _propTypes.default.string,

View file

@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var rel = 'alternate';
var title = 'spee.ch oEmbed profile';
var formatUrlForQuery = function formatUrlForQuery(url) {
return url.replace(/\//g, '%2F').replace(/:/g, '%3A');
};
var createJsonLinkData = function createJsonLinkData(host, canonicalUrl) {
return {
rel: rel,
type: 'application/json+oembed',
href: "".concat(host, "/api/oembed?url=").concat(formatUrlForQuery(canonicalUrl), "%2F&format=json"),
title: title
};
};
var createXmlLinkData = function createXmlLinkData(host, canonicalUrl) {
return {
rel: rel,
type: 'application/xml+oembed',
href: "".concat(host, "/api/oembed?url=").concat(formatUrlForQuery(canonicalUrl), "%2F&format=xml"),
title: title
};
};
var _default = {
json: createJsonLinkData,
xml: createXmlLinkData
};
exports.default = _default;

View file

@ -2,10 +2,14 @@ import React from 'react';
import Helmet from 'react-helmet';
import PropTypes from 'prop-types';
import siteConfig from '@config/siteConfig.json';
import createPageTitle from '../../utils/createPageTitle';
import createMetaTags from '../../utils/createMetaTags';
import oEmbed from '../../utils/oEmbed.js';
import createCanonicalLink from '../../utils/createCanonicalLink';
const { details: { host } } = siteConfig;
class SEO extends React.Component {
render () {
// props from parent
@ -17,17 +21,23 @@ class SEO extends React.Component {
asset,
channel,
});
const canonicalLink = createCanonicalLink(asset, channel, pageUri);
const cannonicalLink = createCanonicalLink(asset, channel, pageUri);
// render results
return (
<Helmet
title={pageTitle}
meta={metaTags}
link={[{rel: 'canonical', href: canonicalLink}]}
link={[
{
rel : 'canonical',
href: cannonicalLink,
},
oEmbed.json(host, cannonicalLink),
]}
/>
);
}
};
}
SEO.propTypes = {
pageTitle: PropTypes.string,

View file

@ -0,0 +1,29 @@
const rel = 'alternate';
const title = 'spee.ch oEmbed profile';
const formatUrlForQuery = (url) => {
return url.replace(/\//g, '%2F').replace(/:/g, '%3A');
};
const createJsonLinkData = (host, canonicalUrl) => {
return {
rel,
type: 'application/json+oembed',
href: `${host}/api/oembed?url=${formatUrlForQuery(canonicalUrl)}%2F&format=json`,
title,
};
};
const createXmlLinkData = (host, canonicalUrl) => {
return {
rel,
type: 'application/xml+oembed',
href: `${host}/api/oembed?url=${formatUrlForQuery(canonicalUrl)}%2F&format=xml`,
title,
};
};
export default {
json: createJsonLinkData,
xml : createXmlLinkData,
};

View file

@ -2,7 +2,7 @@ const db = require('../../../../models');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const getClaimId = require('./getClaimId.js');
const getClaimId = require('../../../utils/getClaimId.js');
const NO_CHANNEL = 'NO_CHANNEL';
const NO_CLAIM = 'NO_CLAIM';

View file

@ -0,0 +1,67 @@
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
const logger = require('winston');
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
const db = require('../../../models');
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
const getClaimId = require('../../utils/getClaimId');
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
const {
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
details: {
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
host,
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
title: siteTitle,
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
},
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
} = require('@config/siteConfig');
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
const getOEmbedDataForAsset = (channelName, channelClaimId, claimName, claimId) => {
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
let fileData, claimData;
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
let data = {
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
version : '1.0',
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
provider_name: siteTitle,
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
provider_url : host,
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
cache_age : 86400, // one day in seconds
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
};
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
return getClaimId(channelName, channelClaimId, claimName, claimId)
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
.then(fullClaimId => {
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
claimId = fullClaimId;
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
return db.Claim.findOne({
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
where: {
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
name : claimName,
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
claimId: fullClaimId,
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
},
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
});
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
})
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
.then(claimRecord => {
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
claimData = claimRecord.dataValues;
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
return db.Blocked.isNotBlocked(claimData.outpoint);
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
})
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
.then(() => {
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
return db.File.findOne({
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
where: {
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
name: claimName,
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
claimId,
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
},
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
});
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
})
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
.then(fileRecord => {
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
fileData = fileRecord.dataValues;
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
logger.debug('file data:', fileData);
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
const serveUrl = `${host}/${fileData.claimId}/${fileData.name}.${fileData.fileType.substring(fileData.fileType.indexOf('/') + 1)}`;
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
// set the resource type
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
if (fileData.fileType === 'video/mp4') {
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
data['type'] = 'video';
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
data['html'] = `<video width="100%" controls poster="${claimData.thumbnail}" src="${serveUrl}"/></video>`;
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
} else {
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
data['type'] = 'picture';
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
data['url'] = serveUrl;
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
}
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
// get the data
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
data['title'] = claimData.title;
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
data['width'] = fileData.width || 600;
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
data['height'] = fileData.height || 400;
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
data['author_name'] = siteTitle;
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
data['author_url'] = host;
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
})
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
.then(() => {
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
return data;
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
});
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
};
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.
module.exports = getOEmbedDataForAsset;
skhameneh commented 2018-07-31 17:09:56 +02:00 (Migrated from github.com)
Review

Do you have configs for the host URL generation?
That would be ideal over hardcoding

Do you have configs for the host URL generation? That would be ideal over hardcoding
bones7242 commented 2018-07-31 18:24:46 +02:00 (Migrated from github.com)
Review

good catch. I meant to do this after testing and forgot.

good catch. I meant to do this after testing and forgot.

View file

@ -0,0 +1,33 @@
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
const db = require('../../../models');
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
const {
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
details: {
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
host,
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
title: siteTitle,
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
},
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
} = require('@config/siteConfig');
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
const getOEmbedDataForChannel = (channelName, channelClaimId) => {
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
return db.Certificate
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
.findOne({
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
where: {
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
name : channelName,
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
claimId: channelClaimId,
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
},
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
})
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
.then(certificateRecord => {
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
const certificateData = certificateRecord.dataValues;
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
return {
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
version : 1.0,
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
provider_name: siteTitle,
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
provider_url : host,
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
type : 'link',
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
author_name : certificateData.name,
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
title : `${certificateData.name}'s channel on Spee.ch`,
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
author_url : `${host}/${certificateData.name}:${certificateData.claimId}`,
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
cache_age : 86400, // one day in seconds
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
};
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
});
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
};
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding
module.exports = getOEmbedDataForChannel;
skhameneh commented 2018-07-31 17:10:34 +02:00 (Migrated from github.com)
Review

Same, use config instead of hard-coding

Same, use config instead of hard-coding

View file

@ -0,0 +1,68 @@
const logger = require('winston');
const lbryUri = require('../../utils/lbryUri');
const getOEmbedDataForChannel = require('./getOEmbedDataForChannel');
const getOEmbedDataForAsset = require('./getOEmbedDataForAsset');
const parseSpeechUrl = require('./parseSpeechUrl');
const getOEmbedData = (req, res) => {
const { query: { url, format } } = req;
logger.debug('req url', url);
logger.debug('req format', format);
const { paramOne, paramTwo } = parseSpeechUrl(url);
let claimName, isChannel, channelName, channelClaimId, claimId;
if (paramTwo) {
({ isChannel, channelName, channelClaimId, claimId } = lbryUri.parseIdentifier(paramOne));
({ claimName } = lbryUri.parseClaim(paramTwo));
} else {
({ isChannel, channelName, channelClaimId } = lbryUri.parseIdentifier(paramOne));
if (!isChannel ) {
({ claimName } = lbryUri.parseClaim(paramOne));
}
}
if (isChannel && !paramTwo) {
getOEmbedDataForChannel(channelName, channelClaimId)
.then(data => {
if (format === 'xml'){
return res.status(503).json({
success: false,
message: 'xml format is not implemented yet',
})
} else {
return res.status(200).json(data);
}
})
.catch((error) => {
return res.status(404).json({
success: false,
message: error,
});
})
} else {
getOEmbedDataForAsset(channelName, channelClaimId, claimName, claimId)
.then(data => {
if (format === 'xml'){
return res.status(503).json({
success: false,
message: 'xml format is not implemented yet',
})
} else {
return res.status(200).json(data);
}
})
.catch((error) => {
return res.status(404).json({
success: false,
message: error,
});
})
}
};
module.exports = getOEmbedData;

View file

@ -0,0 +1,24 @@
const logger = require('winston');
const parseSpeechUrl = (url) => {
const componentsRegex = new RegExp(
'([^:/?#]+://)' +
'([^/?#]*)' +
'(/)' +
'([^/?#]*)' +
'(/)' +
'([^/?#]*)'
);
const [, , , , paramOne, , paramTwo] = componentsRegex
.exec(url)
.map(match => match || null);
logger.debug(`params from speech url: ${paramOne} ${paramTwo}`);
return {
paramOne,
paramTwo,
};
};
module.exports = parseSpeechUrl;

View file

@ -3,7 +3,7 @@ const logger = require('winston');
const { sendGAServeEvent } = require('../../../utils/googleAnalytics');
const handleShowRender = require('../../../render/build/handleShowRender.js');
const lbryUri = require('../utils/lbryUri.js');
const lbryUri = require('../../utils/lbryUri.js');
const determineRequestType = require('../utils/determineRequestType.js');
const getClaimIdAndServeAsset = require('../utils/getClaimIdAndServeAsset.js');
@ -36,6 +36,7 @@ const serveByClaim = (req, res) => {
({ claimName } = lbryUri.parseClaim(params.claim));
logger.debug('serve request:', { headers, ip, originalUrl, params });
getClaimIdAndServeAsset(null, null, claimName, null, originalUrl, ip, res);
sendGAServeEvent(headers, ip, originalUrl);

View file

@ -3,7 +3,7 @@ const logger = require('winston');
const { sendGAServeEvent } = require('../../../utils/googleAnalytics');
const handleShowRender = require('../../../render/build/handleShowRender.js');
const lbryUri = require('../utils/lbryUri.js');
const lbryUri = require('../../utils/lbryUri.js');
const determineRequestType = require('../utils/determineRequestType.js');
const getClaimIdAndServeAsset = require('../utils/getClaimIdAndServeAsset.js');
@ -37,6 +37,7 @@ const serverByIdentifierAndClaim = (req, res) => {
}
logger.debug('serve request:', { headers, ip, originalUrl, params });
getClaimIdAndServeAsset(channelName, channelClaimId, claimName, claimId, originalUrl, ip, res);
sendGAServeEvent(headers, ip, originalUrl);

View file

@ -2,10 +2,9 @@ const logger = require('winston');
const db = require('../../../models');
const getClaimId = require('../../api/claim/longId/getClaimId.js');
const getClaimId = require('../../utils/getClaimId.js');
const { handleErrorResponse } = require('../../utils/errorHandlers.js');
const getLocalFileRecord = require('./getLocalFileRecord.js');
const serveFile = require('./serveFile.js');
const NO_CHANNEL = 'NO_CHANNEL';
@ -25,10 +24,18 @@ const getClaimIdAndServeAsset = (channelName, channelClaimId, claimName, claimId
return db.Blocked.isNotBlocked(outpoint);
})
.then(() => {
return getLocalFileRecord(claimId, claimName);
return db.File.findOne({
where: {
claimId,
name: claimName,
},
});
})
.then(fileRecord => {
serveFile(fileRecord, res);
if (!fileRecord) {
throw NO_FILE;
}
serveFile(fileRecord.dataValues, res);
})
.catch(error => {
if (error === NO_CLAIM) {
@ -53,7 +60,7 @@ const getClaimIdAndServeAsset = (channelName, channelClaimId, claimName, claimId
});
}
if (error === NO_FILE) {
logger.debug('claim was blocked');
logger.debug('no file available');
return res.status(307).redirect(`/api/claim/get/${name}/${claimId}`);
}
handleErrorResponse(originalUrl, ip, error, res);

View file

@ -1,6 +1,6 @@
const logger = require('winston');
const db = require('../../../../models');
const db = require('../../models/index');
const getClaimIdByChannel = (channelName, channelClaimId, claimName) => {
return new Promise((resolve, reject) => {

View file

@ -19,6 +19,7 @@ const userPassword = require('../../controllers/api/user/password');
const publishingConfig = require('../../controllers/api/config/site/publishing');
const getTorList = require('../../controllers/api/tor');
const getBlockedList = require('../../controllers/api/blocked');
const getOEmbedData = require('../../controllers/api/oEmbed');
module.exports = (app) => {
@ -46,4 +47,6 @@ module.exports = (app) => {
app.get('/api/tor', torCheckMiddleware, getTorList);
// blocked
app.get('/api/blocked', torCheckMiddleware, getBlockedList);
// open embed
app.get('/api/oembed', torCheckMiddleware, getOEmbedData)
};