fixed publish analytics
This commit is contained in:
parent
44f9df1766
commit
25500a592e
3 changed files with 9 additions and 10 deletions
|
@ -1,11 +1,8 @@
|
|||
var fs = require('fs');
|
||||
var lbryApi = require('../helpers/lbryApi.js');
|
||||
var config = require('config');
|
||||
var ua = require('universal-analytics');
|
||||
|
||||
var walledAddress = config.get('WalletConfig.lbryAddress');
|
||||
var googleAnalyticsId = config.get('AnalyticsConfig.googleId');
|
||||
var visitor = ua(googleAnalyticsId, {https: true});
|
||||
|
||||
function handlePublishError(error) {
|
||||
if (error.code === "ECONNREFUSED"){
|
||||
|
@ -44,22 +41,22 @@ function deleteTemporaryFile(filepath) {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
publish: function(name, filepath, license, nsfw, socket) {
|
||||
publish: function(name, filepath, license, nsfw, socket, visitor) {
|
||||
// update the client
|
||||
socket.emit("publish-status", "Your image is being published (this might take a second)...");
|
||||
visitor.event("Publish Route", "Publish Request", name, filepath).send();
|
||||
visitor.event("Publish Route", "Publish Request", filepath).send();
|
||||
// create the publish object
|
||||
var publishParams = createPublishParams(name, filepath, license, nsfw);
|
||||
// get a promise to publish
|
||||
lbryApi.publishClaim(publishParams)
|
||||
.then(function(data){
|
||||
visitor.event("Publish", "Publish Success", name, filepath).send();
|
||||
visitor.event("Publish Route", "Publish Success", filepath).send();
|
||||
console.log("publish promise success. Tx info:", data)
|
||||
socket.emit("publish-complete", {name: name, result: data.result});
|
||||
deleteTemporaryFile(filepath);
|
||||
})
|
||||
.catch(function(error){
|
||||
visitor.event("Publish Route", "Publish Failure", name, filepath).send();
|
||||
visitor.event("Publish Route", "Publish Failure", filepath).send();
|
||||
console.log("error:", error);
|
||||
socket.emit("publish-failure", handlePublishError(error));
|
||||
deleteTemporaryFile(filepath);
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
module.exports = function(app, path, siofu, socketHelpers) {
|
||||
module.exports = function(app, path, siofu, socketHelpers, ua, googleAnalyticsId) {
|
||||
var http = require('http').Server(app);
|
||||
var io = require('socket.io')(http);
|
||||
|
||||
io.on('connection', function(socket){
|
||||
console.log('a user connected via sockets');
|
||||
// create visitor record
|
||||
var visitor = ua(googleAnalyticsId, {https: true});
|
||||
// attach upload listeners
|
||||
var uploader = new siofu();
|
||||
uploader.dir = path.join(__dirname, '../../Uploads');
|
||||
|
@ -16,7 +18,7 @@ module.exports = function(app, path, siofu, socketHelpers) {
|
|||
console.log("saved " + event.file.name);
|
||||
if (event.file.success){
|
||||
socket.emit("publish-status", "file upload successfully completed");
|
||||
socketHelpers.publish(event.file.meta.name, event.file.pathName, event.file.meta.license, event.file.meta.nsfw, socket)
|
||||
socketHelpers.publish(event.file.meta.name, event.file.pathName, event.file.meta.license, event.file.meta.nsfw, socket, visitor)
|
||||
} else {
|
||||
socket.emit("publish-failure", "file uploaded, but with errors")
|
||||
};
|
||||
|
|
|
@ -57,7 +57,7 @@ require("./routes/serve-routes.js")(app, routeHelpers, lbryApi, ua, googleAnalyt
|
|||
require("./routes/home-routes.js")(app);
|
||||
|
||||
// wrap the server in socket.io to intercept incoming sockets requests
|
||||
var http = require("./routes/sockets-routes.js")(app, path, siofu, socketHelpers);
|
||||
var http = require("./routes/sockets-routes.js")(app, path, siofu, socketHelpers, ua, googleAnalyticsId);
|
||||
|
||||
// start server
|
||||
http.listen(PORT, function() {
|
||||
|
|
Loading…
Reference in a new issue