diff --git a/helpers/serveHelpers.js b/helpers/serveHelpers.js index a5e5b318..95ea5aab 100644 --- a/helpers/serveHelpers.js +++ b/helpers/serveHelpers.js @@ -47,9 +47,8 @@ module.exports = { if (filePath) { res.status(200).sendFile(filePath, options); } else { - // 'get' the file - // send the file - res.status(307).redirect(`/api/get/${name}/${claimId}`); + // res.status(307).redirect(`/api/get/${name}/${claimId}`); + res.status(400).json({success: false, message: 'that claim is not hosted locally by Spee .fine-print { + text-align: center; +} + .blue { color: #4156C5; } @@ -153,9 +157,7 @@ a, a:visited { .link--primary, .link--primary:visited { color: #4156C5; } -.link--primary.fine-print { - text-align: center; -} + .link--nav { color: black; border-bottom: 2px solid white; @@ -513,24 +515,25 @@ table { /* Show page */ -.video-show, .gifv-show, .image-show { - display: block; - width: 100%; -} -#video-player, .showlite-asset { +#video-player { display: block; margin: 0 auto; - background-color: #fff; + background-color: #fff; cursor: pointer; } #showlite-body #video-player { margin-top: 2%; - padding: 6px; - max-width: 50%; + padding: 6px; + max-width: 50%; border: 1px solid #d0d0d0; } -.showlite-asset { - max-width: 100%; + +.asset { + max-width: 100%; +} + +#showlite-body > .asset { + max-width: 50%; } /* item lists */ diff --git a/public/assets/css/mediaQueries.css b/public/assets/css/mediaQueries.css index 03ecbfdd..4f632183 100644 --- a/public/assets/css/mediaQueries.css +++ b/public/assets/css/mediaQueries.css @@ -36,7 +36,7 @@ padding-right: 1.5em; } - .showlite-asset { + #showlite-body > asset { max-width: 100%; } diff --git a/routes/api-routes.js b/routes/api-routes.js index bcd7a9da..f827997e 100644 --- a/routes/api-routes.js +++ b/routes/api-routes.js @@ -30,57 +30,6 @@ function createFileRecord ({ name, claimId, outpoint, height, address, nsfw, con }; } -// function getAssetByLongClaimId (fullClaimId, name) { -// logger.debug('...getting asset by claim Id...'); -// return new Promise((resolve, reject) => { -// // 1. check locally for claim -// checkForLocalAssetByClaimId(fullClaimId, name) -// .then(dataValues => { -// // if a result was found, return early with the result -// if (dataValues) { -// logger.debug('found a local file for this name and claimId'); -// resolve(dataValues); -// return; -// } -// logger.debug('no local file found for this name and claimId'); -// // 2. if no local claim, resolve and get the claim -// db.Claim -// .resolveClaim(name, fullClaimId) -// .then(resolveResult => { -// // if no result, return early (claim doesn't exist or isn't free) -// if (!resolveResult) { -// resolve(NO_CLAIM); -// return; -// } -// logger.debug('resolve result >> ', resolveResult.dataValues); -// let fileRecord = {}; -// // get the claim -// lbryApi.getClaim(`${name}#${fullClaimId}`) -// .then(getResult => { -// logger.debug('getResult >>', getResult); -// fileRecord = createFileRecord(resolveResult); -// fileRecord = addGetResultsToFileRecord(fileRecord, getResult); -// // insert a record in the File table & Update Claim table -// return db.File.create(fileRecord); -// }) -// .then(() => { -// logger.debug('File record successfully updated'); -// resolve(fileRecord); -// }) -// .catch(error => { -// reject(error); -// }); -// }) -// .catch(error => { -// reject(error); -// }); -// }) -// .catch(error => { -// reject(error); -// }); -// }); -// } - module.exports = (app) => { // route to run a claim_list request on the daemon app.get('/api/claim_list/:name', ({ ip, originalUrl, params }, res) => { @@ -93,30 +42,42 @@ module.exports = (app) => { errorHandlers.handleApiError('claim_list', originalUrl, ip, error, res); }); }); + // route to see if asset is available locally + app.get('/api/local/:name/:claimId', ({ ip, originalUrl, params }, res) => { + const name = params.name; + const claimId = params.claimId; + let isLocalFileAvailable = false; + db.File.findOne({where: {name, claimId}}) + .then(result => { + if (result) { + isLocalFileAvailable = true; + } + res.status(200).json({status: 'success', isLocalFileAvailable}); + }) + .catch(error => { + errorHandlers.handleApiError('get', originalUrl, ip, error, res); + }); + }); // route to get an asset app.get('/api/get/:name/:claimId', ({ ip, originalUrl, params }, res) => { - if (!params.name || !params.claimId) { - res.status(400).json({success: false, message: 'provide a claimId and/or a name'}); - } let fileRecord; - // 1. resolve the claim + // resolve and get the claim db.Claim.resolveClaim(params.name, params.claimId) .then(resolveResult => { if (!resolveResult) { throw new Error('No matching uri found in Claim table'); } fileRecord = createFileRecord(resolveResult); - // 2. get the claim + // get the claim return getClaim(`${params.name}#${params.claimId}`); }) .then(getResult => { - res.status(200).json({status: 'success', message: getResult}); - logger.debug('response was sent to the client'); fileRecord = addGetResultsToFileRecord(fileRecord, getResult); - // 3. insert a record for the claim into the File table + // insert a record for the claim into the File table return db.File.create(fileRecord); }) .then(() => { + res.status(200).json({status: 'success', message: 'content was successfully retrieved via lbrynet'}); logger.debug('File record successfully created'); }) .catch(error => { diff --git a/views/layouts/showlite.handlebars b/views/layouts/showlite.handlebars index 7fb7a400..a97a6f02 100644 --- a/views/layouts/showlite.handlebars +++ b/views/layouts/showlite.handlebars @@ -17,7 +17,7 @@ {{ googleAnalytics }} - {{> getAsset}} + {{{ body }}} diff --git a/views/partials/asset.handlebars b/views/partials/asset.handlebars index 29d3ef28..3229996d 100644 --- a/views/partials/asset.handlebars +++ b/views/partials/asset.handlebars @@ -1,41 +1,26 @@ -{{#ifConditional claimInfo.contentType '===' 'video/mp4'}} - {{#ifConditional claimInfo.fileExt '===' 'gifv'}} - - {{else}} - - - {{/ifConditional}} -{{else}} - - - -{{/ifConditional}} - -
- - -
@@ -44,9 +29,16 @@ const getAssetFunctions = { showAsset: function () { const searchMessage = document.getElementById('search-message'); + const assetHolder = document.getElementById('asset-holder'); const asset = document.getElementById('asset'); searchMessage.hidden = true; - asset.hidden = false; + assetHolder.hidden = false; + asset.setAttribute('src', `/{{claimInfo.claimId}}/{{claimInfo.name}}.{{claimInfo.fileExt}}`); + }, + showSearchMessage: function (msg) { + console.log(msg); + const searchMessage = document.getElementById('search-message'); + searchMessage.hidden = false; }, showFailureMessage: function (msg) { console.log(msg); @@ -54,26 +46,49 @@ const failureMessage = document.getElementById('failure-message'); searchMessage.hidden = true; failureMessage.hidden = false; + failureMessage.innerText(msg); }, - displayAsset: function(contentType, source) { - + checkClaimAvailability: function (claimName, claimId) { + console.log(`getting ${claimName}#${claimId}}`) + var uri = `/api/get/${claimName}/${claimId}`; + var xhr = new XMLHttpRequest(); + var that = this; + xhr.open("GET", uri, true); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + const response = JSON.parse(xhr.response); + if (xhr.status == 200 && response.message === false) { + that.showSearchMessage(); + that.getAsset(claimName, claimId) + } else { + console.log('get failed:', response); + that.showFailureMessage('Well this sucks, but we can\'t seem to phone home'); + } + } else { + console.log('xhr.readyState', xhr.readyState); + } + }; + // Initiate a multipart/form-data upload + xhr.send(); }, getAsset: function(claimName, claimId) { console.log(`getting ${claimName}#${claimId}}`) var uri = `/api/get/${claimName}/${claimId}`; var xhr = new XMLHttpRequest(); + var that = this; xhr.open("GET", uri, true); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { + const response = JSON.parse(xhr.response); if (xhr.status == 200) { - console.log('get returned successfully', xhr.response); - this.showAsset(); + console.log('get returned successfully', response); + that.showAsset(); } else { - console.log('get failed:', xhr.response); + console.log('get failed:', response); + that.showFailureMessage('Hmmm, looks like no peers have your content. How anti-social!'); } } else { console.log('xhr.readyState', xhr.readyState); - this.showFailureMessage(xhr.readyState.message); } }; // Initiate a multipart/form-data upload @@ -81,4 +96,6 @@ }, } + getAssetFunctions.checkClaimAvailability('{{claimInfo.name}}', '{{claimInfo.claimId}}'); + \ No newline at end of file diff --git a/views/show-local.handlebars b/views/show-local.handlebars deleted file mode 100644 index 7282a522..00000000 --- a/views/show-local.handlebars +++ /dev/null @@ -1,17 +0,0 @@ -
-
- - {{claimInfo.title}} -
-
- -
- {{> asset}} -
-
- -
- {{> assetInfo}} -
-
-
\ No newline at end of file diff --git a/views/showLite-local.handlebars b/views/showLite-local.handlebars deleted file mode 100644 index 21ffd8b4..00000000 --- a/views/showLite-local.handlebars +++ /dev/null @@ -1,2 +0,0 @@ -{{> asset }} -hosted via spee<h \ No newline at end of file diff --git a/views/showLite.handlebars b/views/showLite.handlebars index 21ffd8b4..ef25b602 100644 --- a/views/showLite.handlebars +++ b/views/showLite.handlebars @@ -1,2 +1,2 @@ {{> asset }} -hosted via spee<h \ No newline at end of file +hosted via Spee<h \ No newline at end of file