updated serve route to use default content_type image/jpeg
This commit is contained in:
parent
bd53a27c35
commit
64b1b720ae
4 changed files with 63 additions and 25 deletions
|
@ -2,8 +2,8 @@ var axios = require('axios');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
publishClaim: function(publishParams){
|
publishClaim: function(publishParams){
|
||||||
console.log("publish params:>", publishParams);
|
|
||||||
var deferred = new Promise(function(resolve, reject){
|
var deferred = new Promise(function(resolve, reject){
|
||||||
|
console.log(">> lbryApi >> publishClaim:", publishParams);
|
||||||
axios.post('http://localhost:5279/lbryapi', {
|
axios.post('http://localhost:5279/lbryapi', {
|
||||||
"method": "publish",
|
"method": "publish",
|
||||||
"params": publishParams
|
"params": publishParams
|
||||||
|
@ -19,11 +19,12 @@ module.exports = {
|
||||||
},
|
},
|
||||||
getClaim: function(uri){
|
getClaim: function(uri){
|
||||||
var deferred = new Promise(function(resolve, reject){
|
var deferred = new Promise(function(resolve, reject){
|
||||||
|
console.log(">> lbryApi >> getClaim:", uri);
|
||||||
axios.post('http://localhost:5279/lbryapi', {
|
axios.post('http://localhost:5279/lbryapi', {
|
||||||
"method": "get",
|
"method": "get",
|
||||||
"params": { "uri": uri, "timeout": 30}
|
"params": { "uri": uri, "timeout": 20}
|
||||||
}).then(function (getResponse) {
|
}).then(function (getResponse) {
|
||||||
console.log(">> 'get claim' success...");
|
console.log(">> 'get' success");
|
||||||
//check to make sure the daemon didn't just time out (or otherwise send an error that appears to be a success response)
|
//check to make sure the daemon didn't just time out (or otherwise send an error that appears to be a success response)
|
||||||
if (getResponse.data.result.error){
|
if (getResponse.data.result.error){
|
||||||
reject(getResponse.data.result.error);
|
reject(getResponse.data.result.error);
|
||||||
|
@ -34,7 +35,7 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
resolve(getResponse.data);
|
resolve(getResponse.data);
|
||||||
}).catch(function(getUriError){
|
}).catch(function(getUriError){
|
||||||
console.log(">> 'get' error.");
|
console.log(">> 'get' error");
|
||||||
// reject the promise with an error message
|
// reject the promise with an error message
|
||||||
reject(getUriError);
|
reject(getUriError);
|
||||||
return;
|
return;
|
||||||
|
@ -44,15 +45,15 @@ module.exports = {
|
||||||
},
|
},
|
||||||
getClaimsList: function(claimName){
|
getClaimsList: function(claimName){
|
||||||
var deferred = new Promise(function(resolve, reject){
|
var deferred = new Promise(function(resolve, reject){
|
||||||
console.log(">> claims_list for", claimName)
|
console.log(">> lbryApi >> getClaimList:", claimName);
|
||||||
axios.post('http://localhost:5279/lbryapi', {
|
axios.post('http://localhost:5279/lbryapi', {
|
||||||
method: "claim_list",
|
method: "claim_list",
|
||||||
params: { name: claimName }
|
params: { name: claimName }
|
||||||
}).then(function (response) {
|
}).then(function (response) {
|
||||||
console.log(">> claim_list success");
|
console.log(">> 'claim_list' success");
|
||||||
resolve(response.data);
|
resolve(response.data);
|
||||||
}).catch(function(error){
|
}).catch(function(error){
|
||||||
console.log(">> claim_list error");
|
console.log(">> 'claim_list' error");
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -60,12 +61,12 @@ module.exports = {
|
||||||
},
|
},
|
||||||
resolveUri: function(uri){
|
resolveUri: function(uri){
|
||||||
var deferred = new Promise(function(resolve, reject){
|
var deferred = new Promise(function(resolve, reject){
|
||||||
console.log(">> resolve uri for", uri)
|
console.log(">> lbryApi >> resolveUri:", claimName);
|
||||||
axios.post('http://localhost:5279/lbryapi', {
|
axios.post('http://localhost:5279/lbryapi', {
|
||||||
"method": "resolve",
|
"method": "resolve",
|
||||||
"params": { "uri": uri}
|
"params": { "uri": uri}
|
||||||
}).then(function(response){
|
}).then(function(response){
|
||||||
console.log(response.data);
|
console.log(">> 'resolve' success");
|
||||||
resolve(response.data);
|
resolve(response.data);
|
||||||
}).catch(function(error){
|
}).catch(function(error){
|
||||||
console.log(">> 'resolve' error");
|
console.log(">> 'resolve' error");
|
||||||
|
|
|
@ -73,17 +73,20 @@ function getAllFreePublicClaims(claimName){ // note: work in progress
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getClaimBasedOnNameOnly: function(claimName){
|
getClaimBasedOnNameOnly: function(claimName){
|
||||||
var deferred = new Promise(function (resolve, reject){
|
var deferred = new Promise(function (resolve, reject){
|
||||||
console.log(">> get all free claims for", claimName);
|
console.log(">> lbryHelpers >> getClaim BasedOnNameOnly:", claimName);
|
||||||
// promise to get all free public claims
|
// promise to get all free public claims
|
||||||
getAllFreePublicClaims(claimName)
|
getAllFreePublicClaims(claimName)
|
||||||
.then(function(freePublicClaimList){
|
.then(function(freePublicClaimList){
|
||||||
var freePublicClaimUri = freePublicClaimList[0].name + "#" + freePublicClaimList[0].claim_id;
|
var freePublicClaimUri = freePublicClaimList[0].name + "#" + freePublicClaimList[0].claim_id;
|
||||||
console.log(">> your free public claim URI:", freePublicClaimUri);
|
console.log(">> successfully received free public claim URI:", freePublicClaimUri);
|
||||||
// promise to get the chosen uri
|
// promise to get the chosen uri
|
||||||
lbryApi.getClaim(freePublicClaimUri)
|
lbryApi.getClaim(freePublicClaimUri)
|
||||||
.then(function(data){
|
.then(function(data){
|
||||||
console.log(">> dl path =", data.result.download_path)
|
resolve({
|
||||||
resolve(data.result.download_path)
|
fileName: data.result.file_name,
|
||||||
|
directory: data.result.download_directory,
|
||||||
|
contentType: data.result.metadata.stream.source.contentType
|
||||||
|
});
|
||||||
}).catch(function(error){
|
}).catch(function(error){
|
||||||
reject(error)
|
reject(error)
|
||||||
});
|
});
|
||||||
|
@ -98,12 +101,15 @@ module.exports = {
|
||||||
to do: need to pass the URI through a test to see if it is free and public. Right now it is jumping straight to 'get'ing and serving the asset.
|
to do: need to pass the URI through a test to see if it is free and public. Right now it is jumping straight to 'get'ing and serving the asset.
|
||||||
*/
|
*/
|
||||||
var deferred = new Promise(function (resolve, reject){
|
var deferred = new Promise(function (resolve, reject){
|
||||||
console.log(">> get claim based on URI:", uri);
|
console.log(">> lbryHelpers >> getClaimBasedOnUri:", uri);
|
||||||
// promise to get the chosen uri
|
// promise to get the chosen uri
|
||||||
lbryApi.getClaim(uri)
|
lbryApi.getClaim(uri)
|
||||||
.then(function(data){
|
.then(function(data){
|
||||||
console.log(">> dl path =", data.result.download_path)
|
resolve({
|
||||||
resolve(data.result.download_path)
|
fileName: data.result.file_name,
|
||||||
|
directory: data.result.download_directory,
|
||||||
|
contentType: data.result.metadata.stream.source.contentType
|
||||||
|
});
|
||||||
}).catch(function(error){
|
}).catch(function(error){
|
||||||
reject(error)
|
reject(error)
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,3 +1,30 @@
|
||||||
|
function serveFile(fileInfo, res){
|
||||||
|
var options = {
|
||||||
|
root: fileInfo.directory,
|
||||||
|
headers: { "contentType": fileInfo.contentType}
|
||||||
|
};
|
||||||
|
switch (fileInfo.contentType){
|
||||||
|
case "image/jpeg":
|
||||||
|
console.log("sending jpeg");
|
||||||
|
break;
|
||||||
|
case "image/gif":
|
||||||
|
console.log("sending gif");
|
||||||
|
break;
|
||||||
|
case "image/png":
|
||||||
|
console.log("sending png");
|
||||||
|
break;
|
||||||
|
case "video/mp4":
|
||||||
|
console.log("sending mp4");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log("sending unknown file type as .jpeg");
|
||||||
|
options["headers"]["contentType"] = "image/jpeg";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
console.log('options', options);
|
||||||
|
res.status(200).sendFile(fileInfo.fileName, options);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = function(app, routeHelpers, lbryHelpers, ua, googleAnalyticsId){
|
module.exports = function(app, routeHelpers, lbryHelpers, ua, googleAnalyticsId){
|
||||||
// route to fetch one free public claim
|
// route to fetch one free public claim
|
||||||
app.get("/:name/:claim_id", function(req, res){
|
app.get("/:name/:claim_id", function(req, res){
|
||||||
|
@ -6,11 +33,10 @@ module.exports = function(app, routeHelpers, lbryHelpers, ua, googleAnalyticsId)
|
||||||
console.log(">> GET request on /" + uri);
|
console.log(">> GET request on /" + uri);
|
||||||
// create promise
|
// create promise
|
||||||
lbryHelpers.getClaimBasedOnUri(uri)
|
lbryHelpers.getClaimBasedOnUri(uri)
|
||||||
.then(function(filePath){
|
.then(function(fileInfo){
|
||||||
console.log("/:name/:claim_id success.");
|
console.log("/:name/:claim_id success.", fileInfo.fileName);
|
||||||
res.status(200).sendFile(filePath);
|
serveFile(fileInfo, res);
|
||||||
})
|
}).catch(function(error){
|
||||||
.catch(function(error){
|
|
||||||
console.log("/:name/:claim_id error:", error)
|
console.log("/:name/:claim_id error:", error)
|
||||||
routeHelpers.handleRequestError(error, res);
|
routeHelpers.handleRequestError(error, res);
|
||||||
});
|
});
|
||||||
|
@ -21,9 +47,9 @@ module.exports = function(app, routeHelpers, lbryHelpers, ua, googleAnalyticsId)
|
||||||
console.log(">> GET request on /" + req.params.name);
|
console.log(">> GET request on /" + req.params.name);
|
||||||
// create promise
|
// create promise
|
||||||
lbryHelpers.getClaimBasedOnNameOnly(req.params.name)
|
lbryHelpers.getClaimBasedOnNameOnly(req.params.name)
|
||||||
.then(function(filePath){
|
.then(function(fileInfo){
|
||||||
console.log("/:name success.")
|
console.log("/:name success.", fileInfo.fileName);
|
||||||
res.status(200).sendFile(filePath);
|
serveFile(fileInfo, res);
|
||||||
}).catch(function(error){
|
}).catch(function(error){
|
||||||
console.log("/:name error:", error);
|
console.log("/:name error:", error);
|
||||||
routeHelpers.handleRequestError(error, res);
|
routeHelpers.handleRequestError(error, res);
|
||||||
|
|
|
@ -10,10 +10,15 @@ module.exports = function(app, path, siofu, socketHelpers, ua, googleAnalyticsId
|
||||||
var uploader = new siofu();
|
var uploader = new siofu();
|
||||||
uploader.dir = path.join(__dirname, '../../Uploads');
|
uploader.dir = path.join(__dirname, '../../Uploads');
|
||||||
uploader.listen(socket);
|
uploader.listen(socket);
|
||||||
|
uploader.on("start", function(event){
|
||||||
|
if (/\.exe$/.test(event.file.name)) {
|
||||||
|
uploader.abort(event.file.id, socket);
|
||||||
|
}
|
||||||
|
});
|
||||||
uploader.on("error", function(event){
|
uploader.on("error", function(event){
|
||||||
console.log("an error occured while uploading", event.error);
|
console.log("an error occured while uploading", event.error);
|
||||||
socket.emit("publish-status", event.error)
|
socket.emit("publish-status", event.error)
|
||||||
})
|
});
|
||||||
uploader.on("saved", function(event){
|
uploader.on("saved", function(event){
|
||||||
console.log("saved " + event.file.name);
|
console.log("saved " + event.file.name);
|
||||||
if (event.file.success){
|
if (event.file.success){
|
||||||
|
|
Loading…
Reference in a new issue