Merge branch 'master' into undefined-og-description
This commit is contained in:
commit
1aa05b2b1b
43 changed files with 713 additions and 795 deletions
31
README.md
31
README.md
|
@ -14,13 +14,10 @@ spee.ch is a single-serving site that reads and publishes images and videos to a
|
||||||
* start spee.ch
|
* start spee.ch
|
||||||
* clone this repo
|
* clone this repo
|
||||||
* run `npm install`
|
* run `npm install`
|
||||||
* to start the server, from your command line run `node speech.js` while passing three environmental variables:
|
* create your `speechConfig.js` file
|
||||||
* (1) your lbry wallet address (`LBRY_CLAIM_ADDRESS`),
|
* copy `speechConfig.js.example` and name it `speechConfig.js`
|
||||||
* (2) your mysql username (`MYSQL_USERNAME`),
|
* replace the `null` values in the config file with the appropriate values for your environement
|
||||||
* (2) your mysql password (`MYSQL_PASSWORD`),
|
* to start the server, from your command line run `node speech.js`
|
||||||
* (3) the environment to run (`NODE_ENV`).
|
|
||||||
* i.e. `LBRY_CLAIM_ADDRESS=<your wallet address here> MYSQL_USERNAME=<username here> MYSQL_PASSWORD=<password here> NODE_ENV=development node speech.js`
|
|
||||||
* e.g. `LBRY_CLAIM_ADDRESS=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX MYSQL_USERNAME="lbry" MYSQL_PASSWORD="xxxxxx" NODE_ENV=development node speech.js`
|
|
||||||
* To run hot, use `nodemon` instead of `node`
|
* To run hot, use `nodemon` instead of `node`
|
||||||
* visit [localhost:3000](http://localhost:3000)
|
* visit [localhost:3000](http://localhost:3000)
|
||||||
|
|
||||||
|
@ -36,17 +33,17 @@ spee.ch is a single-serving site that reads and publishes images and videos to a
|
||||||
|
|
||||||
#### POST
|
#### POST
|
||||||
* /api/publish
|
* /api/publish
|
||||||
* example: `curl -X POST -F 'name=MyPictureName' -F 'nsfw=false' -F 'file=@/path/to/my/picture.jpeg' https://spee.ch/api/publish`
|
* example: `curl -X POST -F 'name=MyPictureName' -F 'file=@/path/to/myPicture.jpeg' https://spee.ch/api/publish`
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* name (string)
|
* `name`
|
||||||
* nsfw (boolean)
|
* `file` (.mp4, .jpeg, .jpg, .gif, or .png)
|
||||||
* file (.mp4, .jpeg, .jpg, .gif, or .png)
|
* `nsfw` (optional)
|
||||||
* license (string, optional)
|
* `license` (optional)
|
||||||
* title (string, optional)
|
* `title` (optional)
|
||||||
* description (string, optional)
|
* `description` (optional)
|
||||||
* thumbnail (string, optional) (for .mp4 uploads only)
|
* `thumbnail` url to thumbnail image, for .mp4 uploads only (optional)
|
||||||
* channelName(string, optional)
|
* `channelName`(optional)
|
||||||
* channelPassword (string, optional)
|
* `channelPassword` (optional,; required if `channelName` is provided)
|
||||||
|
|
||||||
## bugs
|
## bugs
|
||||||
If you find a bug or experience a problem, please report your issue here on github and find us in the lbry slack!
|
If you find a bug or experience a problem, please report your issue here on github and find us in the lbry slack!
|
||||||
|
|
|
@ -4,10 +4,6 @@ const logger = require('winston');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
authenticateChannelCredentials (channelName, userPassword) {
|
authenticateChannelCredentials (channelName, userPassword) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!channelName) {
|
|
||||||
resolve(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const userName = channelName.substring(1);
|
const userName = channelName.substring(1);
|
||||||
logger.debug(`authenticateChannelCredentials > channelName: ${channelName} username: ${userName} pass: ${userPassword}`);
|
logger.debug(`authenticateChannelCredentials > channelName: ${channelName} username: ${userName} pass: ${userPassword}`);
|
||||||
db.User
|
db.User
|
||||||
|
@ -18,18 +14,32 @@ module.exports = {
|
||||||
resolve(false);
|
resolve(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!user.validPassword(userPassword, user.password)) {
|
return user.comparePassword(userPassword, (passwordErr, isMatch) => {
|
||||||
logger.debug('incorrect password');
|
if (passwordErr) {
|
||||||
resolve(false);
|
logger.error('comparePassword error:', passwordErr);
|
||||||
return;
|
resolve(false);
|
||||||
}
|
return;
|
||||||
logger.debug('user found:', user.dataValues);
|
}
|
||||||
resolve(true);
|
if (!isMatch) {
|
||||||
|
logger.debug('incorrect password');
|
||||||
|
resolve(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logger.debug('...password was a match...');
|
||||||
|
resolve(true);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
logger.error(error);
|
reject(error);
|
||||||
reject();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
authenticateOrSkip (skipAuth, channelName, channelPassword) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (skipAuth) {
|
||||||
|
return resolve(true);
|
||||||
|
}
|
||||||
|
return resolve(module.exports.authenticateChannelCredentials(channelName, channelPassword));
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
{
|
|
||||||
"WalletConfig": {
|
|
||||||
"LbryClaimAddress": "LBRY_CLAIM_ADDRESS"
|
|
||||||
},
|
|
||||||
"Database": {
|
|
||||||
"Username": "MYSQL_USERNAME",
|
|
||||||
"Password": "MYSQL_PASSWORD"
|
|
||||||
},
|
|
||||||
"Logging": {
|
|
||||||
"SlackWebHook": "SLACK_WEB_HOOK"
|
|
||||||
},
|
|
||||||
"Session": {
|
|
||||||
"SessionKey": "SESSION_KEY"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
{}
|
|
|
@ -1,23 +0,0 @@
|
||||||
{
|
|
||||||
"WalletConfig": {
|
|
||||||
"LbryClaimAddress": null,
|
|
||||||
"DefaultChannel": null
|
|
||||||
},
|
|
||||||
"AnalyticsConfig":{
|
|
||||||
"GoogleId": null
|
|
||||||
},
|
|
||||||
"Database": {
|
|
||||||
"Database": "lbry",
|
|
||||||
"Username": null,
|
|
||||||
"Password": null
|
|
||||||
},
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": null,
|
|
||||||
"SlackWebHook": null,
|
|
||||||
"SlackErrorChannel": null,
|
|
||||||
"SlackInfoChannel": null
|
|
||||||
},
|
|
||||||
"Session": {
|
|
||||||
"SessionKey": null
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
{
|
|
||||||
"WalletConfig": {
|
|
||||||
"DefaultChannel": "@speechDev"
|
|
||||||
},
|
|
||||||
"AnalyticsConfig":{
|
|
||||||
"GoogleId": "UA-100747990-1"
|
|
||||||
},
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": "silly",
|
|
||||||
"SlackErrorChannel": "#staging_speech-errors",
|
|
||||||
"SlackInfoChannel": "none"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
{
|
|
||||||
"WalletConfig": {
|
|
||||||
"DefaultChannel": "@speech"
|
|
||||||
},
|
|
||||||
"AnalyticsConfig":{
|
|
||||||
"GoogleId": "UA-60403362-3"
|
|
||||||
},
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": "verbose",
|
|
||||||
"SlackErrorChannel": "#speech-errors",
|
|
||||||
"SlackInfoChannel": "#speech-logs"
|
|
||||||
}
|
|
||||||
}
|
|
30
config/slackConfig.js
Normal file
30
config/slackConfig.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
const config = require('./speechConfig.js');
|
||||||
|
const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook;
|
||||||
|
|
||||||
|
module.exports = (winston) => {
|
||||||
|
if (config.logging.slackWebHook) {
|
||||||
|
// add a transport for errors to slack
|
||||||
|
winston.add(winstonSlackWebHook, {
|
||||||
|
name : 'slack-errors-transport',
|
||||||
|
level : 'warn',
|
||||||
|
webhookUrl: config.logging.slackWebHook,
|
||||||
|
channel : config.logging.slackErrorChannel,
|
||||||
|
username : 'spee.ch',
|
||||||
|
iconEmoji : ':face_with_head_bandage:',
|
||||||
|
});
|
||||||
|
winston.add(winstonSlackWebHook, {
|
||||||
|
name : 'slack-info-transport',
|
||||||
|
level : 'info',
|
||||||
|
webhookUrl: config.logging.slackWebHook,
|
||||||
|
channel : config.logging.slackInfoChannel,
|
||||||
|
username : 'spee.ch',
|
||||||
|
iconEmoji : ':nerd_face:',
|
||||||
|
});
|
||||||
|
// send test message
|
||||||
|
winston.error('Slack "error" logging is online.');
|
||||||
|
winston.warn('Slack "warning" logging is online.');
|
||||||
|
winston.info('Slack "info" logging is online.');
|
||||||
|
} else {
|
||||||
|
winston.warn('Slack logging is not enabled because no SLACK_WEB_HOOK env var provided.');
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,32 +0,0 @@
|
||||||
const config = require('config');
|
|
||||||
const SLACK_WEB_HOOK = config.get('Logging.SlackWebHook');
|
|
||||||
const SLACK_ERROR_CHANNEL = config.get('Logging.SlackErrorChannel');
|
|
||||||
const SLACK_INFO_CHANNEL = config.get('Logging.SlackInfoChannel');
|
|
||||||
const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook;
|
|
||||||
|
|
||||||
module.exports = (winston) => {
|
|
||||||
if (SLACK_WEB_HOOK) {
|
|
||||||
// add a transport for errors to slack
|
|
||||||
winston.add(winstonSlackWebHook, {
|
|
||||||
name : 'slack-errors-transport',
|
|
||||||
level : 'error',
|
|
||||||
webhookUrl: SLACK_WEB_HOOK,
|
|
||||||
channel : SLACK_ERROR_CHANNEL,
|
|
||||||
username : 'spee.ch',
|
|
||||||
iconEmoji : ':face_with_head_bandage:',
|
|
||||||
});
|
|
||||||
winston.add(winstonSlackWebHook, {
|
|
||||||
name : 'slack-info-transport',
|
|
||||||
level : 'info',
|
|
||||||
webhookUrl: SLACK_WEB_HOOK,
|
|
||||||
channel : SLACK_INFO_CHANNEL,
|
|
||||||
username : 'spee.ch',
|
|
||||||
iconEmoji : ':nerd_face:',
|
|
||||||
});
|
|
||||||
// send test message
|
|
||||||
winston.error('Slack error logging is online.');
|
|
||||||
winston.info('Slack info logging is online.');
|
|
||||||
} else {
|
|
||||||
winston.error('Slack logging is not enabled because no SLACK_WEB_HOOK env var provided.');
|
|
||||||
}
|
|
||||||
};
|
|
22
config/speechConfig.js.example
Normal file
22
config/speechConfig.js.example
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
module.exports = {
|
||||||
|
wallet: {
|
||||||
|
lbryClaimAddress: null, // choose an address from your lbry wallet
|
||||||
|
},
|
||||||
|
analytics: {
|
||||||
|
googleId: null, // google id for analytics tracking; leave `null` if not applicable
|
||||||
|
},
|
||||||
|
sql: {
|
||||||
|
database: null, // name of mysql database
|
||||||
|
username: null, // username for mysql
|
||||||
|
password: null, // password for mysql
|
||||||
|
},
|
||||||
|
logging: {
|
||||||
|
logLevel : null, // options: silly, debug, verbose, info
|
||||||
|
slackWebHook : null, // enter a webhook if you wish to push logs to slack; otherwise leave as `null`
|
||||||
|
slackErrorChannel: null, // enter a slack channel (#example) for errors to be sent to; otherwise leave null
|
||||||
|
slackInfoChannel : null, // enter a slack channel (#info) for info level logs to be sent to otherwise leave null
|
||||||
|
},
|
||||||
|
session: {
|
||||||
|
sessionKey: null, // enter a secret key to be used for session encryption
|
||||||
|
},
|
||||||
|
};
|
|
@ -6,24 +6,33 @@ const publishHelpers = require('../helpers/publishHelpers.js');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
publish (publishParams, fileName, fileType) {
|
publish (publishParams, fileName, fileType) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let publishResults = {};
|
let publishResults, certificateId, channelName;
|
||||||
// 1. publish the file
|
// publish the file
|
||||||
return lbryApi.publishClaim(publishParams)
|
return lbryApi.publishClaim(publishParams)
|
||||||
// 2. upsert File record (update is in case the claim has been published before by this daemon)
|
|
||||||
.then(tx => {
|
.then(tx => {
|
||||||
logger.info(`Successfully published ${fileName}`, tx);
|
logger.info(`Successfully published ${fileName}`, tx);
|
||||||
publishResults = tx;
|
publishResults = tx;
|
||||||
return db.Channel.findOne({where: {channelName: publishParams.channel_name}}); // note: should this be db.User ??
|
// get the channel information
|
||||||
|
if (publishParams.channel_name) {
|
||||||
|
logger.debug(`this claim was published in channel: ${publishParams.channel_name}`);
|
||||||
|
return db.Channel.findOne({where: {channelName: publishParams.channel_name}});
|
||||||
|
} else {
|
||||||
|
logger.debug('this claim was published in channel: n/a');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(channel => {
|
.then(channel => {
|
||||||
let certificateId;
|
// set channel information
|
||||||
|
certificateId = null;
|
||||||
|
channelName = null;
|
||||||
if (channel) {
|
if (channel) {
|
||||||
certificateId = channel.channelClaimId;
|
certificateId = channel.channelClaimId;
|
||||||
logger.debug('successfully found channel in Channel table');
|
channelName = channel.channelName;
|
||||||
} else {
|
}
|
||||||
certificateId = null;
|
logger.debug(`certificateId: ${certificateId}`);
|
||||||
logger.debug('channel for publish not found in Channel table');
|
})
|
||||||
};
|
.then(() => {
|
||||||
|
// create the File record
|
||||||
const fileRecord = {
|
const fileRecord = {
|
||||||
name : publishParams.name,
|
name : publishParams.name,
|
||||||
claimId : publishResults.claim_id,
|
claimId : publishResults.claim_id,
|
||||||
|
@ -37,6 +46,7 @@ module.exports = {
|
||||||
fileType,
|
fileType,
|
||||||
nsfw : publishParams.metadata.nsfw,
|
nsfw : publishParams.metadata.nsfw,
|
||||||
};
|
};
|
||||||
|
// create the Claim record
|
||||||
const claimRecord = {
|
const claimRecord = {
|
||||||
name : publishParams.name,
|
name : publishParams.name,
|
||||||
claimId : publishResults.claim_id,
|
claimId : publishResults.claim_id,
|
||||||
|
@ -48,14 +58,16 @@ module.exports = {
|
||||||
height : 0,
|
height : 0,
|
||||||
contentType: fileType,
|
contentType: fileType,
|
||||||
nsfw : publishParams.metadata.nsfw,
|
nsfw : publishParams.metadata.nsfw,
|
||||||
certificateId,
|
|
||||||
amount : publishParams.bid,
|
amount : publishParams.bid,
|
||||||
|
certificateId,
|
||||||
|
channelName,
|
||||||
};
|
};
|
||||||
|
// upsert criteria
|
||||||
const upsertCriteria = {
|
const upsertCriteria = {
|
||||||
name : publishParams.name,
|
name : publishParams.name,
|
||||||
claimId: publishResults.claim_id,
|
claimId: publishResults.claim_id,
|
||||||
};
|
};
|
||||||
// create the records
|
// upsert the records
|
||||||
return Promise.all([db.upsert(db.File, fileRecord, upsertCriteria, 'File'), db.upsert(db.Claim, claimRecord, upsertCriteria, 'Claim')]);
|
return Promise.all([db.upsert(db.File, fileRecord, upsertCriteria, 'File'), db.upsert(db.Claim, claimRecord, upsertCriteria, 'Claim')]);
|
||||||
})
|
})
|
||||||
.then(([file, claim]) => {
|
.then(([file, claim]) => {
|
||||||
|
@ -67,7 +79,6 @@ module.exports = {
|
||||||
resolve(publishResults); // resolve the promise with the result from lbryApi.publishClaim;
|
resolve(publishResults); // resolve the promise with the result from lbryApi.publishClaim;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
logger.error('caught a publishController.publish error');
|
|
||||||
publishHelpers.deleteTemporaryFile(publishParams.file_path); // delete the local file
|
publishHelpers.deleteTemporaryFile(publishParams.file_path); // delete the local file
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
|
|
|
@ -67,12 +67,12 @@ function getAssetByLongClaimId (fullClaimId, name) {
|
||||||
db.Claim
|
db.Claim
|
||||||
.resolveClaim(name, fullClaimId)
|
.resolveClaim(name, fullClaimId)
|
||||||
.then(resolveResult => {
|
.then(resolveResult => {
|
||||||
logger.debug('resolve result >> ', resolveResult.dataValues);
|
|
||||||
// if no result, return early (claim doesn't exist or isn't free)
|
// if no result, return early (claim doesn't exist or isn't free)
|
||||||
if (!resolveResult) {
|
if (!resolveResult) {
|
||||||
resolve(NO_CLAIM);
|
resolve(NO_CLAIM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
logger.debug('resolve result >> ', resolveResult.dataValues);
|
||||||
let fileRecord = {};
|
let fileRecord = {};
|
||||||
// get the claim
|
// get the claim
|
||||||
lbryApi.getClaim(`${name}#${fullClaimId}`)
|
lbryApi.getClaim(`${name}#${fullClaimId}`)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const ua = require('universal-analytics');
|
const ua = require('universal-analytics');
|
||||||
const config = require('config');
|
const config = require('../config/speechConfig.js');
|
||||||
const db = require('../models');
|
const db = require('../models');
|
||||||
const googleApiKey = config.get('AnalyticsConfig.GoogleId');
|
const googleApiKey = config.analytics.googleId;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
postToStats (action, url, ipAddress, name, claimId, result) {
|
postToStats (action, url, ipAddress, name, claimId, result) {
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
const config = require('config');
|
const config = require('../config/speechConfig.js');
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
// get the config file
|
// get the config file
|
||||||
const defaultConfigFile = JSON.parse(fs.readFileSync('./config/default.json'));
|
|
||||||
|
|
||||||
for (let configCategoryKey in defaultConfigFile) {
|
for (let configCategoryKey in config) {
|
||||||
if (defaultConfigFile.hasOwnProperty(configCategoryKey)) {
|
if (config.hasOwnProperty(configCategoryKey)) {
|
||||||
// get the final variables for each config category
|
// get the final variables for each config category
|
||||||
const configVariables = config.get(configCategoryKey);
|
const configVariables = config[configCategoryKey];
|
||||||
for (let configVarKey in configVariables) {
|
for (let configVarKey in configVariables) {
|
||||||
if (configVariables.hasOwnProperty(configVarKey)) {
|
if (configVariables.hasOwnProperty(configVarKey)) {
|
||||||
// print each variable
|
// print each variable
|
||||||
|
|
|
@ -2,38 +2,54 @@ const logger = require('winston');
|
||||||
const { postToStats } = require('../controllers/statsController.js');
|
const { postToStats } = require('../controllers/statsController.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
handleRequestError (action, originalUrl, ip, error, res) {
|
returnErrorMessageAndStatus: function (error) {
|
||||||
logger.error(`Request Error: ${originalUrl}`, module.exports.useObjectPropertiesIfNoKeys(error));
|
let status, message;
|
||||||
postToStats(action, originalUrl, ip, null, null, error);
|
// check for daemon being turned off
|
||||||
if (error.response) {
|
|
||||||
res.status(error.response.status).render('requestError', {message: error.response.data.error.message, status: error.response.status});
|
|
||||||
} else if (error.code === 'ECONNREFUSED') {
|
|
||||||
res.status(503).render('requestError', {message: 'Connection refused. The daemon may not be running.', status: 503});
|
|
||||||
} else if (error.message) {
|
|
||||||
res.status(500).render('requestError', {message: error.message, status: 500});
|
|
||||||
} else {
|
|
||||||
res.status(400).render('requestError', {message: error, status: 400});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
handlePublishError (error) {
|
|
||||||
logger.error('Publish Error:', module.exports.useObjectPropertiesIfNoKeys(error));
|
|
||||||
if (error.code === 'ECONNREFUSED') {
|
if (error.code === 'ECONNREFUSED') {
|
||||||
return 'Connection refused. The daemon may not be running.';
|
status = 503;
|
||||||
|
message = 'Connection refused. The daemon may not be running.';
|
||||||
|
// check for errors from the deamon
|
||||||
} else if (error.response) {
|
} else if (error.response) {
|
||||||
|
status = error.response.status || 500;
|
||||||
if (error.response.data) {
|
if (error.response.data) {
|
||||||
if (error.response.data.message) {
|
if (error.response.data.message) {
|
||||||
return error.response.data.message;
|
message = error.response.data.message;
|
||||||
} else if (error.response.data.error) {
|
} else if (error.response.data.error) {
|
||||||
return error.response.data.error.message;
|
message = error.response.data.error.message;
|
||||||
|
} else {
|
||||||
|
message = error.response.data;
|
||||||
}
|
}
|
||||||
return error.response.data;
|
} else {
|
||||||
|
message = error.response;
|
||||||
}
|
}
|
||||||
return error.response;
|
// check for spee.ch thrown errors
|
||||||
|
} else if (error.message) {
|
||||||
|
status = 400;
|
||||||
|
message = error.message;
|
||||||
|
// fallback for everything else
|
||||||
} else {
|
} else {
|
||||||
return error;
|
status = 400;
|
||||||
|
message = error;
|
||||||
}
|
}
|
||||||
|
return [status, message];
|
||||||
},
|
},
|
||||||
useObjectPropertiesIfNoKeys (err) {
|
handleRequestError: function (action, originalUrl, ip, error, res) {
|
||||||
|
logger.error(`Request Error on ${originalUrl}`, module.exports.useObjectPropertiesIfNoKeys(error));
|
||||||
|
postToStats(action, originalUrl, ip, null, null, error);
|
||||||
|
const [status, message] = this.returnErrorMessageAndStatus(error);
|
||||||
|
res
|
||||||
|
.status(status)
|
||||||
|
.render('requestError', this.createErrorResponsePayload(status, message));
|
||||||
|
},
|
||||||
|
handleApiError: function (action, originalUrl, ip, error, res) {
|
||||||
|
logger.error(`Api ${action} Error on ${originalUrl}`, module.exports.useObjectPropertiesIfNoKeys(error));
|
||||||
|
postToStats(action, originalUrl, ip, null, null, error);
|
||||||
|
const [status, message] = this.returnErrorMessageAndStatus(error);
|
||||||
|
res
|
||||||
|
.status(status)
|
||||||
|
.json(this.createErrorResponsePayload(status, message));
|
||||||
|
},
|
||||||
|
useObjectPropertiesIfNoKeys: function (err) {
|
||||||
if (Object.keys(err).length === 0) {
|
if (Object.keys(err).length === 0) {
|
||||||
let newErrorObject = {};
|
let newErrorObject = {};
|
||||||
Object.getOwnPropertyNames(err).forEach((key) => {
|
Object.getOwnPropertyNames(err).forEach((key) => {
|
||||||
|
@ -43,4 +59,11 @@ module.exports = {
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
},
|
},
|
||||||
|
createErrorResponsePayload (status, message) {
|
||||||
|
return {
|
||||||
|
status,
|
||||||
|
success: false,
|
||||||
|
message,
|
||||||
|
};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
const Handlebars = require('handlebars');
|
const Handlebars = require('handlebars');
|
||||||
const config = require('config');
|
const config = require('../config/speechConfig.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// define any extra helpers you may need
|
// define any extra helpers you may need
|
||||||
googleAnalytics () {
|
googleAnalytics () {
|
||||||
const googleApiKey = config.get('AnalyticsConfig.GoogleId');
|
const googleApiKey = config.analytics.googleId;
|
||||||
return new Handlebars.SafeString(
|
return new Handlebars.SafeString(
|
||||||
`<script>
|
`<script>
|
||||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const db = require('../models');
|
const db = require('../models');
|
||||||
const config = require('config');
|
const config = require('../config/speechConfig.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
validateApiPublishRequest (body, files) {
|
validateApiPublishRequest (body, files) {
|
||||||
|
@ -11,9 +11,6 @@ module.exports = {
|
||||||
if (!body.name) {
|
if (!body.name) {
|
||||||
throw new Error('no name field found in request');
|
throw new Error('no name field found in request');
|
||||||
}
|
}
|
||||||
if (!body.nsfw) {
|
|
||||||
throw new Error('no nsfw field found in request');
|
|
||||||
}
|
|
||||||
if (!files) {
|
if (!files) {
|
||||||
throw new Error('no files found in request');
|
throw new Error('no files found in request');
|
||||||
}
|
}
|
||||||
|
@ -21,11 +18,10 @@ module.exports = {
|
||||||
throw new Error('no file with key of [file] found in request');
|
throw new Error('no file with key of [file] found in request');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
validatePublishSubmission (file, claimName, nsfw) {
|
validatePublishSubmission (file, claimName) {
|
||||||
try {
|
try {
|
||||||
module.exports.validateFile(file);
|
module.exports.validateFile(file);
|
||||||
module.exports.validateClaimName(claimName);
|
module.exports.validateClaimName(claimName);
|
||||||
module.exports.validateNSFW(nsfw);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
@ -79,24 +75,6 @@ module.exports = {
|
||||||
throw new Error('Only posts with a "Public Domain" or "Creative Commons" license are eligible for publishing through spee.ch');
|
throw new Error('Only posts with a "Public Domain" or "Creative Commons" license are eligible for publishing through spee.ch');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cleanseNSFW (nsfw) {
|
|
||||||
switch (nsfw) {
|
|
||||||
case true:
|
|
||||||
case 'on':
|
|
||||||
case 'true':
|
|
||||||
case 1:
|
|
||||||
case '1':
|
|
||||||
return true;
|
|
||||||
case false:
|
|
||||||
case 'false':
|
|
||||||
case 'off':
|
|
||||||
case 0:
|
|
||||||
case '0':
|
|
||||||
return false;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
cleanseChannelName (channelName) {
|
cleanseChannelName (channelName) {
|
||||||
if (channelName) {
|
if (channelName) {
|
||||||
if (channelName.indexOf('@') !== 0) {
|
if (channelName.indexOf('@') !== 0) {
|
||||||
|
@ -105,12 +83,6 @@ module.exports = {
|
||||||
}
|
}
|
||||||
return channelName;
|
return channelName;
|
||||||
},
|
},
|
||||||
validateNSFW (nsfw) {
|
|
||||||
if (nsfw === true || nsfw === false) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new Error('NSFW must be set to either true or false');
|
|
||||||
},
|
|
||||||
createPublishParams (filePath, name, title, description, license, nsfw, thumbnail, channelName) {
|
createPublishParams (filePath, name, title, description, license, nsfw, thumbnail, channelName) {
|
||||||
logger.debug(`Creating Publish Parameters`);
|
logger.debug(`Creating Publish Parameters`);
|
||||||
// provide defaults for title
|
// provide defaults for title
|
||||||
|
@ -138,7 +110,7 @@ module.exports = {
|
||||||
license,
|
license,
|
||||||
nsfw,
|
nsfw,
|
||||||
},
|
},
|
||||||
claim_address: config.get('WalletConfig.LbryClaimAddress'),
|
claim_address: config.wallet.lbryClaimAddress,
|
||||||
};
|
};
|
||||||
// add thumbnail to channel if video
|
// add thumbnail to channel if video
|
||||||
if (thumbnail !== null) {
|
if (thumbnail !== null) {
|
||||||
|
@ -165,7 +137,7 @@ module.exports = {
|
||||||
db.File.findAll({ where: { name } })
|
db.File.findAll({ where: { name } })
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.length >= 1) {
|
if (result.length >= 1) {
|
||||||
const claimAddress = config.get('WalletConfig.LbryClaimAddress');
|
const claimAddress = config.wallet.lbryClaimAddress;
|
||||||
// filter out any results that were not published from spee.ch's wallet address
|
// filter out any results that were not published from spee.ch's wallet address
|
||||||
const filteredResult = result.filter((claim) => {
|
const filteredResult = result.filter((claim) => {
|
||||||
return (claim.address === claimAddress);
|
return (claim.address === claimAddress);
|
||||||
|
|
|
@ -298,7 +298,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D
|
||||||
case 1:
|
case 1:
|
||||||
return resolve(result[0]);
|
return resolve(result[0]);
|
||||||
default:
|
default:
|
||||||
logger.error('more than one entry matches that name and claimID');
|
logger.warn(`more than one entry matches that name (${name}) and claimID (${claimId})`);
|
||||||
return resolve(result[0]);
|
return resolve(result[0]);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,13 +2,13 @@ const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const Sequelize = require('sequelize');
|
const Sequelize = require('sequelize');
|
||||||
const basename = path.basename(module.filename);
|
const basename = path.basename(module.filename);
|
||||||
const config = require('config');
|
const config = require('../config/speechConfig.js');
|
||||||
const db = {};
|
const db = {};
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
|
|
||||||
const database = config.get('Database.Database');
|
const database = config.sql.database;
|
||||||
const username = config.get('Database.Username');
|
const username = config.sql.username;
|
||||||
const password = config.get('Database.Password');
|
const password = config.sql.password;
|
||||||
|
|
||||||
const sequelize = new Sequelize(database, username, password, {
|
const sequelize = new Sequelize(database, username, password, {
|
||||||
host : 'localhost',
|
host : 'localhost',
|
||||||
|
@ -66,7 +66,7 @@ db.upsert = (Model, values, condition, tableName) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
logger.error('Sequelize findOne error', error);
|
logger.error(`${tableName}.upsert error`, error);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ module.exports = (sequelize, { STRING }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
User.prototype.comparePassword = function (password, callback) {
|
User.prototype.comparePassword = function (password, callback) {
|
||||||
logger.debug(`User.prototype.comparePassword ${password} ${this.password}`);
|
|
||||||
bcrypt.compare(password, this.password, callback);
|
bcrypt.compare(password, this.password, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
"cookie-session": "^2.0.0-beta.3",
|
"cookie-session": "^2.0.0-beta.3",
|
||||||
"express": "^4.15.2",
|
"express": "^4.15.2",
|
||||||
"express-handlebars": "^3.0.0",
|
"express-handlebars": "^3.0.0",
|
||||||
"express-session": "^1.15.5",
|
|
||||||
"form-data": "^2.3.1",
|
"form-data": "^2.3.1",
|
||||||
"helmet": "^3.8.1",
|
"helmet": "^3.8.1",
|
||||||
"mysql2": "^1.3.5",
|
"mysql2": "^1.3.5",
|
||||||
|
@ -44,8 +43,6 @@
|
||||||
"sequelize": "^4.1.0",
|
"sequelize": "^4.1.0",
|
||||||
"sequelize-cli": "^3.0.0-3",
|
"sequelize-cli": "^3.0.0-3",
|
||||||
"sleep": "^5.1.1",
|
"sleep": "^5.1.1",
|
||||||
"socket.io": "^2.0.1",
|
|
||||||
"socketio-file-upload": "^0.6.0",
|
|
||||||
"universal-analytics": "^0.4.13",
|
"universal-analytics": "^0.4.13",
|
||||||
"winston": "^2.3.1",
|
"winston": "^2.3.1",
|
||||||
"winston-slack-webhook": "billbitt/winston-slack-webhook"
|
"winston-slack-webhook": "billbitt/winston-slack-webhook"
|
||||||
|
|
|
@ -24,7 +24,7 @@ function publishNewChannel (event) {
|
||||||
// prevent default so this script can handle submission
|
// prevent default so this script can handle submission
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
// validate submission
|
// validate submission
|
||||||
validateNewChannelSubmission(userName, password)
|
validationFunctions.validateNewChannelSubmission(userName, password)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
showChannelCreateInProgressDisplay();
|
showChannelCreateInProgressDisplay();
|
||||||
return sendAuthRequest(userName, password, '/signup') // post the request
|
return sendAuthRequest(userName, password, '/signup') // post the request
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
function triggerFileChooser(fileInputId, event) {
|
|
||||||
document.getElementById(fileInputId).click();
|
|
||||||
}
|
|
||||||
|
|
||||||
function drop_handler(event) {
|
function drop_handler(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -9,7 +6,7 @@ function drop_handler(event) {
|
||||||
if (dt.items) {
|
if (dt.items) {
|
||||||
if (dt.items[0].kind == 'file') {
|
if (dt.items[0].kind == 'file') {
|
||||||
var droppedFile = dt.items[0].getAsFile();
|
var droppedFile = dt.items[0].getAsFile();
|
||||||
previewAndStageFile(droppedFile);
|
publishFileFunctions.previewAndStageFile(droppedFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ function getRequest (url) {
|
||||||
if ( xhttp.status == 200) {
|
if ( xhttp.status == 200) {
|
||||||
resolve(xhttp.response);
|
resolve(xhttp.response);
|
||||||
} else if (xhttp.status == 401) {
|
} else if (xhttp.status == 401) {
|
||||||
reject('Wrong username or password');
|
reject('Wrong channel name or password');
|
||||||
} else {
|
} else {
|
||||||
reject('request failed with status:' + xhttp.status);
|
reject('request failed with status:' + xhttp.status);
|
||||||
};
|
};
|
||||||
|
@ -29,7 +29,7 @@ function postRequest (url, params) {
|
||||||
if ( xhttp.status == 200) {
|
if ( xhttp.status == 200) {
|
||||||
resolve(xhttp.response);
|
resolve(xhttp.response);
|
||||||
} else if (xhttp.status == 401) {
|
} else if (xhttp.status == 401) {
|
||||||
reject( new AuthenticationError('Wrong username or password'));
|
reject( new AuthenticationError('Wrong channel name or password'));
|
||||||
} else {
|
} else {
|
||||||
reject('request failed with status:' + xhttp.status);
|
reject('request failed with status:' + xhttp.status);
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,7 +47,7 @@ function loginToChannel (event) {
|
||||||
const password = document.getElementById('channel-login-password-input').value;
|
const password = document.getElementById('channel-login-password-input').value;
|
||||||
// prevent default
|
// prevent default
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
validateNewChannelLogin(userName, password)
|
validationFunctions.validateNewChannelLogin(userName, password)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// send request
|
// send request
|
||||||
return sendAuthRequest(userName, password, '/login')
|
return sendAuthRequest(userName, password, '/login')
|
||||||
|
@ -71,9 +71,9 @@ function loginToChannel (event) {
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const loginErrorDisplayElement = document.getElementById('login-error-display-element');
|
const loginErrorDisplayElement = document.getElementById('login-error-display-element');
|
||||||
if (error.name){
|
if (error.name){
|
||||||
showError(loginErrorDisplayElement, error.message);
|
validationFunctions.showError(loginErrorDisplayElement, error.message);
|
||||||
} else {
|
} else {
|
||||||
showError(loginErrorDisplayElement, 'There was an error logging into your channel');
|
validationFunctions.showError(loginErrorDisplayElement, 'There was an error logging into your channel');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,99 +1,231 @@
|
||||||
/* publish functions */
|
var stagedFiles = null;
|
||||||
|
|
||||||
function cancelPublish () {
|
const publishFileFunctions = {
|
||||||
window.location.href = '/';
|
triggerFileChooser: function (fileInputId) {
|
||||||
}
|
document.getElementById(fileInputId).click();
|
||||||
|
},
|
||||||
// When a file is selected for publish, validate that file and
|
cancelPublish: function () {
|
||||||
// stage it so it will be ready when the publish button is clicked.
|
window.location.href = '/';
|
||||||
function previewAndStageFile(selectedFile){
|
},
|
||||||
const publishForm = document.getElementById('publish-form');
|
previewAndStageFile: function (selectedFile) {
|
||||||
const assetPreview = document.getElementById('asset-preview-target');
|
const fileSelectionInputError = document.getElementById('input-error-file-selection');
|
||||||
const primaryDropzone = document.getElementById('primary-dropzone');
|
// When a file is selected for publish, validate that file and
|
||||||
const previewReader = new FileReader();
|
// stage it so it will be ready when the publish button is clicked
|
||||||
const nameInput = document.getElementById('claim-name-input');
|
try {
|
||||||
const fileSelectionInputError = document.getElementById('input-error-file-selection');
|
validationFunctions.validateFile(selectedFile); // validate the file's name, type, and size
|
||||||
const thumbnailSelectionTool = document.getElementById('publish-thumbnail');
|
} catch (error) {
|
||||||
const thumbnailSelectionInput = document.getElementById('claim-thumbnail-input');
|
validationFunctions.showError(fileSelectionInputError, error.message);
|
||||||
// validate the file's name, type, and size
|
return;
|
||||||
try {
|
|
||||||
validateFile(selectedFile);
|
|
||||||
} catch (error) {
|
|
||||||
showError(fileSelectionInputError, error.message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// set the image preview, if an image was provided
|
|
||||||
if (selectedFile.type !== 'video/mp4') {
|
|
||||||
if (selectedFile.type === 'image/gif') {
|
|
||||||
assetPreview.innerHTML = `<p>loading preview...</p>`
|
|
||||||
}
|
|
||||||
previewReader.readAsDataURL(selectedFile);
|
|
||||||
previewReader.onloadend = function () {
|
|
||||||
assetPreview.innerHTML = '<img id="asset-preview" src="' + previewReader.result + '" alt="image preview"/>';
|
|
||||||
};
|
|
||||||
// clear & hide the thumbnail selection input
|
|
||||||
thumbnailSelectionInput.value = '';
|
|
||||||
thumbnailSelectionTool.hidden = true;
|
|
||||||
} else {
|
|
||||||
assetPreview.innerHTML = `<img id="asset-preview" src="/assets/img/video_thumb_default.png"/>`;
|
|
||||||
// clear & show the thumbnail selection input
|
|
||||||
thumbnailSelectionInput.value = '';
|
|
||||||
thumbnailSelectionTool.hidden = false;
|
|
||||||
}
|
|
||||||
// hide the drop zone
|
|
||||||
primaryDropzone.setAttribute('class', 'hidden');
|
|
||||||
publishForm.setAttribute('class', 'row')
|
|
||||||
// set the name input value to the image name if none is set yet
|
|
||||||
if (nameInput.value === "") {
|
|
||||||
var filename = selectedFile.name.substring(0, selectedFile.name.indexOf('.'))
|
|
||||||
nameInput.value = cleanseClaimName(filename);
|
|
||||||
checkClaimName(nameInput.value);
|
|
||||||
}
|
|
||||||
// store the selected file for upload
|
|
||||||
stagedFiles = [selectedFile];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate the publish submission and then trigger upload
|
|
||||||
function publishStagedFile(event) {
|
|
||||||
// prevent default so this script can handle submission
|
|
||||||
event.preventDefault();
|
|
||||||
// declare variables
|
|
||||||
const claimName = document.getElementById('claim-name-input').value;
|
|
||||||
let channelName = document.getElementById('channel-name-select').value;
|
|
||||||
const fileSelectionInputError = document.getElementById('input-error-file-selection');
|
|
||||||
const claimNameError = document.getElementById('input-error-claim-name');
|
|
||||||
const channelSelectError = document.getElementById('input-error-channel-select');
|
|
||||||
const publishSubmitError = document.getElementById('input-error-publish-submit');
|
|
||||||
let anonymousOrInChannel;
|
|
||||||
// replace channelName with 'anonymous' if appropriate
|
|
||||||
const radios = document.getElementsByName('anonymous-or-channel');
|
|
||||||
for (let i = 0; i < radios.length; i++) {
|
|
||||||
if (radios[i].checked) {
|
|
||||||
// do whatever you want with the checked radio
|
|
||||||
anonymousOrInChannel = radios[i].value;
|
|
||||||
// only one radio can be logically checked, don't check the rest
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
// set image preview, if an image was provided
|
||||||
if (anonymousOrInChannel === 'anonymous') {
|
this.setImagePreview(selectedFile);
|
||||||
channelName = null;
|
// hide the primary drop zone
|
||||||
};
|
this.hidePrimaryDropzone();
|
||||||
// validate, submit, and handle response
|
// set the name input value to the image name if none is set yet
|
||||||
validateFilePublishSubmission(stagedFiles, claimName, channelName)
|
this.updateClaimNameInputWithFileName(selectedFile);
|
||||||
.then(() => {
|
// store the selected file for upload
|
||||||
uploader.submitFiles(stagedFiles);
|
stagedFiles = [selectedFile];
|
||||||
})
|
},
|
||||||
.catch(error => {
|
hidePrimaryDropzone: function () {
|
||||||
if (error.name === 'FileError') {
|
const primaryDropzone = document.getElementById('primary-dropzone');
|
||||||
showError(fileSelectionInputError, error.message);
|
const publishForm = document.getElementById('publish-form');
|
||||||
} else if (error.name === 'NameError') {
|
primaryDropzone.setAttribute('class', 'hidden');
|
||||||
showError(claimNameError, error.message);
|
publishForm.setAttribute('class', 'row')
|
||||||
} else if (error.name === 'ChannelNameError'){
|
},
|
||||||
console.log(error);
|
updateClaimNameInputWithFileName: function (selectedFile) {
|
||||||
showError(channelSelectError, error.message);
|
const nameInput = document.getElementById('claim-name-input');
|
||||||
} else {
|
if (nameInput.value === "") {
|
||||||
showError(publishSubmitError, error.message);
|
var filename = selectedFile.name.substring(0, selectedFile.name.indexOf('.'))
|
||||||
}
|
nameInput.value = validationFunctions.cleanseClaimName(filename);
|
||||||
return;
|
validationFunctions.checkClaimName(nameInput.value);
|
||||||
})
|
}
|
||||||
};
|
},
|
||||||
|
setImagePreview: function (selectedFile) {
|
||||||
|
const assetPreview = document.getElementById('asset-preview-target');
|
||||||
|
const thumbnailInput = document.getElementById('claim-thumbnail-input');
|
||||||
|
const thumbnailInputTool = document.getElementById('publish-thumbnail');
|
||||||
|
if (selectedFile.type !== 'video/mp4') {
|
||||||
|
const previewReader = new FileReader();
|
||||||
|
if (selectedFile.type === 'image/gif') {
|
||||||
|
assetPreview.innerHTML = `<p>loading preview...</p>`
|
||||||
|
}
|
||||||
|
previewReader.readAsDataURL(selectedFile);
|
||||||
|
previewReader.onloadend = function () {
|
||||||
|
assetPreview.innerHTML = '<img id="asset-preview" src="' + previewReader.result + '" alt="image preview"/>';
|
||||||
|
};
|
||||||
|
// clear & hide the thumbnail selection input
|
||||||
|
thumbnailInput.value = '';
|
||||||
|
thumbnailInputTool.hidden = true;
|
||||||
|
} else {
|
||||||
|
assetPreview.innerHTML = `<img id="asset-preview" src="/assets/img/video_thumb_default.png"/>`;
|
||||||
|
// clear & show the thumbnail selection input
|
||||||
|
thumbnailInput.value = '';
|
||||||
|
thumbnailInputTool.hidden = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
returnNullOrChannel: function () {
|
||||||
|
const channelRadio = document.getElementById('channel-radio');
|
||||||
|
if (channelRadio.checked) {
|
||||||
|
const channelInput = document.getElementById('channel-name-select');
|
||||||
|
return channelInput.value.trim();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
createMetadata: function() {
|
||||||
|
const nameInput = document.getElementById('claim-name-input');
|
||||||
|
const titleInput = document.getElementById('publish-title');
|
||||||
|
const descriptionInput = document.getElementById('publish-description');
|
||||||
|
const licenseInput = document.getElementById('publish-license');
|
||||||
|
const nsfwInput = document.getElementById('publish-nsfw');
|
||||||
|
const thumbnailInput = document.getElementById('claim-thumbnail-input');
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: nameInput.value.trim(),
|
||||||
|
channelName: this.returnNullOrChannel(),
|
||||||
|
title: titleInput.value.trim(),
|
||||||
|
description: descriptionInput.value.trim(),
|
||||||
|
license: licenseInput.value.trim(),
|
||||||
|
nsfw: nsfwInput.checked,
|
||||||
|
type: stagedFiles[0].type,
|
||||||
|
thumbnail: thumbnailInput.value.trim(),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
appendDataToFormData: function (file, metadata) {
|
||||||
|
var fd = new FormData();
|
||||||
|
fd.append('file', file)
|
||||||
|
for (var key in metadata) {
|
||||||
|
if (metadata.hasOwnProperty(key)) {
|
||||||
|
console.log(key, metadata[key]);
|
||||||
|
fd.append(key, metadata[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fd;
|
||||||
|
},
|
||||||
|
publishFile: function (file, metadata) {
|
||||||
|
var uri = "/api/publish";
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
var fd = this.appendDataToFormData(file, metadata);
|
||||||
|
var that = this;
|
||||||
|
xhr.upload.addEventListener("loadstart", function(e) {
|
||||||
|
that.showUploadStartedMessage();
|
||||||
|
})
|
||||||
|
xhr.upload.addEventListener("progress", function(e) {
|
||||||
|
if (e.lengthComputable) {
|
||||||
|
var percentage = Math.round((e.loaded * 100) / e.total);
|
||||||
|
console.log('progress:', percentage);
|
||||||
|
that.showUploadProgressMessage(percentage);
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
xhr.upload.addEventListener("load", function(e){
|
||||||
|
console.log('loaded 100%');
|
||||||
|
that.showFilePublishUpdate("Your file has been loaded, and is now being published to the blockchain. Sit tight...")
|
||||||
|
}, false);
|
||||||
|
xhr.open("POST", uri, true);
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState == 4) {
|
||||||
|
if (xhr.status == 200) {
|
||||||
|
console.log('publish complete!');
|
||||||
|
that.showFilePublishComplete(JSON.parse(xhr.response).message);
|
||||||
|
} else {
|
||||||
|
console.log(xhr.response);
|
||||||
|
that.showFilePublishFailure(JSON.parse(xhr.response).message);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('xhr.readyState', xhr.readyState, 'xhr.status', xhr.status);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Initiate a multipart/form-data upload
|
||||||
|
xhr.send(fd);
|
||||||
|
},
|
||||||
|
// Validate the publish submission and then trigger upload
|
||||||
|
publishStagedFile: function (event) {
|
||||||
|
event.preventDefault(); // prevent default so this script can handle submission
|
||||||
|
const metadata = this.createMetadata();
|
||||||
|
const that = this; // note: necessary ?
|
||||||
|
const fileSelectionInputError = document.getElementById('input-error-file-selection');
|
||||||
|
const claimNameError = document.getElementById('input-error-claim-name');
|
||||||
|
const channelSelectError = document.getElementById('input-error-channel-select');
|
||||||
|
const publishSubmitError = document.getElementById('input-error-publish-submit');
|
||||||
|
// validate, submit, and handle response
|
||||||
|
validationFunctions.validateFilePublishSubmission(stagedFiles, metadata)
|
||||||
|
.then( function() {
|
||||||
|
that.publishFile(stagedFiles[0], metadata);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
if (error.name === 'FileError') {
|
||||||
|
validationFunctions.showError(fileSelectionInputError, error.message);
|
||||||
|
} else if (error.name === 'NameError') {
|
||||||
|
validationFunctions.showError(claimNameError, error.message);
|
||||||
|
} else if (error.name === 'ChannelNameError'){
|
||||||
|
console.log(error);
|
||||||
|
validationFunctions.showError(channelSelectError, error.message);
|
||||||
|
} else {
|
||||||
|
validationFunctions.showError(publishSubmitError, error.message);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
})
|
||||||
|
},
|
||||||
|
showUploadStartedMessage: function (){
|
||||||
|
console.log('starting upload');
|
||||||
|
// hide the publish tool
|
||||||
|
this.hidePublishTools();
|
||||||
|
// show the progress status and animation
|
||||||
|
this.showPublishStatus();
|
||||||
|
this.showPublishProgressBar();
|
||||||
|
},
|
||||||
|
showUploadProgressMessage: function (percentage){
|
||||||
|
this.updatePublishStatus('<p>File is loading to server</p>');
|
||||||
|
this.updateUploadPercent('<p class="blue">' + percentage + '% </p>');
|
||||||
|
},
|
||||||
|
showFilePublishUpdate: function (msg) {
|
||||||
|
this.updatePublishStatus('<p>' + msg + '</p>');
|
||||||
|
this.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>');
|
||||||
|
},
|
||||||
|
showFilePublishFailure: function (msg){
|
||||||
|
this.updatePublishStatus('<p>Something went wrong...</p><p><strong>' + msg + '</strong></p><p>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>');
|
||||||
|
this.hidePublishProgressBar();
|
||||||
|
this.hideUploadPercent();
|
||||||
|
},
|
||||||
|
showFilePublishComplete: function (msg) {
|
||||||
|
console.log('Publish complete!');
|
||||||
|
const showUrl = msg.lbryTx.claim_id + "/" + msg.name;
|
||||||
|
// update status
|
||||||
|
this.updatePublishStatus('<p>Your publish is complete! You are being redirected to it now.</p>');
|
||||||
|
this.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;
|
||||||
|
},
|
||||||
|
hidePublishTools: function () {
|
||||||
|
const publishFormWrapper = document.getElementById('publish-form');
|
||||||
|
publishFormWrapper.setAttribute('class', 'hidden');
|
||||||
|
},
|
||||||
|
// publish status functions
|
||||||
|
showPublishStatus: function () {
|
||||||
|
const publishStatus = document.getElementById('publish-status');
|
||||||
|
publishStatus.setAttribute('class', 'row row--tall flex-container--column flex-container--center-center');
|
||||||
|
},
|
||||||
|
updatePublishStatus: function (msg){
|
||||||
|
const publishUpdate = document.getElementById('publish-update');
|
||||||
|
publishUpdate.innerHTML = msg;
|
||||||
|
},
|
||||||
|
// progress bar functions
|
||||||
|
showPublishProgressBar: function (){
|
||||||
|
const publishProgressBar = document.getElementById('publish-progress-bar');
|
||||||
|
createProgressBar(publishProgressBar, 12);
|
||||||
|
},
|
||||||
|
hidePublishProgressBar: function (){
|
||||||
|
const publishProgressBar = document.getElementById('publish-progress-bar');
|
||||||
|
publishProgressBar.hidden = true;
|
||||||
|
},
|
||||||
|
// upload percent functions
|
||||||
|
updateUploadPercent: function (msg){
|
||||||
|
const uploadPercent = document.getElementById('upload-percent');
|
||||||
|
uploadPercent.innerHTML = msg;
|
||||||
|
},
|
||||||
|
hideUploadPercent: function (){
|
||||||
|
const uploadPercent = document.getElementById('upload-percent');
|
||||||
|
uploadPercent.hidden = true;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,236 +1,231 @@
|
||||||
// validation function which checks the proposed file's type, size, and name
|
// validation function which checks the proposed file's type, size, and name
|
||||||
function validateFile(file) {
|
const validationFunctions = {
|
||||||
if (!file) {
|
validateFile: function (file) {
|
||||||
console.log('no file found');
|
if (!file) {
|
||||||
throw new Error('no file provided');
|
console.log('no file found');
|
||||||
}
|
throw new Error('no file provided');
|
||||||
if (/'/.test(file.name)) {
|
}
|
||||||
console.log('file name had apostrophe in it');
|
if (/'/.test(file.name)) {
|
||||||
throw new Error('apostrophes are not allowed in the file name');
|
console.log('file name had apostrophe in it');
|
||||||
}
|
throw new Error('apostrophes are not allowed in the file name');
|
||||||
// validate size and type
|
}
|
||||||
switch (file.type) {
|
// validate size and type
|
||||||
case 'image/jpeg':
|
switch (file.type) {
|
||||||
case 'image/jpg':
|
case 'image/jpeg':
|
||||||
case 'image/png':
|
case 'image/jpg':
|
||||||
if (file.size > 10000000){
|
case 'image/png':
|
||||||
console.log('file was too big');
|
if (file.size > 10000000) {
|
||||||
throw new Error('Sorry, images are limited to 10 megabytes.');
|
console.log('file was too big');
|
||||||
}
|
throw new Error('Sorry, images are limited to 10 megabytes.');
|
||||||
break;
|
|
||||||
case 'image/gif':
|
|
||||||
if (file.size > 50000000){
|
|
||||||
console.log('file was too big');
|
|
||||||
throw new Error('Sorry, .gifs are limited to 50 megabytes.');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'video/mp4':
|
|
||||||
if (file.size > 50000000){
|
|
||||||
console.log('file was too big');
|
|
||||||
throw new Error('Sorry, videos are limited to 50 megabytes.');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
console.log('file type is not supported');
|
|
||||||
throw new Error(file.type + ' is not a supported file type. Only, .jpeg, .png, .gif, and .mp4 files are currently supported.')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// validation function that checks to make sure the claim name is valid
|
|
||||||
function validateClaimName (name) {
|
|
||||||
// ensure a name was entered
|
|
||||||
if (name.length < 1) {
|
|
||||||
throw new NameError("You must enter a name for your url");
|
|
||||||
}
|
|
||||||
// validate the characters in the 'name' field
|
|
||||||
const invalidCharacters = /[^A-Za-z0-9,-]/g.exec(name);
|
|
||||||
if (invalidCharacters) {
|
|
||||||
throw new NameError('"' + invalidCharacters + '" characters are not allowed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function validateChannelName (name) {
|
|
||||||
name = name.substring(name.indexOf('@') + 1);
|
|
||||||
// ensure a name was entered
|
|
||||||
if (name.length < 1) {
|
|
||||||
throw new ChannelNameError("You must enter a name for your channel");
|
|
||||||
}
|
|
||||||
// validate the characters in the 'name' field
|
|
||||||
const invalidCharacters = /[^A-Za-z0-9,-,@]/g.exec(name);
|
|
||||||
if (invalidCharacters) {
|
|
||||||
throw new ChannelNameError('"' + invalidCharacters + '" characters are not allowed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function validatePassword (password) {
|
|
||||||
if (password.length < 1) {
|
|
||||||
throw new ChannelPasswordError("You must enter a password for you channel");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function cleanseClaimName(name) {
|
|
||||||
name = name.replace(/\s+/g, '-'); // replace spaces with dashes
|
|
||||||
name = name.replace(/[^A-Za-z0-9-]/g, ''); // remove all characters that are not A-Z, a-z, 0-9, or '-'
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
// validation functions to check claim & channel name eligibility as the inputs change
|
|
||||||
|
|
||||||
function isNameAvailable (name, apiUrl) {
|
|
||||||
const url = apiUrl + name;
|
|
||||||
return getRequest(url)
|
|
||||||
}
|
|
||||||
|
|
||||||
function showError(errorDisplay, errorMsg) {
|
|
||||||
errorDisplay.hidden = false;
|
|
||||||
errorDisplay.innerText = errorMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
function hideError(errorDisplay) {
|
|
||||||
errorDisplay.hidden = true;
|
|
||||||
errorDisplay.innerText = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function showSuccess (successElement) {
|
|
||||||
successElement.hidden = false;
|
|
||||||
successElement.innerHTML = "✔";
|
|
||||||
}
|
|
||||||
|
|
||||||
function hideSuccess (successElement) {
|
|
||||||
successElement.hidden = true;
|
|
||||||
successElement.innerHTML = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkAvailability(name, successDisplayElement, errorDisplayElement, validateName, isNameAvailable, errorMessage, apiUrl) {
|
|
||||||
try {
|
|
||||||
// check to make sure the characters are valid
|
|
||||||
validateName(name);
|
|
||||||
// check to make sure it is available
|
|
||||||
isNameAvailable(name, apiUrl)
|
|
||||||
.then(result => {
|
|
||||||
if (result === true) {
|
|
||||||
hideError(errorDisplayElement);
|
|
||||||
showSuccess(successDisplayElement)
|
|
||||||
} else {
|
|
||||||
hideSuccess(successDisplayElement);
|
|
||||||
showError(errorDisplayElement, errorMessage);
|
|
||||||
}
|
}
|
||||||
})
|
break;
|
||||||
.catch(error => {
|
case 'image/gif':
|
||||||
hideSuccess(successDisplayElement);
|
if (file.size > 50000000) {
|
||||||
showError(errorDisplayElement, error.message);
|
console.log('file was too big');
|
||||||
});
|
throw new Error('Sorry, .gifs are limited to 50 megabytes.');
|
||||||
} catch (error) {
|
|
||||||
hideSuccess(successDisplayElement);
|
|
||||||
showError(errorDisplayElement, error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkClaimName(name){
|
|
||||||
const successDisplayElement = document.getElementById('input-success-claim-name');
|
|
||||||
const errorDisplayElement = document.getElementById('input-error-claim-name');
|
|
||||||
checkAvailability(name, successDisplayElement, errorDisplayElement, validateClaimName, isNameAvailable, 'Sorry, that ending is already taken', '/api/isClaimAvailable/');
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkChannelName(name){
|
|
||||||
const successDisplayElement = document.getElementById('input-success-channel-name');
|
|
||||||
const errorDisplayElement = document.getElementById('input-error-channel-name');
|
|
||||||
name = `@${name}`;
|
|
||||||
checkAvailability(name, successDisplayElement, errorDisplayElement, validateChannelName, isNameAvailable, 'Sorry, that name is already taken', '/api/isChannelAvailable/');
|
|
||||||
}
|
|
||||||
|
|
||||||
// validation function which checks all aspects of the publish submission
|
|
||||||
function validateFilePublishSubmission(stagedFiles, claimName, channelName){
|
|
||||||
return new Promise(function (resolve, reject) {
|
|
||||||
// 1. make sure 1 file was staged
|
|
||||||
if (!stagedFiles) {
|
|
||||||
reject(new FileError("Please select a file"));
|
|
||||||
return;
|
|
||||||
} else if (stagedFiles.length > 1) {
|
|
||||||
reject(new FileError("Only one file is allowed at a time"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 2. validate the file's name, type, and size
|
|
||||||
try {
|
|
||||||
validateFile(stagedFiles[0]);
|
|
||||||
} catch (error) {
|
|
||||||
reject(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 3. validate that a channel was chosen
|
|
||||||
if (channelName === 'new' || channelName === 'login') {
|
|
||||||
reject(new ChannelNameError("Please log in to a channel"));
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
// 4. validate the claim name
|
|
||||||
try {
|
|
||||||
validateClaimName(claimName);
|
|
||||||
} catch (error) {
|
|
||||||
reject(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// if all validation passes, check availability of the name (note: do we need to re-validate channel name vs. credentials as well?)
|
|
||||||
return isNameAvailable(claimName, '/api/isClaimAvailable/')
|
|
||||||
.then(result => {
|
|
||||||
if (result) {
|
|
||||||
resolve();
|
|
||||||
} else {
|
|
||||||
reject(new NameError('Sorry, that ending is already taken'));
|
|
||||||
}
|
}
|
||||||
})
|
break;
|
||||||
.catch(error => {
|
case 'video/mp4':
|
||||||
|
if (file.size > 50000000) {
|
||||||
|
console.log('file was too big');
|
||||||
|
throw new Error('Sorry, videos are limited to 50 megabytes.');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log('file type is not supported');
|
||||||
|
throw new Error(file.type + ' is not a supported file type. Only, .jpeg, .png, .gif, and .mp4 files are currently supported.')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// validation function that checks to make sure the claim name is valid
|
||||||
|
validateClaimName: function (name) {
|
||||||
|
console.log('validating the claim name');
|
||||||
|
// ensure a name was entered
|
||||||
|
if (name.length < 1) {
|
||||||
|
throw new NameError("You must enter a name for your url");
|
||||||
|
}
|
||||||
|
// validate the characters in the 'name' field
|
||||||
|
const invalidCharacters = /[^A-Za-z0-9,-]/g.exec(name);
|
||||||
|
if (invalidCharacters) {
|
||||||
|
throw new NameError('"' + invalidCharacters + '" characters are not allowed');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
validateChannelName: function (name) {
|
||||||
|
name = name.substring(name.indexOf('@') + 1);
|
||||||
|
// ensure a name was entered
|
||||||
|
if (name.length < 1) {
|
||||||
|
throw new ChannelNameError("You must enter a name for your channel");
|
||||||
|
}
|
||||||
|
// validate the characters in the 'name' field
|
||||||
|
const invalidCharacters = /[^A-Za-z0-9,-,@]/g.exec(name);
|
||||||
|
if (invalidCharacters) {
|
||||||
|
throw new ChannelNameError('"' + invalidCharacters + '" characters are not allowed');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
validatePassword: function (password) {
|
||||||
|
if (password.length < 1) {
|
||||||
|
throw new ChannelPasswordError("You must enter a password for you channel");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cleanseClaimName: function (name) {
|
||||||
|
name = name.replace(/\s+/g, '-'); // replace spaces with dashes
|
||||||
|
name = name.replace(/[^A-Za-z0-9-]/g, ''); // remove all characters that are not A-Z, a-z, 0-9, or '-'
|
||||||
|
return name;
|
||||||
|
},
|
||||||
|
// validation functions to check claim & channel name eligibility as the inputs change
|
||||||
|
isNameAvailable: function (name, apiUrl) {
|
||||||
|
const url = apiUrl + name;
|
||||||
|
return getRequest(url)
|
||||||
|
},
|
||||||
|
showError: function (errorDisplay, errorMsg) {
|
||||||
|
errorDisplay.hidden = false;
|
||||||
|
errorDisplay.innerText = errorMsg;
|
||||||
|
},
|
||||||
|
hideError: function (errorDisplay) {
|
||||||
|
errorDisplay.hidden = true;
|
||||||
|
errorDisplay.innerText = '';
|
||||||
|
},
|
||||||
|
showSuccess: function (successElement) {
|
||||||
|
successElement.hidden = false;
|
||||||
|
successElement.innerHTML = "✔";
|
||||||
|
},
|
||||||
|
hideSuccess: function (successElement) {
|
||||||
|
successElement.hidden = true;
|
||||||
|
successElement.innerHTML = "";
|
||||||
|
},
|
||||||
|
checkAvailability: function (name, successDisplayElement, errorDisplayElement, validateName, errorMessage, apiUrl) {
|
||||||
|
var that = this;
|
||||||
|
try {
|
||||||
|
// check to make sure the characters are valid
|
||||||
|
validateName(name);
|
||||||
|
// check to make sure it is available
|
||||||
|
that.isNameAvailable(name, apiUrl)
|
||||||
|
.then(function (result) {
|
||||||
|
if (result === true) {
|
||||||
|
that.hideError(errorDisplayElement);
|
||||||
|
that.showSuccess(successDisplayElement)
|
||||||
|
} else {
|
||||||
|
that.hideSuccess(successDisplayElement);
|
||||||
|
that.showError(errorDisplayElement, errorMessage);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
that.hideSuccess(successDisplayElement);
|
||||||
|
that.showError(errorDisplayElement, error.message);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
that.hideSuccess(successDisplayElement);
|
||||||
|
that.showError(errorDisplayElement, error.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
checkClaimName: function (name) {
|
||||||
|
const successDisplayElement = document.getElementById('input-success-claim-name');
|
||||||
|
const errorDisplayElement = document.getElementById('input-error-claim-name');
|
||||||
|
this.checkAvailability(name, successDisplayElement, errorDisplayElement, this.validateClaimName, 'Sorry, that ending is already taken', '/api/isClaimAvailable/');
|
||||||
|
},
|
||||||
|
checkChannelName: function (name) {
|
||||||
|
const successDisplayElement = document.getElementById('input-success-channel-name');
|
||||||
|
const errorDisplayElement = document.getElementById('input-error-channel-name');
|
||||||
|
name = `@${name}`;
|
||||||
|
this.checkAvailability(name, successDisplayElement, errorDisplayElement, this.validateChannelName, 'Sorry, that name is already taken', '/api/isChannelAvailable/');
|
||||||
|
},
|
||||||
|
// validation function which checks all aspects of the publish submission
|
||||||
|
validateFilePublishSubmission: function (stagedFiles, metadata) {
|
||||||
|
const channelName = metadata.channelName;
|
||||||
|
const claimName = metadata.name;
|
||||||
|
var that = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
// 1. make sure 1 file was staged
|
||||||
|
if (!stagedFiles) {
|
||||||
|
reject(new FileError("Please select a file"));
|
||||||
|
return;
|
||||||
|
} else if (stagedFiles.length > 1) {
|
||||||
|
reject(new FileError("Only one file is allowed at a time"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 2. validate the file's name, type, and size
|
||||||
|
try {
|
||||||
|
that.validateFile(stagedFiles[0]);
|
||||||
|
} catch (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
return;
|
||||||
});
|
}
|
||||||
}
|
// 3. validate that a channel was chosen
|
||||||
|
if (channelName === 'new' || channelName === 'login') {
|
||||||
// validation function which checks all aspects of a new channel submission
|
reject(new ChannelNameError("Please log in to a channel"));
|
||||||
function validateNewChannelSubmission(userName, password){
|
return;
|
||||||
const channelName = `@${userName}`;
|
}
|
||||||
return new Promise(function (resolve, reject) {
|
;
|
||||||
// 1. validate name
|
// 4. validate the claim name
|
||||||
try {
|
try {
|
||||||
validateChannelName(channelName);
|
that.validateClaimName(claimName);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return reject(error);
|
|
||||||
}
|
|
||||||
// 2. validate password
|
|
||||||
try {
|
|
||||||
validatePassword(password);
|
|
||||||
} catch (error) {
|
|
||||||
return reject(error);
|
|
||||||
}
|
|
||||||
// 3. if all validation passes, check availability of the name
|
|
||||||
isNameAvailable(channelName, '/api/isChannelAvailable/') // validate the availability
|
|
||||||
.then(result => {
|
|
||||||
if (result) {
|
|
||||||
resolve();
|
|
||||||
} else {
|
|
||||||
reject(new ChannelNameError('Sorry, that name is already taken'));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch( error => {
|
|
||||||
console.log('error evaluating channel name availability', error);
|
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
return;
|
||||||
});
|
}
|
||||||
}
|
// if all validation passes, check availability of the name (note: do we need to re-validate channel name vs. credentials as well?)
|
||||||
// validation function which checks all aspects of a new channel login
|
return that.isNameAvailable(claimName, '/api/isClaimAvailable/')
|
||||||
function validateNewChannelLogin(userName, password){
|
.then(result => {
|
||||||
const channelName = `@${userName}`;
|
if (result) {
|
||||||
return new Promise(function (resolve, reject) {
|
resolve();
|
||||||
// 1. validate name
|
} else {
|
||||||
try {
|
reject(new NameError('Sorry, that ending is already taken'));
|
||||||
validateChannelName(channelName);
|
}
|
||||||
} catch (error) {
|
})
|
||||||
return reject(error);
|
.catch(error => {
|
||||||
}
|
reject(error);
|
||||||
// 2. validate password
|
});
|
||||||
try {
|
});
|
||||||
validatePassword(password);
|
},
|
||||||
} catch (error) {
|
// validation function which checks all aspects of a new channel submission
|
||||||
return reject(error);
|
validateNewChannelSubmission: function (userName, password) {
|
||||||
}
|
const channelName = `@${userName}`;
|
||||||
resolve();
|
var that = this;
|
||||||
});
|
return new Promise(function (resolve, reject) {
|
||||||
}
|
// 1. validate name
|
||||||
|
try {
|
||||||
|
that.validateChannelName(channelName);
|
||||||
|
} catch (error) {
|
||||||
|
return reject(error);
|
||||||
|
}
|
||||||
|
// 2. validate password
|
||||||
|
try {
|
||||||
|
that.validatePassword(password);
|
||||||
|
} catch (error) {
|
||||||
|
return reject(error);
|
||||||
|
}
|
||||||
|
// 3. if all validation passes, check availability of the name
|
||||||
|
that.isNameAvailable(channelName, '/api/isChannelAvailable/') // validate the availability
|
||||||
|
.then(function(result) {
|
||||||
|
if (result) {
|
||||||
|
resolve();
|
||||||
|
} else {
|
||||||
|
reject(new ChannelNameError('Sorry, that name is already taken'));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(function(error) {
|
||||||
|
console.log('error evaluating channel name availability', error);
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// validation function which checks all aspects of a new channel login
|
||||||
|
validateNewChannelLogin: function (userName, password) {
|
||||||
|
const channelName = `@${userName}`;
|
||||||
|
var that = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
// 1. validate name
|
||||||
|
try {
|
||||||
|
that.validateChannelName(channelName);
|
||||||
|
} catch (error) {
|
||||||
|
return reject(error);
|
||||||
|
}
|
||||||
|
// 2. validate password
|
||||||
|
try {
|
||||||
|
that.validatePassword(password);
|
||||||
|
} catch (error) {
|
||||||
|
return reject(error);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,13 +1,13 @@
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const multipart = require('connect-multiparty');
|
const multipart = require('connect-multiparty');
|
||||||
const multipartMiddleware = multipart();
|
const multipartMiddleware = multipart({uploadDir: '/home/lbry/test/'});
|
||||||
const db = require('../models');
|
const db = require('../models');
|
||||||
const { publish } = require('../controllers/publishController.js');
|
const { publish } = require('../controllers/publishController.js');
|
||||||
const { getClaimList, resolveUri } = require('../helpers/lbryApi.js');
|
const { getClaimList, resolveUri } = require('../helpers/lbryApi.js');
|
||||||
const { createPublishParams, validateApiPublishRequest, validatePublishSubmission, cleanseNSFW, cleanseChannelName, checkClaimNameAvailability, checkChannelAvailability } = require('../helpers/publishHelpers.js');
|
const { createPublishParams, validateApiPublishRequest, validatePublishSubmission, cleanseChannelName, checkClaimNameAvailability, checkChannelAvailability } = require('../helpers/publishHelpers.js');
|
||||||
const errorHandlers = require('../helpers/errorHandlers.js');
|
const errorHandlers = require('../helpers/errorHandlers.js');
|
||||||
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
|
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
|
||||||
const { authenticateChannelCredentials } = require('../auth/authentication.js');
|
const { authenticateOrSkip } = require('../auth/authentication.js');
|
||||||
|
|
||||||
module.exports = (app) => {
|
module.exports = (app) => {
|
||||||
// route to run a claim_list request on the daemon
|
// route to run a claim_list request on the daemon
|
||||||
|
@ -21,7 +21,7 @@ module.exports = (app) => {
|
||||||
res.status(200).json(claimsList);
|
res.status(200).json(claimsList);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
errorHandlers.handleRequestError('publish', originalUrl, ip, error, res);
|
errorHandlers.handleApiError('claim_list', originalUrl, ip, error, res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// route to check whether spee.ch has published to a claim
|
// route to check whether spee.ch has published to a claim
|
||||||
|
@ -67,15 +67,13 @@ module.exports = (app) => {
|
||||||
res.status(200).json(resolvedUri);
|
res.status(200).json(resolvedUri);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
errorHandlers.handleRequestError('publish', originalUrl, ip, error, res);
|
errorHandlers.handleApiError('resolve', originalUrl, ip, error, res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// route to run a publish request on the daemon
|
// route to run a publish request on the daemon
|
||||||
app.post('/api/publish', multipartMiddleware, (req, res) => {
|
app.post('/api/publish', multipartMiddleware, ({ body, files, ip, originalUrl, user }, res) => {
|
||||||
logger.debug('req:', req);
|
let file, fileName, filePath, fileType, name, nsfw, license, title, description, thumbnail, anonymous, skipAuth, channelName, channelPassword;
|
||||||
// validate that mandatory parts of the request are present
|
// validate that mandatory parts of the request are present
|
||||||
const body = req.body;
|
|
||||||
const files = req.files;
|
|
||||||
try {
|
try {
|
||||||
validateApiPublishRequest(body, files);
|
validateApiPublishRequest(body, files);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -84,13 +82,12 @@ module.exports = (app) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// validate file, name, license, and nsfw
|
// validate file, name, license, and nsfw
|
||||||
const file = files.file;
|
file = files.file;
|
||||||
const fileName = file.name;
|
fileName = file.path.substring(file.path.lastIndexOf('/') + 1);
|
||||||
const filePath = file.path;
|
filePath = file.path;
|
||||||
const fileType = file.type;
|
fileType = file.type;
|
||||||
const name = body.name;
|
name = body.name;
|
||||||
let nsfw = body.nsfw;
|
nsfw = (body.nsfw === 'true');
|
||||||
nsfw = cleanseNSFW(nsfw); // cleanse nsfw
|
|
||||||
try {
|
try {
|
||||||
validatePublishSubmission(file, name, nsfw);
|
validatePublishSubmission(file, name, nsfw);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -98,20 +95,38 @@ module.exports = (app) => {
|
||||||
res.status(400).json({success: false, message: error.message});
|
res.status(400).json({success: false, message: error.message});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.debug(`name: ${name}, nsfw: ${nsfw}`);
|
|
||||||
// optional inputs
|
// optional inputs
|
||||||
const license = body.license || null;
|
license = body.license || null;
|
||||||
const title = body.title || null;
|
title = body.title || null;
|
||||||
const description = body.description || null;
|
description = body.description || null;
|
||||||
const thumbnail = body.thumbnail || null;
|
thumbnail = body.thumbnail || null;
|
||||||
let channelName = body.channelName || null;
|
anonymous = (body.channelName === 'null') || (body.channelName === undefined);
|
||||||
|
if (user) {
|
||||||
|
channelName = user.channelName || null;
|
||||||
|
} else {
|
||||||
|
channelName = body.channelName || null;
|
||||||
|
}
|
||||||
|
channelPassword = body.channelPassword || null;
|
||||||
|
skipAuth = false;
|
||||||
|
// case 1: publish from spee.ch, client logged in
|
||||||
|
if (user) {
|
||||||
|
skipAuth = true;
|
||||||
|
if (anonymous) {
|
||||||
|
channelName = null;
|
||||||
|
}
|
||||||
|
// case 2: publish from api or spee.ch, client not logged in
|
||||||
|
} else {
|
||||||
|
if (anonymous) {
|
||||||
|
skipAuth = true;
|
||||||
|
channelName = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
channelName = cleanseChannelName(channelName);
|
channelName = cleanseChannelName(channelName);
|
||||||
const channelPassword = body.channelPassword || null;
|
logger.debug(`/api/publish > name: ${name}, license: ${license} title: "${title}" description: "${description}" channelName: "${channelName}" channelPassword: "${channelPassword}" nsfw: "${nsfw}"`);
|
||||||
logger.debug(`license: ${license} title: "${title}" description: "${description}" channelName: "${channelName}" channelPassword: "${channelPassword}"`);
|
|
||||||
// check channel authorization
|
// check channel authorization
|
||||||
authenticateChannelCredentials(channelName, channelPassword)
|
authenticateOrSkip(skipAuth, channelName, channelPassword)
|
||||||
.then(result => {
|
.then(authenticated => {
|
||||||
if (!result) {
|
if (!authenticated) {
|
||||||
throw new Error('Authentication failed, you do not have access to that channel');
|
throw new Error('Authentication failed, you do not have access to that channel');
|
||||||
}
|
}
|
||||||
// make sure the claim name is available
|
// make sure the claim name is available
|
||||||
|
@ -133,14 +148,14 @@ module.exports = (app) => {
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
message: {
|
message: {
|
||||||
|
name,
|
||||||
url : `spee.ch/${result.claim_id}/${name}`,
|
url : `spee.ch/${result.claim_id}/${name}`,
|
||||||
lbryTx: result,
|
lbryTx: result,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
logger.error('publish api error', error);
|
errorHandlers.handleApiError('publish', originalUrl, ip, error, res);
|
||||||
res.status(400).json({success: false, message: error.message});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -157,7 +172,7 @@ module.exports = (app) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// route to get a short channel id from long channel Id
|
// route to get a short channel id from long channel Id
|
||||||
app.get('/api/shortChannelId/:longId/:name', ({ params }, res) => {
|
app.get('/api/shortChannelId/:longId/:name', ({ ip, originalUrl, params }, res) => {
|
||||||
// serve content
|
// serve content
|
||||||
db.Certificate.getShortChannelIdFromLongChannelId(params.longId, params.name)
|
db.Certificate.getShortChannelIdFromLongChannelId(params.longId, params.name)
|
||||||
.then(shortId => {
|
.then(shortId => {
|
||||||
|
@ -166,7 +181,7 @@ module.exports = (app) => {
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
logger.error('api error getting short channel id', error);
|
logger.error('api error getting short channel id', error);
|
||||||
res.status(400).json(error.message);
|
errorHandlers.handleApiError('short channel id', originalUrl, ip, error, res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,7 +24,7 @@ module.exports = (app) => {
|
||||||
app.get('/trending', (req, res) => {
|
app.get('/trending', (req, res) => {
|
||||||
res.status(301).redirect('/popular');
|
res.status(301).redirect('/popular');
|
||||||
});
|
});
|
||||||
app.get('/popular', (req, res) => {
|
app.get('/popular', ({ ip, originalUrl }, res) => {
|
||||||
const startDate = new Date();
|
const startDate = new Date();
|
||||||
startDate.setDate(startDate.getDate() - 1);
|
startDate.setDate(startDate.getDate() - 1);
|
||||||
const dateTime = startDate.toISOString().slice(0, 19).replace('T', ' ');
|
const dateTime = startDate.toISOString().slice(0, 19).replace('T', ' ');
|
||||||
|
@ -36,20 +36,18 @@ module.exports = (app) => {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
errorHandlers.handleRequestError(null, null, null, error, res);
|
errorHandlers.handleRequestError('popular', originalUrl, ip, error, res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// route to display a list of the trending images
|
// route to display a list of the trending images
|
||||||
app.get('/new', (req, res) => {
|
app.get('/new', ({ ip, originalUrl }, res) => {
|
||||||
getRecentClaims()
|
getRecentClaims()
|
||||||
.then(result => {
|
.then(result => {
|
||||||
// logger.debug(result);
|
// logger.debug(result);
|
||||||
res.status(200).render('new', {
|
res.status(200).render('new', { newClaims: result });
|
||||||
newClaims: result,
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
errorHandlers.handleRequestError(null, null, null, error, res);
|
errorHandlers.handleRequestError('new', originalUrl, ip, error, res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// route to send embedable video player (for twitter)
|
// route to send embedable video player (for twitter)
|
||||||
|
|
|
@ -49,7 +49,6 @@ function extractPageFromClaims (claims, pageNumber) {
|
||||||
const claimStartIndex = (pageNumber - 1) * CLAIMS_PER_PAGE;
|
const claimStartIndex = (pageNumber - 1) * CLAIMS_PER_PAGE;
|
||||||
const claimEndIndex = claimStartIndex + 10;
|
const claimEndIndex = claimStartIndex + 10;
|
||||||
const pageOfClaims = claims.slice(claimStartIndex, claimEndIndex);
|
const pageOfClaims = claims.slice(claimStartIndex, claimEndIndex);
|
||||||
logger.debug('page of claims:', pageOfClaims);
|
|
||||||
return pageOfClaims;
|
return pageOfClaims;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
|
||||||
};
|
|
11
speech.js
11
speech.js
|
@ -6,7 +6,7 @@ const expressHandlebars = require('express-handlebars');
|
||||||
const Handlebars = require('handlebars');
|
const Handlebars = require('handlebars');
|
||||||
const handlebarsHelpers = require('./helpers/handlebarsHelpers.js');
|
const handlebarsHelpers = require('./helpers/handlebarsHelpers.js');
|
||||||
const { populateLocalsDotUser, serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js');
|
const { populateLocalsDotUser, serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js');
|
||||||
const config = require('config');
|
const config = require('./config/speechConfig.js');
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const { getDownloadDirectory } = require('./helpers/lbryApi');
|
const { getDownloadDirectory } = require('./helpers/lbryApi');
|
||||||
const helmet = require('helmet');
|
const helmet = require('helmet');
|
||||||
|
@ -17,9 +17,9 @@ const passport = require('passport');
|
||||||
const cookieSession = require('cookie-session');
|
const cookieSession = require('cookie-session');
|
||||||
|
|
||||||
// configure logging
|
// configure logging
|
||||||
const logLevel = config.get('Logging.LogLevel');
|
const logLevel = config.logging.logLevel;
|
||||||
require('./config/loggerConfig.js')(logger, logLevel);
|
require('./config/loggerConfig.js')(logger, logLevel);
|
||||||
require('./config/slackLoggerConfig.js')(logger);
|
require('./config/slackConfig.js')(logger);
|
||||||
|
|
||||||
// check for global config variables
|
// check for global config variables
|
||||||
require('./helpers/configVarCheck.js')();
|
require('./helpers/configVarCheck.js')();
|
||||||
|
@ -42,7 +42,7 @@ app.use((req, res, next) => { // custom logging middleware to log all incoming
|
||||||
// initialize passport
|
// initialize passport
|
||||||
app.use(cookieSession({
|
app.use(cookieSession({
|
||||||
name : 'session',
|
name : 'session',
|
||||||
keys : [config.get('Session.SessionKey')],
|
keys : [config.session.sessionKey],
|
||||||
maxAge: 24 * 60 * 60 * 1000, // 24 hours
|
maxAge: 24 * 60 * 60 * 1000, // 24 hours
|
||||||
}));
|
}));
|
||||||
app.use(passport.initialize());
|
app.use(passport.initialize());
|
||||||
|
@ -82,7 +82,8 @@ db.sequelize
|
||||||
require('./routes/page-routes.js')(app);
|
require('./routes/page-routes.js')(app);
|
||||||
require('./routes/serve-routes.js')(app);
|
require('./routes/serve-routes.js')(app);
|
||||||
require('./routes/home-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
|
.then(server => { // start the server
|
||||||
server.listen(PORT, () => {
|
server.listen(PORT, () => {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<div class="row">
|
<div class="row row--padded">
|
||||||
<h3>404: Not Found</h3>
|
<h3>404: Not Found</h3>
|
||||||
<p>That page does not exist. Return <a class="link--primary" href="/">home</a>.</p>
|
<p>That page does not exist. Return <a class="link--primary" href="/">home</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<div class="row row--tall flex-container--column">
|
<div class="row row--tall flex-container--column">
|
||||||
<form>
|
<form>
|
||||||
<input class="input-file" type="file" id="siofu_input" name="siofu_input" accept="video/*,image/*" onchange="previewAndStageFile(event.target.files[0])" enctype="multipart/form-data"/>
|
<input class="input-file" type="file" id="siofu_input" name="siofu_input" accept="video/*,image/*" onchange="publishFileFunctions.previewAndStageFile(event.target.files[0])" enctype="multipart/form-data"/>
|
||||||
</form>
|
</form>
|
||||||
<div id="primary-dropzone" class="dropzone row row--margined row--padded row--tall flex-container--column flex-container--center-center" ondrop="drop_handler(event);" ondragover="dragover_handler(event);" ondragend="dragend_handler(event)" ondragenter="dragenter_handler(event)" ondragleave="dragexit_handler(event)" onclick="triggerFileChooser('siofu_input', event)">
|
<div id="primary-dropzone" class="dropzone row row--margined row--padded row--tall flex-container--column flex-container--center-center" ondrop="drop_handler(event);" ondragover="dragover_handler(event);" ondragend="dragend_handler(event)" ondragenter="dragenter_handler(event)" ondragleave="dragexit_handler(event)" onclick="publishFileFunctions.triggerFileChooser('siofu_input', event)">
|
||||||
<div id="primary-dropzone-instructions">
|
<div id="primary-dropzone-instructions">
|
||||||
<p class="info-message-placeholder info-message--failure" id="input-error-file-selection" hidden="true"></p>
|
<p class="info-message-placeholder info-message--failure" id="input-error-file-selection" hidden="true"></p>
|
||||||
<p>Drag & drop image or video here to publish</p>
|
<p>Drag & drop image or video here to publish</p>
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
<div class="column column--5 column--sml-10" >
|
<div class="column column--5 column--sml-10" >
|
||||||
<!-- preview -->
|
<!-- preview -->
|
||||||
<div class="row row--padded">
|
<div class="row row--padded">
|
||||||
<div id="asset-preview-holder" class="dropzone" ondrop="drop_handler(event);" ondragover="dragover_handler(event);" ondragend="dragend_handler(event)" ondragenter="preview_onmouseenter_handler()" ondragleave="preview_onmouseleave_handler()" onmouseenter="preview_onmouseenter_handler()" onmouseleave="preview_onmouseleave_handler()" onclick="triggerFileChooser('siofu_input', event)">
|
<div id="asset-preview-holder" class="dropzone" ondrop="drop_handler(event);" ondragover="dragover_handler(event);" ondragend="dragend_handler(event)" ondragenter="preview_onmouseenter_handler()" ondragleave="preview_onmouseleave_handler()" onmouseenter="preview_onmouseenter_handler()" onmouseleave="preview_onmouseleave_handler()" onclick="publishFileFunctions.triggerFileChooser('siofu_input', event)">
|
||||||
<div id="asset-preview-dropzone-instructions" class="hidden">
|
<div id="asset-preview-dropzone-instructions" class="hidden">
|
||||||
<p>Drag & drop image or video here</p>
|
<p>Drag & drop image or video here</p>
|
||||||
<p class="fine-print">OR</p>
|
<p class="fine-print">OR</p>
|
||||||
|
@ -50,105 +50,3 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</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');
|
|
||||||
const publishStatus = document.getElementById('publish-status');
|
|
||||||
const publishUpdate = document.getElementById('publish-update');
|
|
||||||
const publishProgressBar = document.getElementById('publish-progress-bar');
|
|
||||||
const uploadPercent = document.getElementById('upload-percent');
|
|
||||||
|
|
||||||
/* socketio-file-upload listeners */
|
|
||||||
uploader.addEventListener('start', function(event){
|
|
||||||
console.log('starting upload');
|
|
||||||
addInputValuesToFileMetaData(event)
|
|
||||||
// hide the publish tool
|
|
||||||
hidePublishTools();
|
|
||||||
// show the progress status and animation
|
|
||||||
showPublishStatus();
|
|
||||||
showPublishProgressBar();
|
|
||||||
});
|
|
||||||
uploader.addEventListener('progress', function(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){
|
|
||||||
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){
|
|
||||||
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){
|
|
||||||
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');
|
|
||||||
}
|
|
||||||
// publish status functions
|
|
||||||
function showPublishStatus() {
|
|
||||||
publishStatus.setAttribute('class', 'row row--tall flex-container--column flex-container--center-center');
|
|
||||||
}
|
|
||||||
function updatePublishStatus(msg){
|
|
||||||
publishUpdate.innerHTML = msg;
|
|
||||||
}
|
|
||||||
// progress bar functions
|
|
||||||
function showPublishProgressBar(){
|
|
||||||
createProgressBar(publishProgressBar, 12);
|
|
||||||
}
|
|
||||||
function hidePublishProgressBar(){
|
|
||||||
publishProgressBar.hidden = true;
|
|
||||||
}
|
|
||||||
// upload percent functions
|
|
||||||
function updateUploadPercent(msg){
|
|
||||||
uploadPercent.innerHTML = msg;
|
|
||||||
}
|
|
||||||
function hideUploadPercent(){
|
|
||||||
uploadPercent.hidden = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function addInputValuesToFileMetaData(event) {
|
|
||||||
// get values from inputs
|
|
||||||
const name = document.getElementById('claim-name-input').value.trim();
|
|
||||||
const title = document.getElementById('publish-title').value.trim();
|
|
||||||
const description = document.getElementById('publish-description').value.trim();
|
|
||||||
const license = document.getElementById('publish-license').value.trim();
|
|
||||||
const nsfw = document.getElementById('publish-nsfw').checked;
|
|
||||||
const anonymous = document.getElementById('anonymous-select').checked;
|
|
||||||
const channel = document.getElementById('channel-name-select').value.trim();
|
|
||||||
const thumbnail = document.getElementById('claim-thumbnail-input').value.trim();
|
|
||||||
// set values on file meta data
|
|
||||||
event.file.meta.name = name;
|
|
||||||
event.file.meta.title = title;
|
|
||||||
event.file.meta.description = description;
|
|
||||||
event.file.meta.license = license;
|
|
||||||
event.file.meta.nsfw = nsfw;
|
|
||||||
event.file.meta.type = stagedFiles[0].type;
|
|
||||||
if (!anonymous) {
|
|
||||||
event.file.meta.channel = channel;
|
|
||||||
}
|
|
||||||
if (thumbnail && (thumbnail.trim !== '')){
|
|
||||||
event.file.meta.thumbnail = thumbnail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
<!-- google analytics -->
|
<!-- google analytics -->
|
||||||
{{ googleAnalytics }}
|
{{ googleAnalytics }}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body id="channel-body">
|
||||||
<script src="/assets/js/generalFunctions.js"></script>
|
<script src="/assets/js/generalFunctions.js"></script>
|
||||||
<script src="/assets/js/navBarFunctions.js"></script>
|
<script src="/assets/js/navBarFunctions.js"></script>
|
||||||
{{> navBar}}
|
{{> navBar}}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body id="embed-video-player">
|
||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
video {
|
video {
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
<!-- google analytics -->
|
<!-- google analytics -->
|
||||||
{{ googleAnalytics }}
|
{{ googleAnalytics }}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body id="main-body">
|
||||||
<script src="/assets/js/generalFunctions.js"></script>
|
<script src="/assets/js/generalFunctions.js"></script>
|
||||||
<script src="/assets/js/validationFunctions.js"></script>
|
<script src="/assets/js/validationFunctions.js"></script>
|
||||||
<script src="/assets/js/publishFileFunctions.js"></script>
|
<script src="/assets/js/publishFileFunctions.js"></script>
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<!-- google analytics -->
|
<!-- google analytics -->
|
||||||
{{ googleAnalytics }}
|
{{ googleAnalytics }}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body id="show-body">
|
||||||
<script src="/assets/js/generalFunctions.js"></script>
|
<script src="/assets/js/generalFunctions.js"></script>
|
||||||
<script src="/assets/js/navBarFunctions.js"></script>
|
<script src="/assets/js/navBarFunctions.js"></script>
|
||||||
{{> navBar}}
|
{{> navBar}}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
<!-- google analytics -->
|
<!-- google analytics -->
|
||||||
{{ googleAnalytics }}
|
{{ googleAnalytics }}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body id="showlite-body">
|
||||||
{{{ body }}}
|
{{{ body }}}
|
||||||
<script src="/assets/js/showFunctions.js"></script>
|
<script src="/assets/js/showFunctions.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
</div><div class="column column--6 column--sml-10">
|
</div><div class="column column--6 column--sml-10">
|
||||||
<div class="input-text--primary flex-container--row flex-container--left-bottom">
|
<div class="input-text--primary flex-container--row flex-container--left-bottom">
|
||||||
<span>@</span>
|
<span>@</span>
|
||||||
<input type="text" name="new-channel-name" id="new-channel-name" class="input-text" placeholder="exampleChannelName" value="" oninput="checkChannelName(event.target.value)">
|
<input type="text" name="new-channel-name" id="new-channel-name" class="input-text" placeholder="exampleChannelName" value="" oninput="validationFunctions.checkChannelName(event.target.value)">
|
||||||
<span id="input-success-channel-name" class="info-message--success"></span>
|
<span id="input-success-channel-name" class="info-message--success"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
<div class="column column--10">
|
<div class="column column--10">
|
||||||
<form>
|
<form>
|
||||||
<div class="column column--3 column--med-10">
|
<div class="column column--3 column--med-10">
|
||||||
<input type="radio" name="anonymous-or-channel" id="anonymous-select" class="input-radio" value="anonymous" {{#unless user}}checked {{/unless}} onchange="toggleChannel(event.target.value)"/>
|
<input type="radio" name="anonymous-or-channel" id="anonymous-radio" class="input-radio" value="anonymous" {{#unless user}}checked {{/unless}} onchange="toggleChannel(event.target.value)"/>
|
||||||
<label class="label label--pointer" for="anonymous-select">Anonymous</label>
|
<label class="label label--pointer" for="anonymous-radio">Anonymous</label>
|
||||||
</div><div class="column column--7 column--med-10">
|
</div><div class="column column--7 column--med-10">
|
||||||
<input type="radio" name="anonymous-or-channel" id="in-a-channel-select" class="input-radio" value="in a channel" {{#if user}}checked {{/if}} onchange="toggleChannel(event.target.value)"/>
|
<input type="radio" name="anonymous-or-channel" id="channel-radio" class="input-radio" value="in a channel" {{#if user}}checked {{/if}} onchange="toggleChannel(event.target.value)"/>
|
||||||
<label class="label label--pointer" for="in-a-channel-select">In a channel</label>
|
<label class="label label--pointer" for="channel-radio">In a channel</label>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<div class="row row--padded row--wide">
|
<div class="row row--padded row--wide">
|
||||||
<div class="input-error" id="input-error-publish-submit" hidden="true"></div>
|
<div class="input-error" id="input-error-publish-submit" hidden="true"></div>
|
||||||
<button id="publish-submit" class="button--primary button--large" onclick="publishStagedFile(event)">Upload</button>
|
<button id="publish-submit" class="button--primary button--large" onclick="publishFileFunctions.publishStagedFile(event)">Upload</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="row row--short align-content-center">
|
<div class="row row--short align-content-center">
|
||||||
<button class="button--cancel" onclick="cancelPublish()">Cancel</button>
|
<button class="button--cancel" onclick="publishFileFunctions.cancelPublish()">Cancel</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="row row--short align-content-center">
|
<div class="row row--short align-content-center">
|
||||||
<p class="fine-print">By clicking 'Upload', you affirm that you have the rights to publish this content to the LBRY network, and that you understand the properties of publishing it to a decentralized, user-controlled network. <a class="link--primary" target="_blank" href="https://lbry.io/learn">Read more.</a></p>
|
<p class="fine-print">By clicking 'Upload', you affirm that you have the rights to publish this content to the LBRY network, and that you understand the properties of publishing it to a decentralized, user-controlled network. <a class="link--primary" target="_blank" href="https://lbry.io/learn">Read more.</a></p>
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<span id="url-channel" class="url-text--secondary" {{#if user}}{{else}}hidden="true"{{/if}}>{{user.channelName}}:{{user.shortChannelId}}</span>
|
<span id="url-channel" class="url-text--secondary" {{#if user}}{{else}}hidden="true"{{/if}}>{{user.channelName}}:{{user.shortChannelId}}</span>
|
||||||
<span id="url-no-channel-placeholder" class="url-text--secondary tooltip" {{#if user}}hidden="true"{{else}}{{/if}}>xyz<span class="tooltip-text">This will be a random id</span></span>
|
<span id="url-no-channel-placeholder" class="url-text--secondary tooltip" {{#if user}}hidden="true"{{else}}{{/if}}>xyz<span class="tooltip-text">This will be a random id</span></span>
|
||||||
<span id="url-channel-placeholder" class="url-text--secondary tooltip" hidden="true">@channel<span class="tooltip-text">Select a channel above</span></span> /
|
<span id="url-channel-placeholder" class="url-text--secondary tooltip" hidden="true">@channel<span class="tooltip-text">Select a channel above</span></span> /
|
||||||
<input type="text" id="claim-name-input" class="input-text" placeholder="your-url-here" oninput="checkClaimName(event.target.value)">
|
<input type="text" id="claim-name-input" class="input-text" placeholder="your-url-here" oninput="validationFunctions.checkClaimName(event.target.value)">
|
||||||
<span id="input-success-claim-name" class="info-message--success span--absolute"></span>
|
<span id="input-success-claim-name" class="info-message--success span--absolute"></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue