Merge branch 'edge' into logRefactor

# Conflicts:
#	src/Web/Client/index.ts
This commit is contained in:
FoxxMD
2022-02-18 15:45:28 -05:00
8 changed files with 48 additions and 7 deletions

View File

@@ -16,7 +16,7 @@ import {
} from "../Common/interfaces";
import {
createRetryHandler,
formatNumber, getExceptionMessage,
formatNumber, getExceptionMessage, getUserAgent,
mergeArr,
parseBool,
parseDuration, parseMatchMessage,
@@ -99,6 +99,7 @@ class Bot {
dryRun,
heartbeatInterval,
},
userAgent,
credentials: {
reddit: {
clientId,
@@ -173,7 +174,9 @@ class Bot {
this.excludeSubreddits = exclude.map(parseSubredditName);
let creds: any = {
get userAgent() { return getUserName() },
get userAgent() {
return getUserAgent(`web:contextBot:{VERSION}{FRAG}:BOT-${getBotName()}`, userAgent)
},
clientId,
clientSecret,
refreshToken,

View File

@@ -39,3 +39,5 @@ export const filterCriteriaDefault: FilterCriteriaDefaults = {
]
}
}
export const VERSION = '0.10.11';

View File

@@ -1690,6 +1690,17 @@ export interface OperatorJsonConfig {
bots?: BotInstanceJsonConfig[]
/**
* Added to the User-Agent information sent to reddit
*
* This string will be added BETWEEN version and your bot name.
*
* EX: `myBranch` => `web:contextMod:v1.0.0-myBranch:BOT-/u/MyBotUser`
*
* * ENV => `USER_AGENT`
* */
userAgent?: string
/**
* Settings for the web interface
* */
@@ -1865,6 +1876,7 @@ export interface BotInstanceConfig extends BotInstanceJsonConfig {
softLimit: number,
hardLimit: number,
}
userAgent?: string
}
export interface OperatorConfig extends OperatorJsonConfig {

View File

@@ -698,6 +698,7 @@ export const buildOperatorConfigWithDefaults = (data: OperatorJsonConfig): Opera
stream = {},
} = {},
caching: opCache,
userAgent,
web: {
port = 8085,
maxLogs = 200,
@@ -804,6 +805,7 @@ export const buildOperatorConfigWithDefaults = (data: OperatorJsonConfig): Opera
}
},
caching: cache,
userAgent,
web: {
port,
caching: {
@@ -843,7 +845,8 @@ export const buildBotConfig = (data: BotInstanceJsonConfig, opConfig: OperatorCo
actionedEventsMax: opActionedEventsMax,
actionedEventsDefault: opActionedEventsDefault = 25,
provider: defaultProvider,
} = {}
} = {},
userAgent,
} = opConfig;
const {
name: botName,
@@ -984,6 +987,7 @@ export const buildBotConfig = (data: BotInstanceJsonConfig, opConfig: OperatorCo
},
credentials: botCreds,
caching: botCache,
userAgent,
polling: {
shared: [...new Set(realShared)] as PollOn[],
stagger,

View File

@@ -1384,6 +1384,10 @@
"$ref": "#/definitions/SnoowrapOptions",
"description": "Set global snoowrap options as well as default snoowrap config for all bots that don't specify their own"
},
"userAgent": {
"description": "Added to the User-Agent information sent to reddit\n\nThis string will be added BETWEEN version and your bot name.\n\nEX: `myBranch` => `web:contextMod:v1.0.0-myBranch:BOT-/u/MyBotUser`\n\n* ENV => `USER_AGENT`",
"type": "string"
},
"web": {
"description": "Settings for the web interface",
"properties": {

View File

@@ -10,11 +10,11 @@ import {OperatorConfig, BotConnection, LogInfo} from "../../Common/interfaces";
import {
buildCachePrefix,
createCacheManager, defaultFormat, filterLogBySubreddit, filterLogs,
formatLogLineToHtml,
formatLogLineToHtml, getUserAgent,
intersect, isLogLineMinLevel,
LogEntry, parseInstanceLogInfoName, parseInstanceLogName, parseRedditEntity,
parseSubredditLogName, permissions,
randomId, sleep, triggeredIndicator
randomId, replaceApplicationIdentifier, sleep, triggeredIndicator
} from "../../util";
import {Cache} from "cache-manager";
import session, {Session, SessionData} from "express-session";
@@ -124,6 +124,7 @@ const webClient = async (options: OperatorConfig) => {
name,
display,
},
userAgent: uaFragment,
web: {
port,
caching,
@@ -148,6 +149,13 @@ const webClient = async (options: OperatorConfig) => {
},
} = options;
const userAgent = getUserAgent(`web:contextBot:{VERSION}{FRAG}:dashboard`, uaFragment);
app.use((req, res, next) => {
res.locals.applicationIdentifier = replaceApplicationIdentifier('{VERSION}{FRAG}', uaFragment);
next();
});
const webOps = operators.map(x => x.toLowerCase());
const logger = getLogger({defaultLabel: 'Web', ...options.logging}, 'Web');

View File

@@ -1,6 +1,6 @@
<div class="py-3 flex items-center justify-around font-semibold">
<div>
<a href="https://github.com/FoxxMD/context-mod">ContextMod Web</a> created by /u/FoxxMD
<a href="https://github.com/FoxxMD/context-mod">ContextMod <%= locals.applicationIdentifier%></a> created by /u/FoxxMD
</div>
</div>
<script type="text/javascript" src="https://cdn.statuspage.io/se-v2.js"></script>

View File

@@ -35,7 +35,7 @@ import {
import { Document as YamlDocument } from 'yaml'
import InvalidRegexError from "./Utils/InvalidRegexError";
import {constants, promises} from "fs";
import {cacheOptDefaults} from "./Common/defaults";
import {cacheOptDefaults, VERSION} from "./Common/defaults";
import cacheManager, {Cache} from "cache-manager";
import redisStore from "cache-manager-redis-store";
import crypto from "crypto";
@@ -2108,3 +2108,11 @@ export async function* redisScanIterator(client: any, options: any = {}): AsyncI
}
} while (cursor !== '0');
}
export const getUserAgent = (val: string, fragment?: string) => {
return `${replaceApplicationIdentifier(val, fragment)} (developed by /u/FoxxMD)`;
}
export const replaceApplicationIdentifier = (val: string, fragment?: string) => {
return val.replace('{VERSION}', `v${VERSION}`).replace('{FRAG}', (fragment !== undefined ? `-${fragment}` : ''));
}