refactor isApprovedClaim to claims folder shared by client and server

This commit is contained in:
Travis Eden 2018-09-21 16:16:01 -04:00
parent ba3abd2eeb
commit 69f82d814b
7 changed files with 13 additions and 24 deletions

View file

@ -1,7 +1,7 @@
import React from 'react';
import { NavLink, withRouter } from 'react-router-dom';
import NavBarChannelOptionsDropdown from '@components/NavBarChannelOptionsDropdown';
import isApprovedChannel from '../../utils/isApprovedChannel';
import isApprovedChannel from '../../../../utils/isApprovedChannel';
const VIEW = 'VIEW';
const LOGOUT = 'LOGOUT';

View file

@ -1,7 +1,7 @@
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const getChannelData = require('./getChannelData.js');
const isApprovedChannel = require('../../../../utils/isApprovedChannel');
const { publishing: { serveOnlyApproved } } = require('@config/siteConfig');
const isApprovedChannel = require('../../../../../utils/isApprovedChannel');
const { publishing: { serveOnlyApproved, approvedChannels } } = require('@config/siteConfig');
const NO_CHANNEL = 'NO_CHANNEL';
/*
@ -18,7 +18,7 @@ const channelData = ({ ip, originalUrl, body, params }, res) => {
const chanObj = {};
if (channelName) chanObj.name = channelName;
if (channelClaimId) chanObj[(channelClaimId.length === 40 ? 'longId' : 'shortId')] = channelClaimId;
if (serveOnlyApproved && !isApprovedChannel(chanObj)) {
if (serveOnlyApproved && !isApprovedChannel(chanObj, approvedChannels)) {
return res.status(404).json({
success: false,
message: 'This content is unavailable',

View file

@ -3,8 +3,8 @@ const logger = require('winston');
const { details: { host }, publishing: { disabled, disabledMessage } } = require('@config/siteConfig');
const { sendGATimingEvent } = require('../../../../utils/googleAnalytics.js');
const isApprovedChannel = require('../../../../utils/isApprovedChannel');
const { publishing: { publishOnlyApproved } } = require('@config/siteConfig');
const isApprovedChannel = require('../../../../../utils/isApprovedChannel');
const { publishing: { publishOnlyApproved, approvedChannels } } = require('@config/siteConfig');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
@ -57,7 +57,7 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
// check channel authorization
authenticateUser(channelName, channelId, channelPassword, user)
.then(({ channelName, channelClaimId }) => {
if (publishOnlyApproved && !isApprovedChannel({ longId: channelClaimId })) {
if (publishOnlyApproved && !isApprovedChannel({ longId: channelClaimId }, approvedChannels)) {
const error = {
name : UNAPPROVED_CHANNEL,
message: 'This spee.ch instance only allows publishing to approved channels',

View file

@ -1,7 +1,7 @@
const logger = require('winston');
const db = require('../../../models');
const isApprovedChannel = require('../../../utils/isApprovedChannel');
const isApprovedChannel = require('../../../../utils/isApprovedChannel');
const getClaimId = require('../../utils/getClaimId.js');
const { handleErrorResponse } = require('../../utils/errorHandlers.js');
@ -14,7 +14,7 @@ const BLOCKED_CLAIM = 'BLOCKED_CLAIM';
const NO_FILE = 'NO_FILE';
const CONTENT_UNAVAILABLE = 'CONTENT_UNAVAILABLE';
const { publishing: { serveOnlyApproved } } = require('@config/siteConfig');
const { publishing: { serveOnlyApproved, approvedChannels } } = require('@config/siteConfig');
const getClaimIdAndServeAsset = (channelName, channelClaimId, claimName, claimId, originalUrl, ip, res) => {
getClaimId(channelName, channelClaimId, claimName, claimId)
@ -29,7 +29,7 @@ const getClaimIdAndServeAsset = (channelName, channelClaimId, claimName, claimId
});
})
.then(claim => {
if (serveOnlyApproved && !isApprovedChannel({ longId: claim.dataValues.certificateId })) {
if (serveOnlyApproved && !isApprovedChannel({ longId: claim.dataValues.certificateId }, approvedChannels)) {
throw new Error(CONTENT_UNAVAILABLE);
}
logger.debug('Outpoint:', claim.dataValues.outpoint);

View file

@ -1,8 +1,8 @@
const logger = require('winston');
const returnShortId = require('./utils/returnShortId.js');
const isApprovedChannel = require('../utils/isApprovedChannel');
const isApprovedChannel = require('../../utils/isApprovedChannel');
const { assetDefaults: { thumbnail: defaultThumbnail }, details: { host } } = require('@config/siteConfig');
const { publishing: { serveOnlyApproved } } = require('@config/siteConfig');
const { publishing: { serveOnlyApproved, approvedChannels } } = require('@config/siteConfig');
const NO_CLAIM = 'NO_CLAIM';
@ -364,7 +364,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
where: { name, claimId },
})
.then(claimArray => {
if (serveOnlyApproved && !isApprovedChannel({ longId: claimArray[0].dataValues.certificateId })) {
if (serveOnlyApproved && !isApprovedChannel({ longId: claimArray[0].dataValues.certificateId }, approvedChannels)) {
reject('This content is unavailable');
}
switch (claimArray.length) {

View file

@ -1,11 +0,0 @@
const { publishing: { approvedChannels } } = require('@config/siteConfig');
function isApprovedChannel (channel, channels = approvedChannels) {
const { name, shortId: short, longId: long } = channel;
return Boolean(
(long && channels.find(chan => chan.longId === long)) ||
(name && short && channels.find(chan => chan.name === name && chan.shortId === short))
);
}
module.exports = isApprovedChannel;