Fix chainquery bugs and add initial metrics implementation

This commit is contained in:
Shawn 2018-10-08 19:02:05 -05:00
parent 580ca10a8e
commit 860c61dc47
28 changed files with 599 additions and 187 deletions

View file

@ -12,6 +12,16 @@ export function onHandleShowPageUri (params, url) {
};
}
export function onHandleShowHomepage (params, url) {
return {
type: actions.HANDLE_SHOW_HOMEPAGE,
data: {
...params,
url,
}
};
}
export function onRequestError (error) {
return {
type: actions.REQUEST_ERROR,

View file

@ -0,0 +1,6 @@
import Request from '../utils/request';
export function getHomepageChannelsData (host, name, id) {
const url = `${host}/api/homepage/data/channels`;
return Request(url);
}

View file

@ -1,5 +1,6 @@
// request actions
export const HANDLE_SHOW_URI = 'HANDLE_SHOW_URI';
export const HANDLE_SHOW_HOMEPAGE = 'HANDLE_SHOW_HOMEPAGE';
export const REQUEST_ERROR = 'REQUEST_ERROR';
export const REQUEST_UPDATE = 'REQUEST_UPDATE';
export const ASSET_REQUEST_NEW = 'ASSET_REQUEST_NEW';

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { onHandleShowPageUri } from '../../actions/show';
import { onHandleShowHomepage } from '../../actions/show';
import View from './view';
const mapStateToProps = ({ show }) => {
@ -10,7 +10,7 @@ const mapStateToProps = ({ show }) => {
};
const mapDispatchToProps = {
onHandleShowPageUri,
onHandleShowHomepage,
};
export default connect(mapStateToProps, mapDispatchToProps)(View);

View file

@ -4,6 +4,16 @@ import PageLayout from '@components/PageLayout';
import PublishTool from '@containers/PublishTool';
class HomePage extends React.Component {
componentDidMount () {
this.props.onHandleShowHomepage(this.props.match.params);
}
componentWillReceiveProps (nextProps) {
if (nextProps.match.params !== this.props.match.params) {
this.props.onHandleShowHomepage(nextProps.match.params);
}
}
render () {
return (
<PageLayout

View file

@ -1,5 +1,5 @@
import { all } from 'redux-saga/effects';
import { watchHandleShowPageUri } from './show_uri';
import { watchHandleShowPageUri, watchHandleShowHomepage } from './show_uri';
import { watchNewAssetRequest } from './show_asset';
import { watchNewChannelRequest, watchUpdateChannelClaims } from './show_channel';
import { watchFileIsRequested } from './file';
@ -13,6 +13,7 @@ import { watchChannelLogout } from './logoutChannel';
export function * rootSaga () {
yield all([
watchHandleShowPageUri(),
watchHandleShowHomepage(),
watchNewAssetRequest(),
watchNewChannelRequest(),
watchUpdateChannelClaims(),

View file

@ -56,6 +56,19 @@ export function * handleShowPageUri (action) {
}
};
export function * handleShowPageHomepage (action) {
const { identifier, claim } = action.data;
if (identifier) {
return yield call(parseAndUpdateIdentifierAndClaim, identifier, claim);
} else if (claim) {
yield call(parseAndUpdateClaimOnly, claim);
}
};
export function * watchHandleShowPageUri () {
yield takeLatest(actions.HANDLE_SHOW_URI, handleShowPageUri);
};
export function * watchHandleShowHomepage () {
yield takeLatest(actions.HANDLE_SHOW_HOMEPAGE, handleShowPageHomepage);
};

140
package-lock.json generated
View file

@ -6400,6 +6400,23 @@
"buffer-alloc": "1.2.0"
}
},
"isemail": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/isemail/-/isemail-3.1.3.tgz",
"integrity": "sha512-5xbsG5wYADIcB+mfLsd+nst1V/D+I7EU7LEZPo2GOIMu4JzfcRs5yQoypP4avA7QtUqgxYLKBYNv4IdzBmbhdw==",
"dev": true,
"requires": {
"punycode": "2.1.1"
},
"dependencies": {
"punycode": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==",
"dev": true
}
}
},
"isexe": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
@ -6424,6 +6441,25 @@
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
},
"joi": {
"version": "13.7.0",
"resolved": "https://registry.npmjs.org/joi/-/joi-13.7.0.tgz",
"integrity": "sha512-xuY5VkHfeOYK3Hdi91ulocfuFopwgbSORmIwzcwHKESQhC7w1kD5jaVSPnqDxS2I8t3RZ9omCKAxNwXN5zG1/Q==",
"dev": true,
"requires": {
"hoek": "5.0.4",
"isemail": "3.1.3",
"topo": "3.0.0"
},
"dependencies": {
"hoek": {
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/hoek/-/hoek-5.0.4.tgz",
"integrity": "sha512-Alr4ZQgoMlnere5FZJsIyfIjORBqZll5POhDsF4q64dPuJR6rNxXdDxtHSQq8OXRurhmx+PWYEE8bXRROY8h0w==",
"dev": true
}
}
},
"js-base64": {
"version": "2.4.9",
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.4.9.tgz",
@ -12088,6 +12124,12 @@
"is-promise": "2.1.0"
}
},
"rx": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/rx/-/rx-4.1.0.tgz",
"integrity": "sha1-pfE/957zt0D+MKqAP7CfmIBdR4I=",
"dev": true
},
"rx-lite": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz",
@ -13361,6 +13403,23 @@
"repeat-string": "1.6.1"
}
},
"topo": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/topo/-/topo-3.0.0.tgz",
"integrity": "sha512-Tlu1fGlR90iCdIPURqPiufqAlCZYzLjHYVVbcFWDMcX7+tK8hdZWAfsMrD/pBul9jqHHwFjNdf1WaxA9vTRRhw==",
"dev": true,
"requires": {
"hoek": "5.0.4"
},
"dependencies": {
"hoek": {
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/hoek/-/hoek-5.0.4.tgz",
"integrity": "sha512-Alr4ZQgoMlnere5FZJsIyfIjORBqZll5POhDsF4q64dPuJR6rNxXdDxtHSQq8OXRurhmx+PWYEE8bXRROY8h0w==",
"dev": true
}
}
},
"toposort-class": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/toposort-class/-/toposort-class-1.0.1.tgz",
@ -13947,6 +14006,87 @@
"indexof": "0.0.1"
}
},
"wait-on": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/wait-on/-/wait-on-3.1.0.tgz",
"integrity": "sha512-yjYwMvnOhA3PTghvzPQAmT2TSVvBMbOdBRRjMPfBD6FU5si/PkAsI8P3X5sh9ntkYjZvPQLpQRpDUyax5h4COg==",
"dev": true,
"requires": {
"core-js": "2.5.7",
"joi": "13.7.0",
"minimist": "1.2.0",
"request": "2.88.0",
"rx": "4.1.0"
},
"dependencies": {
"core-js": {
"version": "2.5.7",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.7.tgz",
"integrity": "sha512-RszJCAxg/PP6uzXVXL6BsxSXx/B05oJAQ2vkJRjyjrEcNVycaqOmNb5OTxZPE3xa5gwZduqza6L9JOCenh/Ecw==",
"dev": true
},
"har-validator": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.0.tgz",
"integrity": "sha512-+qnmNjI4OfH2ipQ9VQOw23bBd/ibtfbVdK2fYbY4acTDqKTW/YDp9McimZdDbG8iV9fZizUqQMD5xvriB146TA==",
"dev": true,
"requires": {
"ajv": "5.5.2",
"har-schema": "2.0.0"
}
},
"minimist": {
"version": "1.2.0",
"resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
"dev": true
},
"oauth-sign": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
"integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==",
"dev": true
},
"request": {
"version": "2.88.0",
"resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz",
"integrity": "sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==",
"dev": true,
"requires": {
"aws-sign2": "0.7.0",
"aws4": "1.8.0",
"caseless": "0.12.0",
"combined-stream": "1.0.6",
"extend": "3.0.2",
"forever-agent": "0.6.1",
"form-data": "2.3.2",
"har-validator": "5.1.0",
"http-signature": "1.2.0",
"is-typedarray": "1.0.0",
"isstream": "0.1.2",
"json-stringify-safe": "5.0.1",
"mime-types": "2.1.20",
"oauth-sign": "0.9.0",
"performance-now": "2.1.0",
"qs": "6.5.2",
"safe-buffer": "5.1.2",
"tough-cookie": "2.4.3",
"tunnel-agent": "0.6.0",
"uuid": "3.3.2"
}
},
"tough-cookie": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz",
"integrity": "sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ==",
"dev": true,
"requires": {
"psl": "1.1.29",
"punycode": "1.4.1"
}
}
}
},
"warning": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/warning/-/warning-4.0.2.tgz",

