spee.ch/server/models/utils/createFileRecordData.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

const getMediaDimensions = require('../../utils/getMediaDimensions.js');
2019-05-24 22:39:46 +02:00
async function createFileRecordDataAfterGet(resolveResult, getResult) {
const { name, claimId, outpoint, contentType: fileType } = resolveResult;
2018-07-27 02:57:26 +02:00
2019-05-24 22:39:46 +02:00
const { file_name: fileName, download_path: filePath } = getResult;
2018-07-27 02:57:26 +02:00
2019-05-24 22:39:46 +02:00
const { height: fileHeight, width: fileWidth } = await getMediaDimensions(fileType, filePath);
2018-07-27 02:57:26 +02:00
return {
name,
claimId,
outpoint,
fileHeight,
fileWidth,
fileName,
filePath,
fileType,
};
}
2019-05-24 22:39:46 +02:00
async function createFileRecordDataAfterPublish(
fileName,
fileType,
publishParams,
publishResultsOutput
) {
const { name, file_path: filePath } = publishParams;
2018-07-27 02:57:26 +02:00
2019-05-24 22:39:46 +02:00
const { claim_id: claimId, txid, nout } = publishResultsOutput;
2018-07-27 02:57:26 +02:00
2019-05-24 22:39:46 +02:00
const { height: fileHeight, width: fileWidth } = await getMediaDimensions(fileType, filePath);
return {
name,
claimId,
outpoint: `${txid}:${nout}`,
fileHeight,
fileWidth,
fileName,
filePath,
fileType,
};
}
module.exports = {
createFileRecordDataAfterGet,
createFileRecordDataAfterPublish,
};