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

70 lines
1.2 KiB
JavaScript
Raw Normal View History

const getMediaDimensions = require('../../utils/getMediaDimensions.js');
async function createFileRecordDataAfterGet (resolveResult, getResult) {
2018-07-27 02:57:26 +02:00
const {
name,
claimId,
outpoint,
contentType: fileType,
} = resolveResult;
const {
file_name: fileName,
download_path: filePath,
} = getResult;
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,
};
}
async function createFileRecordDataAfterPublish (fileName, fileType, publishParams, publishResults) {
2018-07-27 02:57:26 +02:00
const {
name,
file_path: filePath,
} = publishParams;
const {
claim_id: claimId,
txid,
nout,
} = publishResults;
const {
height: fileHeight,
width: fileWidth,
} = await getMediaDimensions(fileType, filePath);
2018-11-07 23:51:06 +01:00
const obj = {
name,
claimId,
outpoint: `${txid}:${nout}`,
fileHeight,
fileWidth,
fileName,
filePath,
fileType,
};
2018-11-07 23:51:06 +01:00
console.log('createFileRecordDataAfterPublish return:', obj);
return obj;
}
module.exports = {
createFileRecordDataAfterGet,
createFileRecordDataAfterPublish,
};