View file

@ -122,6 +122,7 @@
"sass-loader": "^7.1.0",
"sequelize-cli": "^4.0.0",
"style-loader": "^0.21.0",
"url-loader": "^1.0.1"
"url-loader": "^1.0.1",
"wait-on": "^3.1.0"
}
}

View file

@ -1,7 +1,12 @@
'use strict';
var AbnormalClaimModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'abnormal_claim',
{
@ -19,7 +24,7 @@ var AbnormalClaimModel = (sequelize, {
set() { },
},
is_update: {
type: INTEGER,
type: BOOLEAN,
set() { },
},
block_hash: {
@ -47,11 +52,11 @@ var AbnormalClaimModel = (sequelize, {
set() { },
},
created_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
},
@ -73,7 +78,12 @@ var abnormalClaimTable = {
};
var AddressModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'address',
{
@ -87,15 +97,15 @@ var AddressModel = (sequelize, {
set() { },
},
first_seen: {
type: INTEGER,
type: DATE(6),
set() { },
},
created_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
},
@ -117,7 +127,12 @@ var addressTable = {
};
var BlockModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'block',
{
@ -195,11 +210,11 @@ var BlockModel = (sequelize, {
set() { },
},
created_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
},
@ -257,7 +272,12 @@ const getterMethods$3 = {
};
var ClaimModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'claim',
{
@ -310,14 +330,6 @@ var ClaimModel = (sequelize, {
type: STRING,
set() { },
},
value_as_hex: {
type: STRING,
set() { },
},
value_as_json: {
type: STRING,
set() { },
},
valid_at_height: {
type: INTEGER,
set() { },
@ -343,7 +355,7 @@ var ClaimModel = (sequelize, {
set() { },
},
is_nsfw: {
type: INTEGER,
type: BOOLEAN,
set() { },
},
language: {
@ -367,7 +379,7 @@ var ClaimModel = (sequelize, {
set() { },
},
is_filtered: {
type: INTEGER,
type: BOOLEAN,
set() { },
},
bid_state: {
@ -375,11 +387,11 @@ var ClaimModel = (sequelize, {
set() { },
},
created_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
fee_address: {
@ -409,7 +421,12 @@ var claimTable = {
};
var InputModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'input',
{
@ -431,7 +448,7 @@ var InputModel = (sequelize, {
set() { },
},
is_coinbase: {
type: INTEGER,
type: BOOLEAN,
set() { },
},
coinbase: {
@ -443,7 +460,7 @@ var InputModel = (sequelize, {
set() { },
},
prevout_n: {
type: INTEGER,
type: INTEGER.UNSIGNED,
set() { },
},
prevout_spend_updated: {
@ -467,11 +484,11 @@ var InputModel = (sequelize, {
set() { },
},
created: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified: {
type: INTEGER,
type: DATE(6),
set() { },
},
},
@ -493,7 +510,12 @@ var inputTable = {
};
var OutputModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'output',
{
@ -539,7 +561,7 @@ var OutputModel = (sequelize, {
set() { },
},
is_spent: {
type: INTEGER,
type: BOOLEAN,
set() { },
},
spent_by_input_id: {
@ -547,11 +569,11 @@ var OutputModel = (sequelize, {
set() { },
},
created_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
claim_id: {
@ -577,7 +599,12 @@ var outputTable = {
};
var SupportModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'support',
{
@ -607,11 +634,11 @@ var SupportModel = (sequelize, {
set() { },
},
created_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
},
@ -633,7 +660,12 @@ var supportTable = {
};
var TransactionAddressModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'transaction_address',
{
@ -674,7 +706,12 @@ var transactionAddressTable = {
};
var TransactionModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'transaction',
{
@ -716,7 +753,7 @@ var TransactionModel = (sequelize, {
set() { },
},
lock_time: {
type: INTEGER,
type: DATE(6),
set() { },
},
raw: {
@ -724,15 +761,15 @@ var TransactionModel = (sequelize, {
set() { },
},
created_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
created_time: {
type: INTEGER,
type: DATE(6),
set() {},
},
},
@ -820,7 +857,7 @@ var claimQueries = (db, table) => ({
return await table.findAll({
where: { publisher_id: channelClaimId },
order: [['height', 'DESC']],
raw : true, // returns an array of only data, not an array of instances
raw : false, // returns an array of only data, not an array of instances
})
.then(channelClaimsArray => {
if(channelClaimsArray.length === 0) {

View file

@ -1,7 +1,12 @@
'use strict';
var AbnormalClaimModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'abnormal_claim',
{
@ -19,7 +24,7 @@ var AbnormalClaimModel = (sequelize, {
set() { },
},
is_update: {
type: INTEGER,
type: BOOLEAN,
set() { },
},
block_hash: {
@ -47,11 +52,11 @@ var AbnormalClaimModel = (sequelize, {
set() { },
},
created_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
},
@ -73,7 +78,12 @@ var abnormalClaimTable = {
};
var AddressModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'address',
{
@ -87,15 +97,15 @@ var AddressModel = (sequelize, {
set() { },
},
first_seen: {
type: INTEGER,
type: DATE(6),
set() { },
},
created_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
},
@ -117,7 +127,12 @@ var addressTable = {
};
var BlockModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'block',
{
@ -195,11 +210,11 @@ var BlockModel = (sequelize, {
set() { },
},
created_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
},
@ -257,7 +272,12 @@ const getterMethods$3 = {
};
var ClaimModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'claim',
{
@ -310,14 +330,6 @@ var ClaimModel = (sequelize, {
type: STRING,
set() { },
},
value_as_hex: {
type: STRING,
set() { },
},
value_as_json: {
type: STRING,
set() { },
},
valid_at_height: {
type: INTEGER,
set() { },
@ -343,7 +355,7 @@ var ClaimModel = (sequelize, {
set() { },
},
is_nsfw: {
type: INTEGER,
type: BOOLEAN,
set() { },
},
language: {
@ -367,7 +379,7 @@ var ClaimModel = (sequelize, {
set() { },
},
is_filtered: {
type: INTEGER,
type: BOOLEAN,
set() { },
},
bid_state: {
@ -375,11 +387,11 @@ var ClaimModel = (sequelize, {
set() { },
},
created_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
fee_address: {
@ -409,7 +421,12 @@ var claimTable = {
};
var InputModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'input',
{
@ -431,7 +448,7 @@ var InputModel = (sequelize, {
set() { },
},
is_coinbase: {
type: INTEGER,
type: BOOLEAN,
set() { },
},
coinbase: {
@ -443,7 +460,7 @@ var InputModel = (sequelize, {
set() { },
},
prevout_n: {
type: INTEGER,
type: INTEGER.UNSIGNED,
set() { },
},
prevout_spend_updated: {
@ -467,11 +484,11 @@ var InputModel = (sequelize, {
set() { },
},
created: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified: {
type: INTEGER,
type: DATE(6),
set() { },
},
},
@ -493,7 +510,12 @@ var inputTable = {
};
var OutputModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'output',
{
@ -539,7 +561,7 @@ var OutputModel = (sequelize, {
set() { },
},
is_spent: {
type: INTEGER,
type: BOOLEAN,
set() { },
},
spent_by_input_id: {
@ -547,11 +569,11 @@ var OutputModel = (sequelize, {
set() { },
},
created_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
claim_id: {
@ -577,7 +599,12 @@ var outputTable = {
};
var SupportModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'support',
{
@ -607,11 +634,11 @@ var SupportModel = (sequelize, {
set() { },
},
created_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
},
@ -633,7 +660,12 @@ var supportTable = {
};
var TransactionAddressModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'transaction_address',
{
@ -674,7 +706,12 @@ var transactionAddressTable = {
};
var TransactionModel = (sequelize, {
STRING, BOOLEAN, INTEGER, TEXT, DECIMAL
BOOLEAN,
DATE,
DECIMAL,
INTEGER,
STRING,
TEXT,
}) => sequelize.define(
'transaction',
{
@ -716,7 +753,7 @@ var TransactionModel = (sequelize, {
set() { },
},
lock_time: {
type: INTEGER,
type: DATE(6),
set() { },
},
raw: {
@ -724,15 +761,15 @@ var TransactionModel = (sequelize, {
set() { },
},
created_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
modified_at: {
type: INTEGER,
type: DATE(6),
set() { },
},
created_time: {
type: INTEGER,
type: DATE(6),
set() {},
},
},
@ -799,7 +836,7 @@ const isShortClaimId = (claimId) => {
return (claimId && (claimId.length < 40));
};
var claimQueries = (db, table) => ({
var claimQueries = (db, table, sequelize) => ({
getShortClaimIdFromLongClaimId: async (claimId, claimName) => {
logger$1.debug(`claim.getShortClaimIdFromLongClaimId for ${claimName}#${claimId}`);
@ -820,7 +857,6 @@ var claimQueries = (db, table) => ({
return await table.findAll({
where: { publisher_id: channelClaimId },
order: [['height', 'DESC']],
raw : true, // returns an array of only data, not an array of instances
})
.then(channelClaimsArray => {
if(channelClaimsArray.length === 0) {
@ -1025,7 +1061,7 @@ if (!database || !username || !password) {
}
// set sequelize options
const sequelize$1 = new Sequelize(database, username, password, {
const sequelize = new Sequelize(database, username, password, {
host : host$1,
import : port,
dialect : 'mysql',
@ -1049,8 +1085,8 @@ for(let i = 0; i < DATABASE_STRUCTURE_KEYS.length; i++) {
let dbKey = DATABASE_STRUCTURE_KEYS[i];
let currentData = DATABASE_STRUCTURE[dbKey];
db[dbKey] = currentData.table.createModel(sequelize$1, Sequelize);
db[dbKey].queries = currentData.queries(db, db[dbKey]);
db[dbKey] = currentData.table.createModel(sequelize, Sequelize);
db[dbKey].queries = currentData.queries(db, db[dbKey], sequelize);
}
// run model.association for each model in the db object that has an association
@ -1063,7 +1099,7 @@ DATABASE_STRUCTURE_KEYS.forEach(modelName => {
});
// establish mysql connection
sequelize$1
sequelize
.authenticate()
.then(() => {
logger$2.info('Sequelize has established mysql connection for chainquery successfully.');

View file

@ -98,7 +98,7 @@ for(let i = 0; i < DATABASE_STRUCTURE_KEYS.length; i++) {
let currentData = DATABASE_STRUCTURE[dbKey];
db[dbKey] = currentData.table.createModel(sequelize, Sequelize);
db[dbKey].queries = currentData.queries(db, db[dbKey]);
db[dbKey].queries = currentData.queries(db, db[dbKey], sequelize);
}
// run model.association for each model in the db object that has an association

View file

@ -93,14 +93,6 @@ export default (sequelize, {
type: STRING,
set() { },
},
value_as_hex: {
type: STRING,
set() { },
},
value_as_json: {
type: STRING,
set() { },
},
valid_at_height: {
type: INTEGER,
set() { },

View file

@ -32,7 +32,7 @@ const isShortClaimId = (claimId) => {
return (claimId && (claimId.length < 40));
}
export default (db, table) => ({
export default (db, table, sequelize) => ({
getShortClaimIdFromLongClaimId: async (claimId, claimName) => {
logger.debug(`claim.getShortClaimIdFromLongClaimId for ${claimName}#${claimId}`);
@ -53,7 +53,6 @@ export default (db, table) => ({
return await table.findAll({
where: { publisher_id: channelClaimId },
order: [['height', 'DESC']],
raw : true, // returns an array of only data, not an array of instances
})
.then(channelClaimsArray => {
if(channelClaimsArray.length === 0) {

View file

@ -13,7 +13,7 @@ const claimData = ({ ip, originalUrl, body, params }, res) => {
const claimName = params.claimName;
let claimId = params.claimId;
if (claimId === 'none') claimId = null;
chainquery.claim.queries.resolveClaim(claimName, claimId)
chainquery.claim.queries.resolveClaim(claimName, claimId).catch(() => {})
.then(claimInfo => {
if (!claimInfo) {
// Not found remote, try local
@ -28,6 +28,7 @@ const claimData = ({ ip, originalUrl, body, params }, res) => {
message: 'No claim could be found',
});
}
res.status(200).json({
success: true,
data : getClaimData(claimInfo),

View file

@ -4,6 +4,7 @@ const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const getClaimData = require('server/utils/getClaimData');
const chainquery = require('chainquery');
const db = require('../../../../models');
const waitOn = require('wait-on');
/*
@ -11,60 +12,46 @@ const db = require('../../../../models');
*/
const claimGet = ({ ip, originalUrl, params }, res) => {
const claimGet = async ({ ip, originalUrl, params }, res) => {
const name = params.name;
const claimId = params.claimId;
let resolveResult;
let getResult;
chainquery.claim.queries.resolveClaim(name, claimId)
.then(result => {
if (!result) {
// could not find remote, return false to try local
return false;
try {
let claimData = await chainquery.claim.queries.resolveClaim(name, claimId).catch(() => {});
if(!claimData) {
claimData = await db.Claim.resolveClaim(name, claimId);
}
return resolveResult = result;
})
.then(result => {
if (result === false) {
// Could not find remote, try local
return db.Claim.resolveClaim(name, claimId);
}
return result;
})
.then(result => {
if (!result) {
if(!claimData) {
throw new Error('No matching uri found in Claim table');
}
return resolveResult = result;
})
.then(result => getClaim(`${name}#${claimId}`))
.then(result => {
if (!result) {
let lbrynetResult = await getClaim(`${name}#${claimId}`);
if(!lbrynetResult) {
throw new Error(`Unable to Get ${name}#${claimId}`);
}
getResult = result;
if (result.completed) {
return createFileRecordDataAfterGet(getClaimData(resolveResult), getResult)
.then(fileData => {
let fileData = await createFileRecordDataAfterGet(getClaimData(claimData), lbrynetResult);
const upsertCriteria = { name, claimId };
return db.upsert(db.File, fileData, upsertCriteria, 'File');
await db.upsert(db.File, fileData, upsertCriteria, 'File');
try {
await waitOn({
resources: [ lbrynetResult.file_name ],
delay: 100,
timeout: 10000, // 10 seconds
});
}
})
.then(() => {
const { message, completed } = getResult;
} catch (e) {}
const { message, completed } = lbrynetResult;
res.status(200).json({
success: true,
message,
completed,
});
})
.catch(error => {
} catch(error) {
handleErrorResponse(originalUrl, ip, error, res);
});
}
};
module.exports = claimGet;

View file

@ -20,14 +20,15 @@ const claimLongId = ({ ip, originalUrl, body, params }, res) => {
const channelClaimId = body.channelClaimId;
const claimName = body.claimName;
let claimId = body.claimId;
getClaimId(channelName, channelClaimId, claimName, claimId)
.then(fullClaimId => {
claimId = fullClaimId;
return chainquery.claim.queries.getOutpoint(claimName, fullClaimId);
return chainquery.claim.queries.getOutpoint(claimName, fullClaimId).catch(() => {});
})
.then(outpointResult => {
if (!outpointResult) {
return db.Claim.getOutpoint(claimName, fullClaimId);
return db.Claim.getOutpoint(claimName, claimId);
}
return outpointResult;
})

View file

@ -1,5 +1,6 @@
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const db = require('../../../../models');
const chainquery = require('chainquery');
/*
@ -7,14 +8,18 @@ const db = require('../../../../models');
*/
const claimShortId = ({ ip, originalUrl, body, params }, res) => {
db.Claim.getShortClaimIdFromLongClaimId(params.longId, params.name)
.then(shortId => {
const claimShortId = async ({ ip, originalUrl, body, params }, res) => {
try {
let shortId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(params.longId, params.name);
if(shortId === null) {
shortId = await db.Claim.getShortClaimIdFromLongClaimId(params.longId, params.name);
}
res.status(200).json({success: true, data: shortId});
})
.catch(error => {
} catch(error) {
handleErrorResponse(originalUrl, ip, error, res);
});
}
};
module.exports = claimShortId;

View file

@ -0,0 +1,28 @@
const db = require('../../../../models');
const getChannelData = (channelName, channelClaimId) => {
return new Promise((resolve, reject) => {
let longChannelClaimId;
// 1. get the long channel Id (make sure channel exists)
db.Certificate
.getLongChannelId(channelName, channelClaimId)
.then(fullClaimId => {
longChannelClaimId = fullClaimId;
return db
.Certificate
.getShortChannelIdFromLongChannelId(fullClaimId, channelName);
})
.then(shortChannelClaimId => {
resolve({
channelName,
longChannelClaimId,
shortChannelClaimId,
});
})
.catch(error => {
reject(error);
});
});
};
module.exports = getChannelData;

View file

@ -0,0 +1,35 @@
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const getChannelData = require('./getChannelData.js');
const NO_CHANNEL = 'NO_CHANNEL';
/*
route to get data for a channel
*/
const channelData = ({ ip, originalUrl, body, params }, res) => {
const channelName = params.channelName;
let channelClaimId = params.channelClaimId;
if (channelClaimId === 'none') channelClaimId = null;
getChannelData(channelName, channelClaimId)
.then(data => {
res.status(200).json({
success: true,
data,
});
})
.catch(error => {
if (error === NO_CHANNEL) {
return res.status(404).json({
success: false,
message: 'No matching channel was found',
});
}
handleErrorResponse(originalUrl, ip, error, res);
});
};
module.exports = channelData;

View file

@ -1,6 +1,7 @@
const logger = require('winston');
const db = require('../../../models');
const chainquery = require('chainquery');
const getClaimId = require('../../utils/getClaimId.js');
const { handleErrorResponse } = require('../../utils/errorHandlers.js');
@ -16,8 +17,13 @@ const getClaimIdAndServeAsset = (channelName, channelClaimId, claimName, claimId
getClaimId(channelName, channelClaimId, claimName, claimId)
.then(fullClaimId => {
claimId = fullClaimId;
logger.debug('Full claim id:', fullClaimId);
return db.Claim.getOutpoint(claimName, fullClaimId);
return chainquery.claim.queries.getOutpoint(claimName, fullClaimId).catch(() => {});
})
.then(outpointResult => {
if (!outpointResult) {
return db.Claim.getOutpoint(claimName, claimId);
}
return outpointResult;
})
.then(outpoint => {
logger.debug('Outpoint:', outpoint);

View file

@ -1,22 +1,38 @@
const logger = require('winston');
const db = require('../../models');
const chainquery = require('chainquery');
const getClaimIdByChannel = (channelName, channelClaimId, claimName) => {
const getClaimIdByChannel = async (channelName, channelClaimId, claimName) => {
logger.debug(`getClaimIdByChannel(${channelName}, ${channelClaimId}, ${claimName})`);
return db.Certificate
.getLongChannelId(channelName, channelClaimId)
.then(longChannelId => {
return db.Claim.getClaimIdByLongChannelId(longChannelId, claimName);
});
let channelId = await chainquery.claim.queries.getLongClaimIdFromShortClaimId(channelName, channelClaimId);
if(channelId === null) {
channelId = await db.Certificate.getLongChannelId(channelName, channelClaimId);
}
let claimId = await chainquery.claim.queries.getClaimIdByLongChannelId(longChannelId, claimName);
if(claimId === null) {
claimId = db.Claim.getClaimIdByLongChannelId(longChannelId, claimName);
}
return claimId;
};
const getClaimId = (channelName, channelClaimId, name, claimId) => {
const getClaimId = async (channelName, channelClaimId, name, claimId) => {
logger.debug(`getClaimId: ${channelName}, ${channelClaimId}, ${name}, ${claimId})`);
if (channelName) {
return getClaimIdByChannel(channelName, channelClaimId, name);
return await getClaimIdByChannel(channelName, channelClaimId, name);
} else {
return db.Claim.getLongClaimId(name, claimId);
let claimIdResult = await chainquery.claim.queries.getLongClaimId(name, claimId);
if(claimIdResult === null) {
claimIdResult = await db.Claim.getLongClaimId(name, claimId);
}
return claimIdResult;
}
};

View file

@ -27,6 +27,25 @@ const {
},
} = require('@config/siteConfig');
function logMetricsMiddleware(req, res, next) {
res.on('finish', () => {
const userAgent = req.get('user-agent');
db.RequestMetrics.create({
isInternal: /node\-fetch/.test(userAgent),
routePath: httpContext.get('routePath'),
params: JSON.stringify(req.params),
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
request: req.url,
routeData: JSON.stringify(httpContext.get('routeData')),
referrer: req.get('referrer'),
userAgent,
});
});
next();
}
function setRouteDataInContextMiddleware(routePath, routeData) {
return function (req, res, next) {
httpContext.set('routePath', routePath);
@ -97,7 +116,12 @@ function Server () {
let routeMethod = routeData.hasOwnProperty('method') ? routeData.method : 'get';
let controllers = Array.isArray(routeData.controller) ? routeData.controller : [routeData.controller];
app[routeMethod](routePath, setRouteDataInContextMiddleware(routePath, routeData), ...controllers);
app[routeMethod](
routePath,
logMetricsMiddleware,
setRouteDataInContextMiddleware(routePath, routeData),
...controllers,
);
});
this.app = app;

View file

@ -1,13 +1,14 @@
const Sequelize = require('sequelize');
const logger = require('winston');
const Certificate = require('./certificate.js');
const Channel = require('./channel.js');
const Claim = require('./claim.js');
const File = require('./file.js');
const User = require('./user.js');
const Blocked = require('./blocked.js');
const Tor = require('./tor.js');
const Blocked = require('./blocked');
const Certificate = require('./certificate');
const Channel = require('./channel');
const Claim = require('./claim');
const File = require('./file');
const Metrics = require('./metrics');
const Tor = require('./tor');
const User = require('./user');
const {
database,
@ -48,13 +49,14 @@ sequelize
// manually add each model to the db object (note: make this dynamic)
const db = {};
db['Blocked'] = sequelize.import('Blocked', Blocked);
db['Certificate'] = sequelize.import('Certificate', Certificate);
db['Channel'] = sequelize.import('Channel', Channel);
db['Claim'] = sequelize.import('Claim', Claim);
db['File'] = sequelize.import('File', File);
db['User'] = sequelize.import('User', User);
db['Blocked'] = sequelize.import('Blocked', Blocked);
db['Metrics'] = sequelize.import('Metrics', Metrics);
db['Tor'] = sequelize.import('Tor', Tor);
db['User'] = sequelize.import('User', User);
// run model.association for each model in the db object that has an association
logger.info('associating db models...');

53
server/models/metrics.js Normal file
View file

@ -0,0 +1,53 @@
module.exports = (sequelize, { BOOLEAN, DATE, STRING }) => {
const RequestMetrics = sequelize.define(
'RequestMetrics',
{
time: {
type: DATE(6),
defaultValue: sequelize.NOW,
},
isInternal: {
type: BOOLEAN,
},
claimId: {
type: STRING,
defaultValue: null,
},
ip: {
type: STRING,
defaultValue: null,
},
request: {
type: STRING,
defaultValue: null,
},
userAgent: {
type: STRING,
defaultValue: null,
},
referrer: {
type: STRING,
defaultValue: null,
},
routePath: {
type: STRING,
defaultValue: null,
},
params: {
type: STRING,
defaultValue: null,
}
},
{
freezeTableName: true,
timestamps: false, // don't use default timestamps columns
indexes: [
{
fields: ['isInternal', 'isChannel', 'time', 'claimId', 'routePath'],
},
],
}
);
return RequestMetrics;
};

View file

@ -22,10 +22,14 @@ const getBlockedList = require('../../controllers/api/blocked');
const getOEmbedData = require('../../controllers/api/oEmbed');
module.exports = {
// homepage routes
'/api/homepage/data/channels': { controller: [ torCheckMiddleware, channelData ] },
// channel routes
'/api/channel/availability/:name': { controller: [ torCheckMiddleware, channelAvailability ] },
'/api/channel/short-id/:longId/:name': { controller: [ torCheckMiddleware, channelShortId ] },
'/api/channel/data/:channelName/:channelClaimId': { controller: [ torCheckMiddleware, channelData ] },
'/api/channel/data/:channelName/:channelClaimId': { controller: [ torCheckMiddleware, channelData ] },
'/api/channel/claims/:channelName/:channelClaimId/:page': { controller: [ torCheckMiddleware, channelClaims ] },
// claim routes
'/api/claim/availability/:name': { controller: [ torCheckMiddleware, claimAvailability ] },

View file

@ -1,7 +1,7 @@
module.exports = {
...require('./pages'),
...require('./api'),
...require('./assets'),
...require('./auth'),
...require('./assets'),
...require('./fallback'),
};

View file

@ -2,8 +2,12 @@ const handlePageRequest = require('../../controllers/pages/sendReactApp');
const handleVideoEmbedRequest = require('../../controllers/pages/sendVideoEmbedPage');
const redirect = require('../../controllers/utils/redirect');
// TODO: Adjust build & sources to use import/export everywhere
const Actions = require('@actions').default;
const Sagas = require('@sagas').default;
module.exports = {
'/': { controller: handlePageRequest },
'/': { controller: handlePageRequest, action: Actions.onHandleShowHomepage, saga: Sagas.handleShowHomepage },
'/login': { controller: handlePageRequest },
'/about': { controller: handlePageRequest },
'/trending': { controller: redirect('/popular') },