organized api controllers and helpers
This commit is contained in:
parent
dd012282d3
commit
aa1834e1c6
33 changed files with 310 additions and 296 deletions
|
@ -1,4 +1,4 @@
|
|||
const db = require('../../models');
|
||||
const db = require('../../../../models');
|
||||
|
||||
const checkChannelAvailability = (name) => {
|
||||
return db.Channel
|
|
@ -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');
|
||||
|
||||
/*
|
||||
|
31
server/controllers/api/channel/claims/getChannelClaims.js
Normal file
31
server/controllers/api/channel/claims/getChannelClaims.js
Normal 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;
|
|
@ -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';
|
||||
|
32
server/controllers/api/channel/data/getChannelData.js
Normal file
32
server/controllers/api/channel/data/getChannelData.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
const db = require('../../../../models');
|
||||
const NO_CHANNEL = 'NO_CHANNEL';
|
||||
|
||||
const 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);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = getChannelData;
|
|
@ -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';
|
||||
|
|
@ -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');
|
||||
|
||||
/*
|
||||
|
|
@ -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');
|
||||
|
||||
/*
|
||||
|
|
@ -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');
|
||||
|
||||
/*
|
||||
|
|
@ -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');
|
||||
|
||||
/*
|
||||
|
|
@ -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');
|
||||
|
||||
/*
|
||||
|
|
@ -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';
|
|
@ -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;
|
|
@ -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;
|
|
@ -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');
|
||||
|
||||
/*
|
||||
|
|
@ -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;
|
|
@ -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;
|
|
@ -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) => {
|
|
@ -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;
|
|
@ -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');
|
||||
|
||||
/*
|
||||
|
|
@ -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');
|
||||
|
||||
/*
|
||||
|
|
@ -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;
|
||||
|
|
@ -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');
|
||||
|
||||
/*
|
||||
|
|
@ -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';
|
||||
|
||||
/*
|
|
@ -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';
|
||||
|
|
@ -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,
|
||||
};
|
||||
},
|
||||
};
|
|
@ -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 => {
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in a new issue