412 blocked content #428

Merged
bones7242 merged 13 commits from 412-blocked_content into master 2018-05-01 01:07:59 +02:00
33 changed files with 310 additions and 296 deletions
Showing only changes of commit aa1834e1c6 - Show all commits

View file

@ -1,4 +1,4 @@
const db = require('../../models');
const db = require('../../../../models');
const checkChannelAvailability = (name) => {
return db.Channel

View file

@ -1,6 +1,6 @@
const checkChannelAvailability = require('../utils/checkChannelAvailability.js');
const { sendGATimingEvent } = require('../../utils/googleAnalytics.js');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const checkChannelAvailability = require('./checkChannelAvailability.js');
const { sendGATimingEvent } = require('../../../../utils/googleAnalytics.js');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
/*

View file

@ -0,0 +1,31 @@
const db = require('../../../../models');
const { returnPaginatedChannelClaims } = require('./channelPagination.js');
const NO_CHANNEL = 'NO_CHANNEL';
const getChannelClaims = (channelName, channelClaimId, page) => {
return new Promise((resolve, reject) => {
// 1. get the long channel Id (make sure channel exists)
db.Certificate.getLongChannelId(channelName, channelClaimId)
.then(longChannelClaimId => {
if (!longChannelClaimId) {
return [null, null, null];
}
// 2. get the short ID and all claims for that channel
return Promise.all([longChannelClaimId, db.Claim.getAllChannelClaims(longChannelClaimId)]);
})
.then(([longChannelClaimId, channelClaimsArray]) => {
if (!longChannelClaimId) {
return resolve(NO_CHANNEL);
}
// 3. format the data for the view, including pagination
let paginatedChannelViewData = returnPaginatedChannelClaims(channelName, longChannelClaimId, channelClaimsArray, page);
// 4. return all the channel information and contents
resolve(paginatedChannelViewData);
})
.catch(error => {
reject(error);
});
});
};
module.exports = getChannelClaims;

View file

@ -1,5 +1,5 @@
const { getChannelClaims } = require('../utils/serveHelpers.js');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const getChannelClaims = require('./getChannelClaims.js');
const NO_CHANNEL = 'NO_CHANNEL';

View file

@ -0,0 +1,32 @@
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
const db = require('../../../../models');
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
const NO_CHANNEL = 'NO_CHANNEL';
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
const getChannelData = (channelName, channelClaimId, page) => {
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
return new Promise((resolve, reject) => {
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
// 1. get the long channel Id (make sure channel exists)
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
db.Certificate.getLongChannelId(channelName, channelClaimId)
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
.then(longChannelClaimId => {
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
if (!longChannelClaimId) {
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
return [null, null, null];
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
}
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
// 2. get the short ID and all claims for that channel
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
return Promise.all([longChannelClaimId, db.Certificate.getShortChannelIdFromLongChannelId(longChannelClaimId, channelName)]);
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
})
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
.then(([longChannelClaimId, shortChannelClaimId]) => {
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
if (!longChannelClaimId) {
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
return resolve(NO_CHANNEL);
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
}
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
// 3. return all the channel information
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
resolve({
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
channelName,
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
longChannelClaimId,
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
shortChannelClaimId,
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
});
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
})
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
.catch(error => {
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
reject(error);
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
});
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
});
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
};
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
module.exports = getChannelData;
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.

View file

@ -1,5 +1,5 @@
const { getChannelData } = require('../utils/serveHelpers.js');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const { getChannelData } = require('../../../utils/serveHelpers.js');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const NO_CHANNEL = 'NO_CHANNEL';

View file

@ -1,5 +1,5 @@
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const db = require('../../models/index');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const db = require('../../../../models');
/*

View file

@ -1,6 +1,6 @@
const checkClaimAvailability = require('../utils/checkClaimAvailability.js');
const { sendGATimingEvent } = require('../../utils/googleAnalytics.js');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const { sendGATimingEvent } = require('../../../../utils/googleAnalytics.js');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
/*

View file

@ -1,5 +1,5 @@
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const db = require('../../models/index');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const db = require('../../../../models');
/*

View file

@ -1,7 +1,7 @@
const { getClaim } = require('../../lbrynet');
const { addGetResultsToFileData, createFileData } = require('../utils/file.js');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const db = require('../../models');
const { getClaim } = require('../../../../lbrynet');
const { addGetResultsToFileData, createFileData } = require('../../../utils/file.js');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const db = require('../../../../models');
/*

View file

@ -1,5 +1,5 @@
const { getClaimList } = require('../../lbrynet/index');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const { getClaimList } = require('../../../../lbrynet');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
/*

View file

@ -1,5 +1,5 @@
const { getClaimId } = require('../utils/serveHelpers.js');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const { getClaimId } = require('../../../utils/serveHelpers.js');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const NO_CHANNEL = 'NO_CHANNEL';
const NO_CLAIM = 'NO_CLAIM';

View file

@ -0,0 +1,40 @@
const logger = require('winston');
const { details, publishing } = require('../../../../../config/siteConfig.js');
const createBasicPublishParams = (filePath, name, title, description, license, nsfw, thumbnail) => {
logger.debug(`Creating Publish Parameters`);
// provide defaults for title
if (title === null || title.trim() === '') {
title = name;
}
// provide default for description
if (description === null || description.trim() === '') {
description = '';
}
// provide default for license
if (license === null || license.trim() === '') {
license = ' '; // default to empty string
}
// create the publish params
const publishParams = {
name,
file_path: filePath,
bid : 0.01,
metadata : {
description,
title,
author : details.title,
language: 'en',
license,
nsfw,
},
claim_address: publishing.primaryClaimAddress,
};
// add thumbnail to channel if video
if (thumbnail) {
publishParams['metadata']['thumbnail'] = thumbnail;
}
return publishParams;
};
module.exports = createBasicPublishParams;

View file

@ -0,0 +1,28 @@
const logger = require('winston');
const { details, publishing } = require('../../../../../config/siteConfig.js');
const createThumbnailPublishParams = (thumbnailFilePath, claimName, license, nsfw) => {
if (!thumbnailFilePath) {
return;
}
logger.debug(`Creating Thumbnail Publish Parameters`);
// create the publish params
return {
name : `${claimName}-thumb`,
file_path: thumbnailFilePath,
bid : 0.01,
metadata : {
title : `${claimName} thumbnail`,
description: `a thumbnail for ${claimName}`,
author : details.title,
language : 'en',
license,
nsfw,
},
claim_address: publishing.primaryClaimAddress,
channel_name : publishing.thumbnailChannel,
channel_id : publishing.thumbnailChannelId,
};
};
module.exports = createThumbnailPublishParams;

View file

@ -1,15 +1,13 @@
const { details: { host } } = require('../../../config/siteConfig.js');
const { authenticateUser } = require('../../auth/authentication.js');
const { sendGATimingEvent } = require('../../utils/googleAnalytics.js');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const checkClaimAvailability = require('../utils/checkClaimAvailability');
const publish = require('../utils/publish.js');
const {
createBasicPublishParams,
createThumbnailPublishParams,
parsePublishApiRequestBody,
parsePublishApiRequestFiles,
} = require('../utils/publishHelpers.js');
const { details: { host } } = require('../../../../../config/siteConfig.js');
const { authenticateUser } = require('../../../../auth/authentication.js');
const { sendGATimingEvent } = require('../../../../utils/googleAnalytics.js');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const publish = require('./publish.js');
const createBasicPublishParams = require('./createBasicPublishParams.js');
const createThumbnailPublishParams = require('./createThumbnailPublishParams.js');
const parsePublishApiRequestBody = require('./parsePublishApiRequestBody.js');
const parsePublishApiRequestFiles = require('./parsePublishApiRequestFiles.js');
const checkClaimAvailability = require('../utils/checkClaimAvailability.js');
/*

View file

@ -0,0 +1,27 @@
const parsePublishApiRequestBody = ({name, nsfw, license, title, description, thumbnail}) => {
// validate name
if (!name) {
throw new Error('no name field found in request');
}
const invalidNameCharacters = /[^A-Za-z0-9,-]/.exec(name);
if (invalidNameCharacters) {
throw new Error('The claim name you provided is not allowed. Only the following characters are allowed: A-Z, a-z, 0-9, and "-"');
}
// optional parameters
nsfw = (nsfw === 'true');
license = license || null;
title = title || null;
description = description || null;
thumbnail = thumbnail || null;
// return results
return {
name,
nsfw,
license,
title,
description,
thumbnail,
};
};
module.exports = parsePublishApiRequestBody;

View file

@ -0,0 +1,34 @@
const validateFileTypeAndSize = require('./validateFileTypeAndSize.js');
const parsePublishApiRequestFiles = ({file, thumbnail}) => {
// make sure a file was provided
if (!file) {
throw new Error('no file with key of [file] found in request');
}
if (!file.path) {
throw new Error('no file path found');
}
if (!file.type) {
throw new Error('no file type found');
}
if (!file.size) {
throw new Error('no file type found');
}
// validate the file name
if (/'/.test(file.name)) {
throw new Error('apostrophes are not allowed in the file name');
}
// validate the file
validateFileTypeAndSize(file);
// return results
return {
fileName : file.name,
filePath : file.path,
fileType : file.type,
thumbnailFileName: (thumbnail ? thumbnail.name : null),
thumbnailFilePath: (thumbnail ? thumbnail.path : null),
thumbnailFileType: (thumbnail ? thumbnail.type : null),
};
};
module.exports = parsePublishApiRequestFiles;

View file

@ -1,6 +1,6 @@
const logger = require('winston');
const db = require('../../models');
const { publishClaim } = require('../../lbrynet');
const db = require('../../../../models');
const { publishClaim } = require('../../../../lbrynet');
const deleteFile = require('./deleteFile.js');
const publish = (publishParams, fileName, fileType) => {

View file

@ -0,0 +1,33 @@
const logger = require('winston');
const validateFileTypeAndSize = (file) => {
// check file type and size
switch (file.type) {
case 'image/jpeg':
case 'image/jpg':
case 'image/png':
if (file.size > 10000000) {
logger.debug('publish > file validation > .jpeg/.jpg/.png was too big');
throw new Error('Sorry, images are limited to 10 megabytes.');
}
break;
case 'image/gif':
if (file.size > 50000000) {
logger.debug('publish > file validation > .gif was too big');
throw new Error('Sorry, .gifs are limited to 50 megabytes.');
}
break;
case 'video/mp4':
if (file.size > 50000000) {
logger.debug('publish > file validation > .mp4 was too big');
throw new Error('Sorry, videos are limited to 50 megabytes.');
}
break;
default:
logger.debug('publish > file validation > unrecognized file type');
throw new Error('The ' + file.type + ' content type is not supported. Only, .jpeg, .png, .gif, and .mp4 files are currently supported.');
}
return file;
};
module.exports = validateFileTypeAndSize;

View file

@ -1,5 +1,5 @@
const { resolveUri } = require('../../lbrynet/index');
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const { resolveUri } = require('../../../../lbrynet/index');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
/*

View file

@ -1,5 +1,5 @@
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const db = require('../../models/index');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const db = require('../../../../models');
/*

View file

@ -1,5 +1,5 @@
const db = require('../../models/index');
const { publishing: { primaryClaimAddress, additionalClaimAddresses } } = require('../../../config/siteConfig.js');
const db = require('../../../../models');
const { publishing: { primaryClaimAddress, additionalClaimAddresses } } = require('../../../../../config/siteConfig.js');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;

View file

@ -1,5 +1,5 @@
const { handleErrorResponse } = require('../utils/errorHandlers.js');
const db = require('../../models/index');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const db = require('../../../../models');
/*

View file

@ -1,11 +1,11 @@
const { sendGAServeEvent } = require('../../utils/googleAnalytics');
const { sendGAServeEvent } = require('../../../utils/googleAnalytics');
const {
determineResponseType,
logRequestData,
getClaimIdAndServeAsset,
} = require('../utils/serve.js');
const lbryUri = require('../utils/lbryUri.js');
const handleShowRender = require('../../render/build/handleShowRender.js');
} = require('../../utils/serve.js');
const lbryUri = require('../../utils/lbryUri.js');
const handleShowRender = require('../../../render/build/handleShowRender.js');
const SERVE = 'SERVE';
/*

View file

@ -1,12 +1,12 @@
const { sendGAServeEvent } = require('../../utils/googleAnalytics');
const { sendGAServeEvent } = require('../../../utils/googleAnalytics');
const {
determineResponseType,
flipClaimNameAndIdForBackwardsCompatibility,
logRequestData,
getClaimIdAndServeAsset,
} = require('../utils/serve.js');
const lbryUri = require('../utils/lbryUri.js');
const handleShowRender = require('../../render/build/handleShowRender.js');
} = require('../../utils/serve.js');
const lbryUri = require('../../utils/lbryUri.js');
const handleShowRender = require('../../../render/build/handleShowRender.js');
const SERVE = 'SERVE';

View file

@ -1,165 +0,0 @@
const logger = require('winston');
const { details, publishing } = require('../../../config/siteConfig.js');
module.exports = {
parsePublishApiRequestBody ({name, nsfw, license, title, description, thumbnail}) {
// validate name
if (!name) {
throw new Error('no name field found in request');
}
const invalidNameCharacters = /[^A-Za-z0-9,-]/.exec(name);
if (invalidNameCharacters) {
throw new Error('The claim name you provided is not allowed. Only the following characters are allowed: A-Z, a-z, 0-9, and "-"');
}
// optional parameters
nsfw = (nsfw === 'true');
license = license || null;
title = title || null;
description = description || null;
thumbnail = thumbnail || null;
// return results
return {
name,
nsfw,
license,
title,
description,
thumbnail,
};
},
parsePublishApiRequestFiles ({file, thumbnail}) {
// make sure a file was provided
if (!file) {
throw new Error('no file with key of [file] found in request');
}
if (!file.path) {
throw new Error('no file path found');
}
if (!file.type) {
throw new Error('no file type found');
}
if (!file.size) {
throw new Error('no file type found');
}
// validate the file name
if (/'/.test(file.name)) {
throw new Error('apostrophes are not allowed in the file name');
}
// validate the file
module.exports.validateFileTypeAndSize(file);
// return results
return {
fileName : file.name,
filePath : file.path,
fileType : file.type,
thumbnailFileName: (thumbnail ? thumbnail.name : null),
thumbnailFilePath: (thumbnail ? thumbnail.path : null),
thumbnailFileType: (thumbnail ? thumbnail.type : null),
};
},
validateFileTypeAndSize (file) {
// check file type and size
switch (file.type) {
case 'image/jpeg':
case 'image/jpg':
case 'image/png':
if (file.size > 10000000) {
logger.debug('publish > file validation > .jpeg/.jpg/.png was too big');
throw new Error('Sorry, images are limited to 10 megabytes.');
}
break;
case 'image/gif':
if (file.size > 50000000) {
logger.debug('publish > file validation > .gif was too big');
throw new Error('Sorry, .gifs are limited to 50 megabytes.');
}
break;
case 'video/mp4':
if (file.size > 50000000) {
logger.debug('publish > file validation > .mp4 was too big');
throw new Error('Sorry, videos are limited to 50 megabytes.');
}
break;
default:
logger.debug('publish > file validation > unrecognized file type');
throw new Error('The ' + file.type + ' content type is not supported. Only, .jpeg, .png, .gif, and .mp4 files are currently supported.');
}
return file;
},
createBasicPublishParams (filePath, name, title, description, license, nsfw, thumbnail) {
logger.debug(`Creating Publish Parameters`);
// provide defaults for title
if (title === null || title.trim() === '') {
title = name;
}
// provide default for description
if (description === null || description.trim() === '') {
description = '';
}
// provide default for license
if (license === null || license.trim() === '') {
license = ' '; // default to empty string
}
// create the publish params
const publishParams = {
name,
file_path: filePath,
bid : 0.01,
metadata : {
description,
title,
author : details.title,
language: 'en',
license,
nsfw,
},
claim_address: publishing.primaryClaimAddress,
};
// add thumbnail to channel if video
if (thumbnail) {
publishParams['metadata']['thumbnail'] = thumbnail;
}
return publishParams;
},
createThumbnailPublishParams (thumbnailFilePath, claimName, license, nsfw) {
if (!thumbnailFilePath) {
return;
}
logger.debug(`Creating Thumbnail Publish Parameters`);
// create the publish params
return {
name : `${claimName}-thumb`,
file_path: thumbnailFilePath,
bid : 0.01,
metadata : {
title : `${claimName} thumbnail`,
description: `a thumbnail for ${claimName}`,
author : details.title,
language : 'en',
license,
nsfw,
},
claim_address: publishing.primaryClaimAddress,
channel_name : publishing.thumbnailChannel,
channel_id : publishing.thumbnailChannelId,
};
},
addGetResultsToFileData (fileInfo, getResult) {
fileInfo.fileName = getResult.file_name;
fileInfo.filePath = getResult.download_path;
return fileInfo;
},
createFileData ({ name, claimId, outpoint, height, address, nsfw, contentType }) {
return {
name,
claimId,
outpoint,
height,
address,
fileName: '',
filePath: '',
fileType: contentType,
nsfw,
};
},
};

View file

@ -1,6 +1,5 @@
const db = require('../../models/index');
const db = require('../../models');
const logger = require('winston');
const { returnPaginatedChannelClaims } = require('./channelPagination.js');
const NO_CHANNEL = 'NO_CHANNEL';
const NO_CLAIM = 'NO_CLAIM';
@ -53,58 +52,6 @@ module.exports = {
});
});
},
getChannelData (channelName, channelClaimId, page) {
return new Promise((resolve, reject) => {
// 1. get the long channel Id (make sure channel exists)
db.Certificate.getLongChannelId(channelName, channelClaimId)
.then(longChannelClaimId => {
if (!longChannelClaimId) {
return [null, null, null];
}
// 2. get the short ID and all claims for that channel
return Promise.all([longChannelClaimId, db.Certificate.getShortChannelIdFromLongChannelId(longChannelClaimId, channelName)]);
})
.then(([longChannelClaimId, shortChannelClaimId]) => {
if (!longChannelClaimId) {
return resolve(NO_CHANNEL);
}
// 3. return all the channel information
resolve({
channelName,
longChannelClaimId,
shortChannelClaimId,
});
})
.catch(error => {
reject(error);
});
});
},
getChannelClaims (channelName, channelClaimId, page) {
return new Promise((resolve, reject) => {
// 1. get the long channel Id (make sure channel exists)
db.Certificate.getLongChannelId(channelName, channelClaimId)
.then(longChannelClaimId => {
if (!longChannelClaimId) {
return [null, null, null];
}
// 2. get the short ID and all claims for that channel
return Promise.all([longChannelClaimId, db.Claim.getAllChannelClaims(longChannelClaimId)]);
})
.then(([longChannelClaimId, channelClaimsArray]) => {
if (!longChannelClaimId) {
return resolve(NO_CHANNEL);
}
// 3. format the data for the view, including pagination
let paginatedChannelViewData = returnPaginatedChannelClaims(channelName, longChannelClaimId, channelClaimsArray, page);
// 4. return all the channel information and contents
resolve(paginatedChannelViewData);
})
.catch(error => {
reject(error);
});
});
},
getLocalFileRecord (claimId, name) {
return db.File.findOne({where: {claimId, name}})
.then(file => {

View file

@ -1,16 +1,16 @@
const channelAvailability = require('../../controllers/api/channelAvailability');
const channelClaims = require('../../controllers/api/channelClaims');
const channelData = require('../../controllers/api/channelData');
const channelShortId = require('../../controllers/api/channelShortId');
const claimAvailability = require('../../controllers/api/claimAvailability');
const claimData = require('../../controllers/api/claimData');
const claimGet = require('../../controllers/api/claimGet');
const claimLongId = require('../../controllers/api/claimLongId');
const claimPublish = require('../../controllers/api/claimPublish');
const claimResolve = require('../../controllers/api/claimResolve');
const claimShortId = require('../../controllers/api/claimShortId');
const claimList = require('../../controllers/api/claimList');
const fileAvailability = require('../../controllers/api/fileAvailability');
const channelAvailability = require('../../controllers/api/channel/availability');
const channelClaims = require('../../controllers/api/channel/claims');
const channelData = require('../../controllers/api/channel/data');
const channelShortId = require('../../controllers/api/channel/shortId');
const claimAvailability = require('../../controllers/api/claim/availability');
const claimData = require('../../controllers/api/claim/data/');
const claimGet = require('../../controllers/api/claim/get');
const claimLongId = require('../../controllers/api/claim/longId');
const claimPublish = require('../../controllers/api/claim/publish');
const claimResolve = require('../../controllers/api/claim/resolve');
const claimShortId = require('../../controllers/api/claim/shortId');
const claimList = require('../../controllers/api/claim/list');
const fileAvailability = require('../../controllers/api/file/availability');
const multipartMiddleware = require('../utils/multipartMiddleware');

View file

@ -1,5 +1,5 @@
const serveAssetByClaim = require('../../controllers/assets/serveAssetByClaim');
const serveAssetByIdentifierAndClaim = require('../../controllers/assets/serveAssetByIdentifierAndClaim');
const serveAssetByClaim = require('../../controllers/assets/serveByClaim');
const serveAssetByIdentifierAndClaim = require('../../controllers/assets/serveByIdentifierAndClaim');
module.exports = (app, db) => {
app.get('/:identifier/:claim', serveAssetByIdentifierAndClaim);

View file

@ -1,6 +1,6 @@
const PassportLocalStrategy = require('passport-local').Strategy;
const logger = require('winston');
const db = require('../../models/index');
const db = require('../../models');
const returnUserAndChannelInfo = (userInstance) => {
return new Promise((resolve, reject) => {

View file

@ -1,27 +1,34 @@
const chai = require('chai');
const expect = chai.expect;
describe('publishHelpers.js', function () {
const publishHelpers = require('../../server/controllers/utils/publishHelpers.js');
describe('publish utils', function () {
describe('#parsePublishApiRequestBody()', function () {
const parsePublishApiRequestBody = require('../../../server/controllers/api/claim/publish/parsePublishApiRequestBody.js');
it('should throw an error if no body', function () {
expect(publishHelpers.parsePublishApiRequestBody.bind(this, null)).to.throw();
expect(parsePublishApiRequestBody.bind(this, null)).to.throw();
});
it('should throw an error if no body.name', function () {
const bodyNoName = {};
expect(publishHelpers.parsePublishApiRequestBody.bind(this, bodyNoName)).to.throw();
expect(parsePublishApiRequestBody.bind(this, bodyNoName)).to.throw();
});
});
describe('#parsePublishApiRequestFiles()', function () {
const parsePublishApiRequestFiles = require('../../../server/controllers/api/claim/publish/parsePublishApiRequestFiles.js');
it('should throw an error if no files', function () {
expect(publishHelpers.parsePublishApiRequestFiles.bind(this, null)).to.throw();
expect(parsePublishApiRequestFiles.bind(this, null)).to.throw();
});
it('should throw an error if no files.file', function () {
const filesNoFile = {};
expect(publishHelpers.parsePublishApiRequestFiles.bind(this, filesNoFile)).to.throw();
expect(parsePublishApiRequestFiles.bind(this, filesNoFile)).to.throw();
});
it('should throw an error if file.size is too large', function () {
const filesTooBig = {
file: {
@ -31,8 +38,9 @@ describe('publishHelpers.js', function () {
size: 10000001,
},
};
expect(publishHelpers.parsePublishApiRequestFiles.bind(this, filesTooBig)).to.throw();
expect(parsePublishApiRequestFiles.bind(this, filesTooBig)).to.throw();
});
it('should throw error if not an accepted file type', function () {
const filesWrongType = {
file: {
@ -42,8 +50,9 @@ describe('publishHelpers.js', function () {
size: 10000000,
},
};
expect(publishHelpers.parsePublishApiRequestFiles.bind(this, filesWrongType)).to.throw();
expect(parsePublishApiRequestFiles.bind(this, filesWrongType)).to.throw();
});
it('should throw NO error if no problems', function () {
const filesNoProblems = {
file: {
@ -53,7 +62,7 @@ describe('publishHelpers.js', function () {
size: 10000000,
},
};
expect(publishHelpers.parsePublishApiRequestFiles.bind(this, filesNoProblems)).to.not.throw();
expect(parsePublishApiRequestFiles.bind(this, filesNoProblems)).to.not.throw();
});
});