simplified File data creation
This commit is contained in:
parent
2d7dbdc8a0
commit
82f56ccc9a
3 changed files with 10 additions and 24 deletions
|
@ -1,7 +0,0 @@
|
|||
const addGetResultsToFileData = (fileInfo, getResult) => {
|
||||
fileInfo.fileName = getResult.file_name;
|
||||
fileInfo.filePath = getResult.download_path;
|
||||
return fileInfo;
|
||||
};
|
||||
|
||||
module.exports = addGetResultsToFileData;
|
|
@ -1,14 +1,11 @@
|
|||
const createFileData = ({ name, claimId, outpoint, height, address, nsfw, contentType }) => {
|
||||
const createFileData = ({ name, claimId, outpoint, contentType: fileType }, { file_name: fileName, download_path: filePath }) => {
|
||||
return {
|
||||
name,
|
||||
claimId,
|
||||
outpoint,
|
||||
height,
|
||||
address,
|
||||
fileName: '',
|
||||
filePath: '',
|
||||
fileType: contentType,
|
||||
nsfw,
|
||||
fileName,
|
||||
filePath,
|
||||
fileType,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const { getClaim } = require('../../../../lbrynet');
|
||||
const addGetResultsToFileData = require('./addGetResultsToFileData.js');
|
||||
const createFileData = require('./createFileData.js');
|
||||
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
|
||||
const db = require('../../../../models');
|
||||
|
@ -13,15 +12,11 @@ const db = require('../../../../models');
|
|||
const claimGet = ({ ip, originalUrl, params }, res) => {
|
||||
const name = params.name;
|
||||
const claimId = params.claimId;
|
||||
let fileData;
|
||||
let resolveResult;
|
||||
let getResult;
|
||||
let message;
|
||||
let completed;
|
||||
// resolve the claim
|
||||
db.Claim.resolveClaim(name, claimId)
|
||||
.then(result => {
|
||||
// make sure a claim actually exists at that uri
|
||||
if (!result) {
|
||||
throw new Error('No matching uri found in Claim table');
|
||||
}
|
||||
|
@ -30,13 +25,14 @@ const claimGet = ({ ip, originalUrl, params }, res) => {
|
|||
})
|
||||
.then(result => {
|
||||
getResult = result;
|
||||
fileData = createFileData(resolveResult);
|
||||
fileData = addGetResultsToFileData(fileData, getResult);
|
||||
const upsertCriteria = { name, claimId};
|
||||
return db.upsert(db.File, fileData, upsertCriteria, 'File');
|
||||
})
|
||||
.then(() => {
|
||||
({ message, completed } = getResult);
|
||||
const fileData = createFileData(resolveResult, getResult);
|
||||
const upsertCriteria = { name, claimId};
|
||||
return db.upsert(db.File, fileData, upsertCriteria, 'File')
|
||||
})
|
||||
.then(() => {
|
||||
const { message, completed } = getResult;
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message,
|
||||
|
|
Loading…
Reference in a new issue