changed File create to upsert
This commit is contained in:
parent
a6ccc9b682
commit
50ffc42b57
4 changed files with 25 additions and 5 deletions
|
@ -69,6 +69,7 @@ db.upsert = (Model, values, condition, tableName) => {
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
logger.error(`${tableName}.upsert error`, error);
|
logger.error(`${tableName}.upsert error`, error);
|
||||||
|
throw error;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ module.exports = (app) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// route to see if asset is available locally
|
// route to see if asset is available locally
|
||||||
app.get('/api/check-local-claim/:name/:claimId', ({ ip, originalUrl, params }, res) => {
|
app.get('/api/local-file-available/:name/:claimId', ({ ip, originalUrl, params }, res) => {
|
||||||
const name = params.name;
|
const name = params.name;
|
||||||
const claimId = params.claimId;
|
const claimId = params.claimId;
|
||||||
let isLocalFileAvailable = false;
|
let isLocalFileAvailable = false;
|
||||||
|
@ -60,8 +60,10 @@ module.exports = (app) => {
|
||||||
});
|
});
|
||||||
// route to get an asset
|
// route to get an asset
|
||||||
app.get('/api/get-claim/:name/:claimId', ({ ip, originalUrl, params }, res) => {
|
app.get('/api/get-claim/:name/:claimId', ({ ip, originalUrl, params }, res) => {
|
||||||
|
const name = params.name;
|
||||||
|
const claimId = params.claimId;
|
||||||
// resolve the claim
|
// resolve the claim
|
||||||
db.Claim.resolveClaim(params.name, params.claimId)
|
db.Claim.resolveClaim(name, claimId)
|
||||||
.then(resolveResult => {
|
.then(resolveResult => {
|
||||||
// make sure a claim actually exists at that uri
|
// make sure a claim actually exists at that uri
|
||||||
if (!resolveResult) {
|
if (!resolveResult) {
|
||||||
|
@ -69,11 +71,11 @@ module.exports = (app) => {
|
||||||
}
|
}
|
||||||
let fileData = createFileData(resolveResult);
|
let fileData = createFileData(resolveResult);
|
||||||
// get the claim
|
// get the claim
|
||||||
return Promise.all([fileData, getClaim(`${params.name}#${params.claimId}`)]);
|
return Promise.all([fileData, getClaim(`${name}#${claimId}`)]);
|
||||||
})
|
})
|
||||||
.then(([ fileData, getResult ]) => {
|
.then(([ fileData, getResult ]) => {
|
||||||
fileData = addGetResultsToFileData(fileData, getResult);
|
fileData = addGetResultsToFileData(fileData, getResult);
|
||||||
return Promise.all([db.File.create(fileData), getResult]); // note: should be upsert
|
return Promise.all([db.upsert(db.File, fileData, {name, claimId}, 'File'), getResult]);
|
||||||
})
|
})
|
||||||
.then(([ fileRecord, {message, completed} ]) => {
|
.then(([ fileRecord, {message, completed} ]) => {
|
||||||
res.status(200).json({ status: 'success', message, completed });
|
res.status(200).json({ status: 'success', message, completed });
|
||||||
|
|
17
testpage.html
Normal file
17
testpage.html
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Test Page</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<img src="https://staging.spee.ch/zackmath"/>
|
||||||
|
<img src="https://staging.spee.ch/8/zackmath"/>
|
||||||
|
<img src="https://staging.spee.ch/zackmath.ext"/>
|
||||||
|
<img src="https://staging.spee.ch/8/zackmath.ext"/>
|
||||||
|
<video width="50%" controls poster="https://spee.ch/assets/img/video_thumb_default.png" src="https://staging.spee.ch/LBRY-Hype"></video>
|
||||||
|
<video width="50%" controls poster="https://spee.ch/assets/img/video_thumb_default.png" src="https://staging.spee.ch/a/LBRY-Hype"></video>
|
||||||
|
<video width="50%" controls poster="https://spee.ch/assets/img/video_thumb_default.png" src="https://staging.spee.ch/LBRY-Hype.test"></video>
|
||||||
|
<video width="50%" controls poster="https://spee.ch/assets/img/video_thumb_default.png" src="https://staging.spee.ch/a/LBRY-Hype.test"></video>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -67,7 +67,7 @@
|
||||||
},
|
},
|
||||||
checkClaimAvailability: function (claimName, claimId) {
|
checkClaimAvailability: function (claimName, claimId) {
|
||||||
console.log(`checking local availability for ${claimName}#${claimId}`)
|
console.log(`checking local availability for ${claimName}#${claimId}`)
|
||||||
var uri = `/api/check-local-claim/${claimName}/${claimId}`;
|
var uri = `/api/local-file-available/${claimName}/${claimId}`;
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
var that = this;
|
var that = this;
|
||||||
xhr.open("GET", uri, true);
|
xhr.open("GET", uri, true);
|
||||||
|
|
Loading…
Reference in a new issue