commit
2311e5685f
8 changed files with 76 additions and 48 deletions
|
@ -1,6 +1,6 @@
|
||||||
import Request from '../utils/request';
|
import Request from '../utils/request';
|
||||||
|
|
||||||
export function getLongClaimId (host, name, modifier) {
|
export function getLongClaimId(host, name, modifier) {
|
||||||
let body = {};
|
let body = {};
|
||||||
// create request params
|
// create request params
|
||||||
if (modifier) {
|
if (modifier) {
|
||||||
|
@ -13,40 +13,40 @@ export function getLongClaimId (host, name, modifier) {
|
||||||
}
|
}
|
||||||
body['claimName'] = name;
|
body['claimName'] = name;
|
||||||
const params = {
|
const params = {
|
||||||
method : 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body : JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
};
|
};
|
||||||
// create url
|
// create url
|
||||||
const url = `${host}/api/claim/long-id`;
|
const url = `${host}/api/claim/long-id`;
|
||||||
// return the request promise
|
// return the request promise
|
||||||
return Request(url, params);
|
return Request(url, params);
|
||||||
};
|
}
|
||||||
|
|
||||||
export function getShortId (host, name, claimId) {
|
export function getShortId(host, name, claimId) {
|
||||||
const url = `${host}/api/claim/short-id/${claimId}/${name}`;
|
const url = `${host}/api/claim/short-id/${claimId}/${name}`;
|
||||||
return Request(url);
|
return Request(url);
|
||||||
};
|
}
|
||||||
|
|
||||||
export function getClaimData (host, name, claimId) {
|
export function getClaimData(host, name, claimId) {
|
||||||
const url = `${host}/api/claim/data/${name}/${claimId}`;
|
const url = `${host}/api/claim/data/${name}/${claimId}`;
|
||||||
return Request(url);
|
return Request(url);
|
||||||
};
|
}
|
||||||
|
|
||||||
export function checkClaimAvailability (claim) {
|
export function checkClaimAvailability(claim) {
|
||||||
const url = `/api/claim/availability/${claim}`;
|
const url = `/api/claim/availability/${claim}`;
|
||||||
return Request(url);
|
return Request(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getClaimViews (claimId) {
|
export function getClaimViews(claimId) {
|
||||||
const url = `/api/claim/views/${claimId}`;
|
const url = `/api/claim/views/${claimId}`;
|
||||||
return Request(url);
|
return Request(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doAbandonClaim (claimId) {
|
export function doAbandonClaim(outpoint) {
|
||||||
const params = {
|
const params = {
|
||||||
method : 'POST',
|
method: 'POST',
|
||||||
body : JSON.stringify({claimId}),
|
body: JSON.stringify({ outpoint }),
|
||||||
headers: new Headers({
|
headers: new Headers({
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -22,14 +22,29 @@ export const makePublishRequestChannel = (fd, isUpdate) => {
|
||||||
xhr.upload.addEventListener('load', onLoad);
|
xhr.upload.addEventListener('load', onLoad);
|
||||||
// set state change handler
|
// set state change handler
|
||||||
xhr.onreadystatechange = () => {
|
xhr.onreadystatechange = () => {
|
||||||
if (xhr.readyState === 4) {
|
if (xhr.readyState === XMLHttpRequest.DONE) {
|
||||||
const response = JSON.parse(xhr.response);
|
switch (xhr.status) {
|
||||||
if ((xhr.status === 200) && response.success) {
|
case 413:
|
||||||
emitter({success: response});
|
emitter({error: new Error("Unfortunately it appears this web server " +
|
||||||
emitter(END);
|
"has been misconfigured, please inform the service administrators " +
|
||||||
} else {
|
"that they must set their nginx/apache request size maximums higher " +
|
||||||
emitter({error: new Error(response.message)});
|
"than their file size limits.")});
|
||||||
emitter(END);
|
emitter(END);
|
||||||
|
break;
|
||||||
|
case 200:
|
||||||
|
var response = JSON.parse(xhr.response);
|
||||||
|
if (response.success) {
|
||||||
|
emitter({success: response});
|
||||||
|
emitter(END);
|
||||||
|
} else {
|
||||||
|
emitter({error: new Error(response.message)});
|
||||||
|
emitter(END);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
emitter({error: new Error("Received an unexpected response from " +
|
||||||
|
"server: " + xhr.status)});
|
||||||
|
emitter(END);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,17 +5,19 @@ import { updatePublishStatus, clearFile } from '../actions/publish';
|
||||||
import { removeAsset } from '../actions/show';
|
import { removeAsset } from '../actions/show';
|
||||||
import { doAbandonClaim } from '../api/assetApi';
|
import { doAbandonClaim } from '../api/assetApi';
|
||||||
|
|
||||||
function * abandonClaim (action) {
|
function* abandonClaim(action) {
|
||||||
const { claimData, history } = action.data;
|
const { claimData, history } = action.data;
|
||||||
const { claimId } = claimData;
|
const { outpoint } = claimData;
|
||||||
|
|
||||||
const confirm = window.confirm('Are you sure you want to abandon this claim? This action cannot be undone.');
|
const confirm = window.confirm(
|
||||||
|
'Are you sure you want to abandon this claim? This action cannot be undone.'
|
||||||
|
);
|
||||||
if (!confirm) return;
|
if (!confirm) return;
|
||||||
|
|
||||||
yield put(updatePublishStatus(publishStates.ABANDONING, 'Your claim is being abandoned...'));
|
yield put(updatePublishStatus(publishStates.ABANDONING, 'Your claim is being abandoned...'));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
yield call(doAbandonClaim, claimId);
|
yield call(doAbandonClaim, outpoint);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return console.log('abandon error:', error.message);
|
return console.log('abandon error:', error.message);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +27,6 @@ function * abandonClaim (action) {
|
||||||
return history.push('/');
|
return history.push('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function * watchAbandonClaim () {
|
export function* watchAbandonClaim() {
|
||||||
yield takeLatest(actions.ABANDON_CLAIM, abandonClaim);
|
yield takeLatest(actions.ABANDON_CLAIM, abandonClaim);
|
||||||
};
|
}
|
||||||
|
|
|
@ -9,28 +9,28 @@ const authenticateUser = require('../publish/authentication.js');
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const claimAbandon = async (req, res) => {
|
const claimAbandon = async (req, res) => {
|
||||||
const {claimId} = req.body;
|
const { outpoint } = req.body;
|
||||||
const {user} = req;
|
const { user } = req;
|
||||||
try {
|
try {
|
||||||
const [channel, claim] = await Promise.all([
|
const [channel, claim] = await Promise.all([
|
||||||
authenticateUser(user.channelName, null, null, user),
|
authenticateUser(user.channelName, null, null, user),
|
||||||
db.Claim.findOne({where: {claimId}}),
|
db.Claim.findOne({ where: { outpoint } }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!claim) throw new Error('That channel does not exist');
|
if (!claim) throw new Error('That channel does not exist');
|
||||||
if (!channel.channelName) throw new Error('You don\'t own this channel');
|
if (!channel.channelName) throw new Error("You don't own this channel");
|
||||||
|
|
||||||
await abandonClaim({claimId});
|
await abandonClaim({ outpoint });
|
||||||
const file = await db.File.findOne({where: {claimId}});
|
const file = await db.File.findOne({ where: { outpoint } });
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
deleteFile(file.filePath),
|
deleteFile(file.filePath),
|
||||||
db.File.destroy({where: {claimId}}),
|
db.File.destroy({ where: { outpoint } }),
|
||||||
db.Claim.destroy({where: {claimId}}),
|
db.Claim.destroy({ where: { outpoint } }),
|
||||||
]);
|
]);
|
||||||
logger.debug(`Claim abandoned: ${claimId}`);
|
logger.debug(`Claim abandoned: ${outpoint}`);
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
message: `Claim with id ${claimId} abandonded`,
|
message: `Claim with outpoint ${outpoint} abandonded`,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('abandon claim error:', error);
|
logger.error('abandon claim error:', error);
|
||||||
|
|
|
@ -20,10 +20,7 @@ const { setupBlockList } = require('./utils/blockList');
|
||||||
const speechPassport = require('./speechPassport');
|
const speechPassport = require('./speechPassport');
|
||||||
const processTrending = require('./utils/processTrending');
|
const processTrending = require('./utils/processTrending');
|
||||||
|
|
||||||
const {
|
const { setRouteDataInContextMiddleware } = require('./middleware/httpContextMiddleware');
|
||||||
logMetricsMiddleware,
|
|
||||||
setRouteDataInContextMiddleware,
|
|
||||||
} = require('./middleware/logMetricsMiddleware');
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
details: { port: PORT, blockListEndpoint },
|
details: { port: PORT, blockListEndpoint },
|
||||||
|
@ -145,7 +142,7 @@ function Server() {
|
||||||
|
|
||||||
app[routeMethod](
|
app[routeMethod](
|
||||||
routePath,
|
routePath,
|
||||||
logMetricsMiddleware,
|
// logMetricsMiddleware,
|
||||||
setRouteDataInContextMiddleware(routePath, routeData),
|
setRouteDataInContextMiddleware(routePath, routeData),
|
||||||
...controllers
|
...controllers
|
||||||
);
|
);
|
||||||
|
|
|
@ -73,13 +73,14 @@ module.exports = {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async abandonClaim({ claimId }) {
|
async abandonClaim({ outpoint }) {
|
||||||
logger.debug(`lbryApi >> Abandon claim "${claimId}"`);
|
logger.debug(`lbryApi >> Abandon claim "${outpoint}"`);
|
||||||
const gaStartTime = Date.now();
|
const gaStartTime = Date.now();
|
||||||
|
const [txid, nout] = outpoint.split(':');
|
||||||
try {
|
try {
|
||||||
const abandon = await axios.post(lbrynetUri, {
|
const abandon = await axios.post(lbrynetUri, {
|
||||||
method: 'claim_abandon',
|
method: 'stream_abandon',
|
||||||
params: { claim_id: claimId },
|
params: { txid: txid, nout: Number(nout) },
|
||||||
});
|
});
|
||||||
sendGATimingEvent('lbrynet', 'abandonClaim', 'ABANDON_CLAIM', gaStartTime, Date.now());
|
sendGATimingEvent('lbrynet', 'abandonClaim', 'ABANDON_CLAIM', gaStartTime, Date.now());
|
||||||
return abandon.data;
|
return abandon.data;
|
||||||
|
|
|
@ -7,7 +7,7 @@ const {
|
||||||
const ipBanFile = './site/config/ipBan.txt';
|
const ipBanFile = './site/config/ipBan.txt';
|
||||||
const forbiddenMessage =
|
const forbiddenMessage =
|
||||||
'<h1>Forbidden</h1>If you are seeing this by mistake, please contact us using <a href="https://chat.lbry.com/">https://chat.lbry.com/</a>';
|
'<h1>Forbidden</h1>If you are seeing this by mistake, please contact us using <a href="https://chat.lbry.com/">https://chat.lbry.com/</a>';
|
||||||
|
const maxPublishesInTenMinutes = 20;
|
||||||
let ipCounts = {};
|
let ipCounts = {};
|
||||||
let blockedAddresses = [];
|
let blockedAddresses = [];
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ const autoblockPublishMiddleware = (req, res, next) => {
|
||||||
}
|
}
|
||||||
}, 600000 /* 10 minute retainer */);
|
}, 600000 /* 10 minute retainer */);
|
||||||
|
|
||||||
if (count === 10) {
|
if (count === maxPublishesInTenMinutes) {
|
||||||
logger.error(`Banning IP: ${ip}`);
|
logger.error(`Banning IP: ${ip}`);
|
||||||
blockedAddresses.push(ip);
|
blockedAddresses.push(ip);
|
||||||
res.status(403).send(forbiddenMessage);
|
res.status(403).send(forbiddenMessage);
|
||||||
|
|
13
server/middleware/httpContextMiddleware.js
Normal file
13
server/middleware/httpContextMiddleware.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
const httpContext = require('express-http-context');
|
||||||
|
|
||||||
|
function setRouteDataInContextMiddleware(routePath, routeData) {
|
||||||
|
return function(req, res, next) {
|
||||||
|
httpContext.set('routePath', routePath);
|
||||||
|
httpContext.set('routeData', routeData);
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
setRouteDataInContextMiddleware,
|
||||||
|
};
|
Loading…
Add table
Reference in a new issue