replaced oembed route logic with two files
This commit is contained in:
parent
5230970705
commit
79109cce69
3 changed files with 105 additions and 60 deletions
58
server/controllers/api/oEmbed/getOEmbedDataForAsset.js
Normal file
58
server/controllers/api/oEmbed/getOEmbedDataForAsset.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
const logger = require('winston');
|
||||
const db = require('../../../models');
|
||||
const getClaimId = require('../../utils/getClaimId');
|
||||
|
||||
const getOEmbedDataForAsset = (channelName, channelClaimId, claimName, claimId) => {
|
||||
let fileData, claimData;
|
||||
let data = {
|
||||
version : 1.0,
|
||||
author_name : 'Spee.ch',
|
||||
author_url : 'https://spee.ch',
|
||||
provider_name: 'Spee.ch',
|
||||
provider_url : 'https://spee.ch',
|
||||
cache_age : 86400, // one day in seconds
|
||||
};
|
||||
|
||||
return getClaimId(channelName, channelClaimId, claimName, claimId)
|
||||
.then(fullClaimId => {
|
||||
claimId = fullClaimId;
|
||||
return db.Claim.findOne({
|
||||
where: {
|
||||
name : claimName,
|
||||
claimId: fullClaimId,
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(claimRecord => {
|
||||
claimData = claimRecord.dataValues;
|
||||
return db.Blocked.isNotBlocked(claimData.outpoint);
|
||||
})
|
||||
.then(() => {
|
||||
return db.File.findOne({
|
||||
where: {
|
||||
name: claimName,
|
||||
claimId,
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(fileRecord => {
|
||||
fileData = fileRecord.dataValues;
|
||||
logger.debug('file data:', fileData);
|
||||
// set the resource type
|
||||
if (fileData.fileType === 'video/mp4') {
|
||||
data['type'] = 'video';
|
||||
} else {
|
||||
data['type'] = 'picture';
|
||||
}
|
||||
// get the data
|
||||
data['title'] = claimData.title;
|
||||
data['thumbnail_url'] = `https://dev1.spee.ch/${fileData.claimId}/${fileData.name}.${fileData.fileType.substring('/')}`;
|
||||
data['thumbnail_width'] = fileData.width || 600;
|
||||
data['thumbnail_height'] = fileData.height || 400;
|
||||
})
|
||||
.then(() => {
|
||||
return data;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = getOEmbedDataForAsset;
|
17
server/controllers/api/oEmbed/getOEmbedDataForChannel.js
Normal file
17
server/controllers/api/oEmbed/getOEmbedDataForChannel.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
const logger = require('winston');
|
||||
|
||||
const getOEmbedDataForChannel = (channelName, channelClaimId) => {
|
||||
logger.debug('get oembed for channel:', `${channelName}:${channelClaimId}`);
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
version : 1.0,
|
||||
author_name : 'Spee.ch',
|
||||
author_url : 'https://spee.ch',
|
||||
provider_name: 'Spee.ch',
|
||||
provider_url : 'https://spee.ch',
|
||||
cache_age : 86400, // one day in seconds
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = getOEmbedDataForChannel;
|
|
@ -1,8 +1,9 @@
|
|||
const logger = require('winston');
|
||||
const db = require('../../../models');
|
||||
|
||||
const lbryUri = require('../../utils/lbryUri');
|
||||
const getClaimId = require('../../utils/getClaimId');
|
||||
|
||||
const getOEmbedDataForChannel = require('./getOEmbedDataForChannel');
|
||||
const getOEmbedDataForAsset = require('./getOEmbedDataForAsset');
|
||||
|
||||
|
||||
const parseSpeechUrl = (url) => {
|
||||
// parse the request url
|
||||
|
@ -32,82 +33,51 @@ const getOEmbedData = (req, res) => {
|
|||
logger.debug('req url', url);
|
||||
logger.debug('req format', format);
|
||||
|
||||
let data = {
|
||||
version: 1.0 ,
|
||||
author_name: 'Spee.ch',
|
||||
author_url: 'https://spee.ch',
|
||||
provider_name: 'Spee.ch',
|
||||
provider_url: 'https://spee.ch',
|
||||
cache_age: 86400, // one day in seconds
|
||||
};
|
||||
|
||||
const { paramOne, paramTwo } = parseSpeechUrl(url);
|
||||
let fileData, claimData;
|
||||
|
||||
let claimName, isChannel, channelName, channelClaimId, claimId;
|
||||
|
||||
if (paramTwo) {
|
||||
({ isChannel, channelName, channelClaimId, claimId } = lbryUri.parseIdentifier(paramOne));
|
||||
({ claimName } = lbryUri.parseClaim(paramTwo));
|
||||
} else {
|
||||
({ isChannel } = lbryUri.parseIdentifier(paramOne));
|
||||
({ isChannel, channelName, channelClaimId } = lbryUri.parseIdentifier(paramOne));
|
||||
if (!isChannel ) {
|
||||
({ claimName } = lbryUri.parseClaim(paramOne));
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug('ischannel:', isChannel);
|
||||
|
||||
if (isChannel && !paramTwo) {
|
||||
data['title'] = paramOne;
|
||||
data['thumbnail_url'] = 'test';
|
||||
data['thumbnail_width'] = 'test';
|
||||
data['thumbnail_height'] = 'test';
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: 'hello',
|
||||
data,
|
||||
});
|
||||
|
||||
} else {
|
||||
// return claim info
|
||||
getClaimId(channelName, channelClaimId, claimName, claimId)
|
||||
.then(fullClaimId => {
|
||||
claimId = fullClaimId;
|
||||
return db.Claim.findOne({
|
||||
where: {
|
||||
name : claimName,
|
||||
claimId: fullClaimId
|
||||
}
|
||||
});
|
||||
})
|
||||
.then(claimRecord => {
|
||||
claimData = claimRecord.dataValues;
|
||||
return db.Blocked.isNotBlocked(claimData.outpoint);
|
||||
})
|
||||
.then(() => {
|
||||
return db.File.findOne({
|
||||
where: {
|
||||
name: claimName,
|
||||
claimId,
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(fileRecord => {
|
||||
fileData = fileRecord.dataValues;
|
||||
logger.debug('file data:', fileData);
|
||||
// get channel data
|
||||
data['title'] = claimData.title;
|
||||
data['thumbnail_url'] = `https://dev1.spee.ch/${claimId}/${claimName}.ext`;
|
||||
data['thumbnail_width'] = fileData.width || 600;
|
||||
data['thumbnail_height'] = fileData.height || 400;
|
||||
// send response
|
||||
getOEmbedDataForChannel(channelName, channelClaimId)
|
||||
.then(data => {
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: 'hello',
|
||||
data,
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: error,
|
||||
});
|
||||
})
|
||||
|
||||
} else {
|
||||
getOEmbedDataForAsset(channelName, channelClaimId, claimName, claimId)
|
||||
.then(data => {
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: 'hello',
|
||||
data,
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: error,
|
||||
});
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue