1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00

Compare commits

...

2 commits

Author SHA1 Message Date
Nick Schonning
89bdffc616
Merge c8bc986323 into 549ab089ee 2024-07-31 11:04:45 +00:00
Nick Schonning
c8bc986323
Opt-in streaming to Prettier 2024-07-12 11:27:36 -04:00
6 changed files with 684 additions and 465 deletions

View file

@ -83,3 +83,4 @@ AUTHORS.md
# Process a few selected JS files
!lint-staged.config.js
!/streaming/*.js

View file

@ -29,7 +29,7 @@ export class RequestError extends Error {
*/
constructor(message) {
super(message);
this.name = "RequestError";
this.name = 'RequestError';
this.status = 400;
}
}
@ -40,7 +40,7 @@ export class AuthenticationError extends Error {
*/
constructor(message) {
super(message);
this.name = "AuthenticationError";
this.name = 'AuthenticationError';
this.status = 401;
}
}

File diff suppressed because it is too large Load diff

View file

@ -31,18 +31,21 @@ function sanitizeRequestLog(req) {
const log = pinoHttpSerializers.req(req);
if (typeof log.url === 'string' && log.url.includes('access_token')) {
// Doorkeeper uses SecureRandom.urlsafe_base64 per RFC 6749 / RFC 6750
log.url = log.url.replace(/(access_token)=([a-zA-Z0-9\-_]+)/gi, '$1=[Redacted]');
log.url = log.url.replace(
/(access_token)=([a-zA-Z0-9\-_]+)/gi,
'$1=[Redacted]',
);
}
return log;
}
export const logger = pino({
name: "streaming",
name: 'streaming',
// Reformat the log level to a string:
formatters: {
level: (label) => {
return {
level: label
level: label,
};
},
},
@ -54,17 +57,17 @@ export const logger = pino({
'req.headers["sec-websocket-protocol"]',
'req.headers.authorization',
'req.headers.cookie',
'req.query.access_token'
]
}
'req.query.access_token',
],
},
});
export const httpLogger = pinoHttp({
logger,
genReqId: generateRequestId,
serializers: {
req: sanitizeRequestLog
}
req: sanitizeRequestLog,
},
});
/**
@ -90,11 +93,11 @@ export function createWebsocketLogger(request, resolvedAccount) {
return logger.child({
req: {
id: request.id
id: request.id,
},
account: {
id: resolvedAccount.accountId ?? null
}
id: resolvedAccount.accountId ?? null,
},
});
}
@ -104,7 +107,10 @@ export function createWebsocketLogger(request, resolvedAccount) {
* @param {string} environment
*/
export function initializeLogLevel(env, environment) {
if (env.LOG_LEVEL && Object.keys(logger.levels.values).includes(env.LOG_LEVEL)) {
if (
env.LOG_LEVEL &&
Object.keys(logger.levels.values).includes(env.LOG_LEVEL)
) {
logger.level = env.LOG_LEVEL;
} else if (environment === 'development') {
logger.level = 'debug';

View file

@ -55,7 +55,7 @@ export function setupMetrics(channels, pgPool) {
const connectedChannels = new metrics.Gauge({
name: 'connected_channels',
help: 'The number of channels the streaming server is streaming to',
labelNames: [ 'type', 'channel' ]
labelNames: ['type', 'channel'],
});
const redisSubscriptions = new metrics.Gauge({
@ -65,13 +65,13 @@ export function setupMetrics(channels, pgPool) {
const redisMessagesReceived = new metrics.Counter({
name: 'redis_messages_received_total',
help: 'The total number of messages the streaming server has received from redis subscriptions'
help: 'The total number of messages the streaming server has received from redis subscriptions',
});
const messagesSent = new metrics.Counter({
name: 'messages_sent_total',
help: 'The total number of messages the streaming server sent to clients per connection type',
labelNames: [ 'type' ]
labelNames: ['type'],
});
// Prime the gauges so we don't loose metrics between restarts:

View file

@ -1,16 +1,6 @@
// @ts-check
const FALSE_VALUES = [
false,
0,
'0',
'f',
'F',
'false',
'FALSE',
'off',
'OFF',
];
const FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF'];
/**
* @param {any} value
@ -24,8 +14,10 @@ export function isTruthy(value) {
* See app/lib/ascii_folder.rb for the canon definitions
* of these constants
*/
const NON_ASCII_CHARS = 'ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž';
const EQUIVALENT_ASCII_CHARS = 'AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz';
const NON_ASCII_CHARS =
'ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž';
const EQUIVALENT_ASCII_CHARS =
'AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz';
/**
* @param {string} str
@ -45,7 +37,10 @@ export function foldToASCII(str) {
* @returns {string}
*/
export function normalizeHashtag(str) {
return foldToASCII(str.normalize('NFKC').toLowerCase()).replace(/[^\p{L}\p{N}_\u00b7\u200c]/gu, '');
return foldToASCII(str.normalize('NFKC').toLowerCase()).replace(
/[^\p{L}\p{N}_\u00b7\u200c]/gu,
'',
);
}
/**