return canonicalUrl on publish/update; fixes
This commit is contained in:
parent
ffe8aaba47
commit
936ac2f439
5 changed files with 149 additions and 38 deletions
|
@ -73,7 +73,7 @@ function * publishFile (action) {
|
|||
});
|
||||
}
|
||||
if (success.data.claimId) {
|
||||
return history.push(`/${success.data.claimId}/${success.data.name}`);
|
||||
return history.push(success.data.pushTo);
|
||||
} else {
|
||||
// this returns to the homepage, needs work
|
||||
return yield put(updatePublishStatus(publishStates.FAILED, 'ERROR'));
|
||||
|
|
|
@ -850,7 +850,7 @@ var claimQueries = (db, table, sequelize) => ({
|
|||
});
|
||||
},
|
||||
|
||||
getShortClaimIdFromLongClaimId: async (claimId, claimName) => {
|
||||
getShortClaimIdFromLongClaimId: async (claimId, claimName, pendingClaim) => {
|
||||
logger$1.debug(`claim.getShortClaimIdFromLongClaimId for ${claimName}#${claimId}`);
|
||||
return await table.findAll({
|
||||
where: { name: claimName },
|
||||
|
@ -860,7 +860,12 @@ var claimQueries = (db, table, sequelize) => ({
|
|||
throw new Error('No claim(s) found with that claim name');
|
||||
}
|
||||
|
||||
return returnShortId(result, claimId);
|
||||
let list = result.map(claim => claim.dataValues);
|
||||
if (pendingClaim) {
|
||||
list = list.concat(pendingClaim);
|
||||
}
|
||||
|
||||
return returnShortId(list, claimId);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -981,6 +986,24 @@ var claimQueries = (db, table, sequelize) => ({
|
|||
});
|
||||
},
|
||||
|
||||
resolveClaimInChannel: async (claimName, channelId) => {
|
||||
logger$1.debug(`Claim.resolveClaimByNames: ${claimName} in ${channelId}`);
|
||||
return table.findAll({
|
||||
where: {
|
||||
name: claimName,
|
||||
publisher_id: channelId,
|
||||
},
|
||||
}).then(claimArray => {
|
||||
if (claimArray.length === 0) {
|
||||
return null;
|
||||
} else if (claimArray.length !== 1) {
|
||||
logger$1.warn(`more than one record matches ${claimName} in ${channelId}`);
|
||||
}
|
||||
|
||||
return claimArray[0];
|
||||
});
|
||||
},
|
||||
|
||||
getOutpoint: async (name, claimId) => {
|
||||
logger$1.debug(`finding outpoint for ${name}#${claimId}`);
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ export default (db, table, sequelize) => ({
|
|||
});
|
||||
},
|
||||
|
||||
getShortClaimIdFromLongClaimId: async (claimId, claimName) => {
|
||||
getShortClaimIdFromLongClaimId: async (claimId, claimName, pendingClaim) => {
|
||||
logger.debug(`claim.getShortClaimIdFromLongClaimId for ${claimName}#${claimId}`);
|
||||
return await table.findAll({
|
||||
where: { name: claimName },
|
||||
|
@ -59,7 +59,12 @@ export default (db, table, sequelize) => ({
|
|||
throw new Error('No claim(s) found with that claim name');
|
||||
}
|
||||
|
||||
return returnShortId(result, claimId);
|
||||
let list = result.map(claim => claim.dataValues);
|
||||
if (pendingClaim) {
|
||||
list = list.concat(pendingClaim);
|
||||
}
|
||||
|
||||
return returnShortId(list, claimId);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -180,6 +185,24 @@ export default (db, table, sequelize) => ({
|
|||
});
|
||||
},
|
||||
|
||||
resolveClaimInChannel: async (claimName, channelId) => {
|
||||
logger.debug(`Claim.resolveClaimByNames: ${claimName} in ${channelId}`);
|
||||
return table.findAll({
|
||||
where: {
|
||||
name: claimName,
|
||||
publisher_id: channelId,
|
||||
},
|
||||
}).then(claimArray => {
|
||||
if (claimArray.length === 0) {
|
||||
return null;
|
||||
} else if (claimArray.length !== 1) {
|
||||
logger.warn(`more than one record matches ${claimName} in ${channelId}`);
|
||||
}
|
||||
|
||||
return claimArray[0];
|
||||
});
|
||||
},
|
||||
|
||||
getOutpoint: async (name, claimId) => {
|
||||
logger.debug(`finding outpoint for ${name}#${claimId}`);
|
||||
|
||||
|
|
|
@ -17,6 +17,9 @@ const parsePublishApiRequestBody = require('./parsePublishApiRequestBody.js');
|
|||
const parsePublishApiRequestFiles = require('./parsePublishApiRequestFiles.js');
|
||||
const authenticateUser = require('./authentication.js');
|
||||
|
||||
const chainquery = require('chainquery');
|
||||
const createCanonicalLink = require('../../../../../utils/createCanonicalLink');
|
||||
|
||||
const CLAIM_TAKEN = 'CLAIM_TAKEN';
|
||||
const UNAPPROVED_CHANNEL = 'UNAPPROVED_CHANNEL';
|
||||
|
||||
|
@ -42,7 +45,25 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
|
|||
});
|
||||
}
|
||||
// define variables
|
||||
let channelName, channelId, channelPassword, description, fileName, filePath, fileExtension, fileType, gaStartTime, license, name, nsfw, thumbnail, thumbnailFileName, thumbnailFilePath, thumbnailFileType, title;
|
||||
let channelName,
|
||||
channelId,
|
||||
channelPassword,
|
||||
description,
|
||||
fileName,
|
||||
filePath,
|
||||
fileExtension,
|
||||
fileType,
|
||||
gaStartTime,
|
||||
license,
|
||||
name,
|
||||
nsfw,
|
||||
thumbnail,
|
||||
thumbnailFileName,
|
||||
thumbnailFilePath,
|
||||
thumbnailFileType,
|
||||
title,
|
||||
claimData,
|
||||
claimId;
|
||||
// record the start time of the request
|
||||
gaStartTime = Date.now();
|
||||
// validate the body and files of the request
|
||||
|
@ -64,6 +85,7 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
|
|||
};
|
||||
throw error;
|
||||
}
|
||||
|
||||
return Promise.all([
|
||||
checkClaimAvailability(name),
|
||||
createPublishParams(filePath, name, title, description, license, nsfw, thumbnail, channelName, channelClaimId),
|
||||
|
@ -85,17 +107,37 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
|
|||
// publish the asset
|
||||
return publish(publishParams, fileName, fileType, filePath);
|
||||
})
|
||||
.then(claimData => {
|
||||
logger.debug('Publish success >', claimData);
|
||||
.then(publishResults => {
|
||||
logger.info('Publish success >', publishResults);
|
||||
claimData = publishResults;
|
||||
({claimId} = claimData);
|
||||
|
||||
if (channelName) {
|
||||
return chainquery.claim.queries.getShortClaimIdFromLongClaimId(claimData.certificateId, channelName);
|
||||
} else {
|
||||
return chainquery.claim.queries.getShortClaimIdFromLongClaimId(claimId, name, claimData).catch(error => {
|
||||
return claimId.slice(0, 1);
|
||||
});
|
||||
}
|
||||
})
|
||||
.then(shortId => {
|
||||
let canonicalUrl;
|
||||
if (channelName) {
|
||||
canonicalUrl = createCanonicalLink({ asset: { ...claimData, channelShortId: shortId } });
|
||||
} else {
|
||||
canonicalUrl = createCanonicalLink({ asset: { ...claimData, shortId } })
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: 'publish completed successfully',
|
||||
data : {
|
||||
name,
|
||||
claimId : claimData.claimId,
|
||||
url : `${host}/${claimData.claimId}/${name}`, // for backwards compatability with app
|
||||
showUrl : `${host}/${claimData.claimId}/${name}`,
|
||||
serveUrl: `${host}/${claimData.claimId}/${name}${fileExtension}`,
|
||||
claimId,
|
||||
url : `${host}${canonicalUrl}`, // for backwards compatability with app
|
||||
showUrl : `${host}${canonicalUrl}`,
|
||||
serveUrl: `${host}${canonicalUrl}${fileExtension}`,
|
||||
pushTo : canonicalUrl,
|
||||
claimData,
|
||||
},
|
||||
});
|
||||
|
|
|
@ -9,6 +9,8 @@ const parsePublishApiRequestBody = require('../publish/parsePublishApiRequestBod
|
|||
const parsePublishApiRequestFiles = require('../publish/parsePublishApiRequestFiles.js');
|
||||
const authenticateUser = require('../publish/authentication.js');
|
||||
const createThumbnailPublishParams = require('../publish/createThumbnailPublishParams.js');
|
||||
const chainquery = require('chainquery');
|
||||
const createCanonicalLink = require('../../../../../utils/createCanonicalLink');
|
||||
|
||||
/*
|
||||
route to update a claim through the daemon
|
||||
|
@ -42,7 +44,7 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
|
|||
}
|
||||
|
||||
// define variables
|
||||
let channelName, channelId, channelPassword, description, fileName, filePath, fileType, gaStartTime, thumbnail, fileExtension, license, name, nsfw, thumbnailFileName, thumbnailFilePath, thumbnailFileType, title, claimRecord, metadata;
|
||||
let channelName, channelId, channelPassword, description, fileName, filePath, fileType, gaStartTime, thumbnail, fileExtension, license, name, nsfw, thumbnailFileName, thumbnailFilePath, thumbnailFileType, title, claimRecord, metadata, publishResult;
|
||||
// record the start time of the request
|
||||
gaStartTime = Date.now();
|
||||
|
||||
|
@ -57,19 +59,22 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
|
|||
// check channel authorization
|
||||
authenticateUser(channelName, channelId, channelPassword, user)
|
||||
.then(({ channelName, channelClaimId }) => {
|
||||
return db.Claim.findOne({
|
||||
where: {
|
||||
name,
|
||||
channelName,
|
||||
},
|
||||
});
|
||||
return chainquery.claim.queries.resolveClaimInChannel(name, channelClaimId).then(claim => claim.dataValues);
|
||||
})
|
||||
.then(claim => {
|
||||
return resolveUri(`${claim.name}#${claim.claimId}`);
|
||||
claimRecord = claim;
|
||||
|
||||
if (!files.file) {
|
||||
return Promise.all([
|
||||
db.File.findOne({ where: { name, claimId: claim.claim_id } }),
|
||||
resolveUri(`${claim.name}#${claim.claim_id}`),
|
||||
]);
|
||||
}
|
||||
|
||||
return [null, null];
|
||||
})
|
||||
.then(fullClaim => {
|
||||
claimRecord = fullClaim;
|
||||
logger.info('fullClaim', fullClaim);
|
||||
.then(([fileResult, resolution]) => {
|
||||
|
||||
metadata = Object.assign({}, {
|
||||
title : claimRecord.title,
|
||||
description: claimRecord.description,
|
||||
|
@ -89,9 +94,9 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
|
|||
if (files.file) {
|
||||
publishParams['file_path'] = filePath;
|
||||
} else {
|
||||
fileName = fullClaim.file_name;
|
||||
fileType = fullClaim.mime_type;
|
||||
publishParams['sources'] = fullClaim.claim.value.stream.source;
|
||||
fileName = fileResult.fileName;
|
||||
fileType = fileResult.fileType;
|
||||
publishParams['sources'] = resolution.claim.value.stream.source;
|
||||
}
|
||||
// publish the thumbnail, if one exists
|
||||
if (thumbnailFileName) {
|
||||
|
@ -103,26 +108,44 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
|
|||
const fp = files && files.file && files.file.path ? files.file.path : undefined;
|
||||
return publish(publishParams, fileName, fileType, fp);
|
||||
})
|
||||
.then(claimData => {
|
||||
// this may need to happen in ../publish/index.js as well
|
||||
if (claimData.error) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: claimData.message,
|
||||
.then(result => {
|
||||
publishResult = result;
|
||||
|
||||
if (channelName) {
|
||||
return chainquery.claim.queries.getShortClaimIdFromLongClaimId(result.certificateId, channelName);
|
||||
} else {
|
||||
return chainquery.claim.queries.getShortClaimIdFromLongClaimId(result.claimId, name, result).catch(error => {
|
||||
return result.claimId.slice(0, 1);
|
||||
});
|
||||
}
|
||||
const {claimId} = claimData;
|
||||
})
|
||||
.then(shortId => {
|
||||
let canonicalUrl;
|
||||
if (channelName) {
|
||||
canonicalUrl = createCanonicalLink({ asset: { ...publishResult, channelShortId: shortId } });
|
||||
} else {
|
||||
canonicalUrl = createCanonicalLink({ asset: { ...publishResult, shortId } })
|
||||
}
|
||||
|
||||
if (publishResult.error) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: publishResult.message,
|
||||
});
|
||||
}
|
||||
|
||||
const {claimId} = publishResult;
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: 'update successful',
|
||||
data : {
|
||||
name,
|
||||
channelName,
|
||||
channelId: claimData.certificateId,
|
||||
claimId,
|
||||
url : `${details.host}/${claimId}/${name}`, // for backwards compatability with app
|
||||
showUrl : `${details.host}/${claimId}/${name}`,
|
||||
claimData,
|
||||
url : `${details.host}${canonicalUrl}`, // for backwards compatability with app
|
||||
showUrl : `${details.host}${canonicalUrl}`,
|
||||
serveUrl: `${details.host}${canonicalUrl}${fileExtension}`,
|
||||
pushTo : canonicalUrl,
|
||||
claimData: publishResult,
|
||||
},
|
||||
});
|
||||
// record the publish end time and send to google analytics
|
||||
|
|
Loading…
Reference in a new issue