Upload refactor #242
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"WalletConfig": {
|
||||
"LbryClaimAddress": null,
|
||||
"LbryChangeAddress": null,
|
||||
"DefaultChannel": null
|
||||
},
|
||||
"AnalyticsConfig":{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"WalletConfig": {
|
||||
"DefaultChannel": "@speechDev"
|
||||
"DefaultChannel": "@speechDev",
|
||||
"LbryChangeAddress": "bPsZ4wmrNUsn7gMP9cZ9G6RjM5RpuJAeTt"
|
||||
},
|
||||
"AnalyticsConfig":{
|
||||
"GoogleId": "UA-100747990-1"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"WalletConfig": {
|
||||
"DefaultChannel": "@speech"
|
||||
"DefaultChannel": "@speech",
|
||||
"LbryChangeAddress": null
|
||||
},
|
||||
"AnalyticsConfig":{
|
||||
"GoogleId": "UA-60403362-3"
|
||||
|
|
|
@ -11,9 +11,6 @@ module.exports = {
|
|||
if (!body.name) {
|
||||
throw new Error('no name field found in request');
|
||||
}
|
||||
if (!body.nsfw) {
|
||||
throw new Error('no nsfw field found in request');
|
||||
}
|
||||
if (!files) {
|
||||
throw new Error('no files found in request');
|
||||
}
|
||||
|
@ -94,7 +91,7 @@ module.exports = {
|
|||
case '0':
|
||||
return false;
|
||||
default:
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
},
|
||||
cleanseChannelName (channelName) {
|
||||
|
@ -138,7 +135,8 @@ module.exports = {
|
|||
license,
|
||||
nsfw,
|
||||
},
|
||||
claim_address: config.get('WalletConfig.LbryClaimAddress'),
|
||||
claim_address : config.get('WalletConfig.LbryClaimAddress'),
|
||||
change_address: config.get('WalletConfig.LbryChangeAddress'),
|
||||
};
|
||||
// add thumbnail to channel if video
|
||||
if (thumbnail !== null) {
|
||||
|
|
|
@ -44,8 +44,6 @@
|
|||
"sequelize": "^4.1.0",
|
||||
"sequelize-cli": "^3.0.0-3",
|
||||
"sleep": "^5.1.1",
|
||||
"socket.io": "^2.0.1",
|
||||
"socketio-file-upload": "^0.6.0",
|
||||
"universal-analytics": "^0.4.13",
|
||||
"winston": "^2.3.1",
|
||||
"winston-slack-webhook": "billbitt/winston-slack-webhook"
|
||||
|
|
|
@ -81,7 +81,7 @@ function publishStagedFile(event) {
|
|||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
// validate, submit, and handle response
|
||||
validateFilePublishSubmission(stagedFiles, claimName, channelName)
|
||||
.then(() => {
|
||||
uploader.submitFiles(stagedFiles);
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
publishFile(stagedFiles[0], claimName);
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.name === 'FileError') {
|
||||
|
@ -96,4 +96,37 @@ function publishStagedFile(event) {
|
|||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
}
|
||||
return;
|
||||
})
|
||||
};
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
};
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
var publishFile = function (file, name) {
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
var uri = "/api/publish";
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
var xhr = new XMLHttpRequest();
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
var fd = new FormData();
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
console.log('publish file, file:', file);
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
console.log('publish file, name:', name);
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
fd.append('file', file);
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
fd.append('name', name);
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
xhr.upload.addEventListener("progress", function(e) {
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
if (e.lengthComputable) {
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
var percentage = Math.round((e.loaded * 100) / e.total);
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
console.log('progress:', percentage);
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
}
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
}, false);
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
xhr.upload.addEventListener("load", function(e){
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
console.log('loaded 100%');
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
}, false);
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
xhr.open("POST", uri, true);
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
xhr.onreadystatechange = function() {
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
alert(xhr.responseText); // handle response.
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
} else {
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
console.log('xhr.readyState', xhr.readyState, 'xhr.status', xhr.status);
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
}
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
};
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
// Initiate a multipart/form-data upload
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
xhr.send(fd);
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
}
|
||||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
||||
|
|
|||
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
Presumably Presumably `const`
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage. Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.
|
|
@ -72,7 +72,7 @@ module.exports = (app) => {
|
|||
});
|
||||
// route to run a publish request on the daemon
|
||||
app.post('/api/publish', multipartMiddleware, (req, res) => {
|
||||
logger.debug('req:', req);
|
||||
logger.debug('req:', req.body, req.files);
|
||||
// validate that mandatory parts of the request are present
|
||||
const body = req.body;
|
||||
const files = req.files;
|
||||
|
@ -89,8 +89,7 @@ module.exports = (app) => {
|
|||
const filePath = file.path;
|
||||
const fileType = file.type;
|
||||
const name = body.name;
|
||||
let nsfw = body.nsfw;
|
||||
nsfw = cleanseNSFW(nsfw); // cleanse nsfw
|
||||
const nsfw = cleanseNSFW(body.nsfw); // cleanse nsfw input
|
||||
try {
|
||||
validatePublishSubmission(file, name, nsfw);
|
||||
} catch (error) {
|
||||
|
@ -107,7 +106,7 @@ module.exports = (app) => {
|
|||
let channelName = body.channelName || null;
|
||||
channelName = cleanseChannelName(channelName);
|
||||
const channelPassword = body.channelPassword || null;
|
||||
logger.debug(`license: ${license} title: "${title}" description: "${description}" channelName: "${channelName}" channelPassword: "${channelPassword}"`);
|
||||
logger.debug(`license: ${license} title: "${title}" description: "${description}" channelName: "${channelName}" channelPassword: "${channelPassword}" nsfw: "${nsfw}"`);
|
||||
// check channel authorization
|
||||
authenticateChannelCredentials(channelName, channelPassword)
|
||||
.then(result => {
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
const logger = require('winston');
|
||||
const { publish } = require('../controllers/publishController.js');
|
||||
const { createPublishParams } = require('../helpers/publishHelpers.js');
|
||||
const { useObjectPropertiesIfNoKeys } = require('../helpers/errorHandlers.js');
|
||||
const { postToStats } = require('../controllers/statsController.js');
|
||||
|
||||
module.exports = (app, siofu, hostedContentPath) => {
|
||||
const http = require('http');
|
||||
const server = http.Server(app);
|
||||
const io = require('socket.io')(server);
|
||||
|
||||
io.on('connection', socket => {
|
||||
logger.silly('a user connected via sockets');
|
||||
// attach upload listeners
|
||||
const uploader = new siofu();
|
||||
uploader.dir = hostedContentPath;
|
||||
uploader.listen(socket);
|
||||
// listener for when file upload starts
|
||||
uploader.on('start', ({ file }) => {
|
||||
// log
|
||||
logger.info('client started an upload:', file.name);
|
||||
// server side test to make sure file is not a bad file type
|
||||
if (/\.exe$/.test(file.name)) {
|
||||
uploader.abort(file.id, socket);
|
||||
}
|
||||
});
|
||||
// listener for when file upload encounters an error
|
||||
uploader.on('error', ({ error }) => {
|
||||
logger.error('an error occured while uploading', error);
|
||||
postToStats('PUBLISH', '/', null, null, null, error);
|
||||
socket.emit('publish-status', error);
|
||||
});
|
||||
// listener for when file has been uploaded
|
||||
uploader.on('saved', ({ file }) => {
|
||||
if (file.success) {
|
||||
logger.debug(`Client successfully uploaded ${file.name}`);
|
||||
socket.emit('publish-update', 'File upload successfully completed. Your image is being published to LBRY (this might take a second)...');
|
||||
// /*
|
||||
// NOTE: need to validate that client has the credentials to the channel they chose
|
||||
// otherwise they could circumvent security.
|
||||
// */
|
||||
let thumbnail;
|
||||
if (file.meta.thumbnail) {
|
||||
thumbnail = file.meta.thumbnail;
|
||||
} else {
|
||||
thumbnail = null;
|
||||
}
|
||||
let channelName;
|
||||
if (file.meta.channel) {
|
||||
channelName = file.meta.channel;
|
||||
} else {
|
||||
channelName = null;
|
||||
}
|
||||
// prepare the publish parameters
|
||||
const publishParams = createPublishParams(file.pathName, file.meta.name, file.meta.title, file.meta.description, file.meta.license, file.meta.nsfw, thumbnail, channelName);
|
||||
logger.debug('publish parameters:', publishParams);
|
||||
// publish the file
|
||||
publish(publishParams, file.name, file.meta.type)
|
||||
.then(result => {
|
||||
socket.emit('publish-complete', { name: publishParams.name, result });
|
||||
})
|
||||
.catch(error => {
|
||||
logger.error('Publish Error:', useObjectPropertiesIfNoKeys(error));
|
||||
socket.emit('publish-failure', error.message);
|
||||
});
|
||||
} else {
|
||||
socket.emit('publish-failure', 'File uploaded, but with errors');
|
||||
logger.error(`An error occurred in uploading the client's file`);
|
||||
// to-do: remove the file, if not done automatically
|
||||
}
|
||||
});
|
||||
// handle disconnect
|
||||
socket.on('disconnect', () => {
|
||||
logger.silly('a user disconnected via sockets');
|
||||
});
|
||||
});
|
||||
|
||||
return server;
|
||||
};
|
|
@ -82,7 +82,8 @@ db.sequelize
|
|||
require('./routes/page-routes.js')(app);
|
||||
require('./routes/serve-routes.js')(app);
|
||||
require('./routes/home-routes.js')(app);
|
||||
return require('./routes/sockets-routes.js')(app, siofu, hostedContentPath);
|
||||
const http = require('http');
|
||||
return http.Server(app);
|
||||
})
|
||||
.then(server => { // start the server
|
||||
server.listen(PORT, () => {
|
||||
|
|
|
@ -51,15 +51,10 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script src="/siofu/client.js"></script>
|
||||
<script typ="text/javascript">
|
||||
|
||||
checkCookie();
|
||||
|
||||
const socket = io();
|
||||
const uploader = new SocketIOFileUpload(socket);
|
||||
let stagedFiles = null;
|
||||
|
||||
const publishFormWrapper = document.getElementById('publish-form');
|
||||
|
@ -68,8 +63,7 @@
|
|||
const publishProgressBar = document.getElementById('publish-progress-bar');
|
||||
const uploadPercent = document.getElementById('upload-percent');
|
||||
|
||||
/* socketio-file-upload listeners */
|
||||
uploader.addEventListener('start', function(event){
|
||||
function uploadStarted (event){
|
||||
console.log('starting upload');
|
||||
addInputValuesToFileMetaData(event)
|
||||
// hide the publish tool
|
||||
|
@ -77,30 +71,29 @@
|
|||
// show the progress status and animation
|
||||
showPublishStatus();
|
||||
showPublishProgressBar();
|
||||
});
|
||||
uploader.addEventListener('progress', function(event){
|
||||
};
|
||||
function uploadProgress (event){
|
||||
var percent = event.bytesLoaded / event.file.size * 100;
|
||||
updatePublishStatus('<p>File is loading to server</p>')
|
||||
updateUploadPercent(`<p class="blue">${percent.toFixed(2)}%</p>`)
|
||||
});
|
||||
/* socket.io message listeners */
|
||||
socket.on('publish-update', function(msg){
|
||||
};
|
||||
function filePublishUpdate (msg) {
|
||||
updatePublishStatus(`<p>${msg}</p>`);
|
||||
updateUploadPercent(`<p>Curious what magic is happening here? <a class="link--primary" target="blank" href="https://lbry.io/faq/what-is-lbry">Learn more.</a></p>`);
|
||||
});
|
||||
socket.on('publish-failure', function(msg){
|
||||
};
|
||||
function filePublishFailure (msg){
|
||||
updatePublishStatus('<p> --(✖╭╮✖)→ </p><p>' + JSON.stringify(msg) + '</p><strong>For help, post the above error text in the #speech channel on the <a class="link--primary" href="https://discord.gg/YjYbwhS" target="_blank">lbry discord</a></strong>');
|
||||
hidePublishProgressBar();
|
||||
hideUploadPercent();
|
||||
});
|
||||
socket.on('publish-complete', function(msg){
|
||||
};
|
||||
function filePublishComplete (msg) {
|
||||
const showUrl = msg.result.claim_id + "/" + msg.name;
|
||||
// update status
|
||||
updatePublishStatus('<p>Your publish is complete! You are being redirected to it now.</p>');
|
||||
updateUploadPercent('<p><a class="link--primary" target="_blank" href="\' + showUrl + \'">If you do not get redirected, click here.</a></p>')
|
||||
// redirect the user
|
||||
window.location.href = showUrl;
|
||||
});
|
||||
};
|
||||
|
||||
function hidePublishTools() {
|
||||
publishFormWrapper.setAttribute('class', 'hidden');
|
||||
|
|
Presumably
const
Late on catching this one, but this function name doesn't imply it is redirecting me to the homepage.