Development #287

Merged
bones7242 merged 58 commits from development into master 2017-12-11 20:53:02 +01:00
4 changed files with 25 additions and 5 deletions
Showing only changes of commit 50ffc42b57 - Show all commits

View file

@ -69,6 +69,7 @@ db.upsert = (Model, values, condition, tableName) => {
})
.catch(function (error) {
logger.error(`${tableName}.upsert error`, error);
throw error;
});
};

View file

@ -43,7 +43,7 @@ module.exports = (app) => {
});
});
// 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 claimId = params.claimId;
let isLocalFileAvailable = false;
@ -60,8 +60,10 @@ module.exports = (app) => {
});
// route to get an asset
app.get('/api/get-claim/:name/:claimId', ({ ip, originalUrl, params }, res) => {
const name = params.name;
const claimId = params.claimId;
// resolve the claim
db.Claim.resolveClaim(params.name, params.claimId)
db.Claim.resolveClaim(name, claimId)
.then(resolveResult => {
// make sure a claim actually exists at that uri
if (!resolveResult) {
@ -69,11 +71,11 @@ module.exports = (app) => {
}
let fileData = createFileData(resolveResult);
// get the claim
return Promise.all([fileData, getClaim(`${params.name}#${params.claimId}`)]);
return Promise.all([fileData, getClaim(`${name}#${claimId}`)]);
})
.then(([ 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} ]) => {
res.status(200).json({ status: 'success', message, completed });

17
testpage.html Normal file
View 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>

View file

@ -67,7 +67,7 @@
},
checkClaimAvailability: function (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 that = this;
xhr.open("GET", uri, true);