mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2025-03-27 02:02:10 +01:00
user agents
This commit is contained in:
parent
e08de753b6
commit
3b583b3d67
@ -14,9 +14,12 @@ export class ClientEntity extends TrackedEntity {
|
||||
@Column({ length: 62, type: 'varchar' })
|
||||
address: string;
|
||||
|
||||
@Column()
|
||||
@Column({ length: 64, type: 'varchar' })
|
||||
clientName: string;
|
||||
|
||||
@Column({ length: 128, type: 'varchar', nullable: true })
|
||||
userAgent: string;
|
||||
|
||||
@Column({ length: 8, type: 'varchar' })
|
||||
sessionId: string;
|
||||
|
||||
@ -24,7 +27,6 @@ export class ClientEntity extends TrackedEntity {
|
||||
startTime: Date;
|
||||
|
||||
|
||||
|
||||
@Column({ type: 'real', default: 0 })
|
||||
bestDifficulty: number
|
||||
|
||||
|
@ -76,4 +76,14 @@ export class ClientService {
|
||||
public async deleteAll() {
|
||||
return await this.clientRepository.softDelete({})
|
||||
}
|
||||
|
||||
public async getUserAgents() {
|
||||
const result = await this.clientRepository.createQueryBuilder('client')
|
||||
.select('client.userAgent as userAgent')
|
||||
.addSelect('COUNT(client.userAgent)', 'count')
|
||||
.groupBy('client.userAgent')
|
||||
.orderBy('count', 'DESC')
|
||||
.getRawMany();
|
||||
return result;
|
||||
}
|
||||
}
|
@ -18,11 +18,16 @@ export class AppController {
|
||||
@Get('info')
|
||||
public async info() {
|
||||
|
||||
const blockData = await this.blocksService.getFoundBlocks();
|
||||
const userAgents = await this.clientService.getUserAgents();
|
||||
|
||||
const CACHE_KEY = 'SITE_HASHRATE_GRAPH';
|
||||
const cachedResult = await this.cacheManager.get(CACHE_KEY);
|
||||
if (cachedResult != null) {
|
||||
return {
|
||||
chartData: cachedResult
|
||||
chartData: cachedResult,
|
||||
blockData,
|
||||
userAgents
|
||||
};
|
||||
}
|
||||
|
||||
@ -30,11 +35,11 @@ export class AppController {
|
||||
|
||||
await this.cacheManager.set(CACHE_KEY, chartData, 600);
|
||||
|
||||
const blockData = await this.blocksService.getFoundBlocks();
|
||||
|
||||
return {
|
||||
chartData,
|
||||
blockData
|
||||
blockData,
|
||||
userAgents
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -274,6 +274,7 @@ export class StratumV1Client extends EasyUnsubscribe {
|
||||
sessionId: this.extraNonceAndSessionId,
|
||||
address: this.clientAuthorization.address,
|
||||
clientName: this.clientAuthorization.worker,
|
||||
userAgent: this.clientSubscription.userAgent,
|
||||
startTime: new Date(),
|
||||
});
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { IsArray } from 'class-validator';
|
||||
import { Expose, Transform } from 'class-transformer';
|
||||
import { IsArray, IsString, MaxLength } from 'class-validator';
|
||||
|
||||
import { eRequestMethod } from '../enums/eRequestMethod';
|
||||
import { StratumBaseMessage } from './StratumBaseMessage';
|
||||
@ -9,6 +10,14 @@ export class SubscriptionMessage extends StratumBaseMessage {
|
||||
@IsArray()
|
||||
params: string[];
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@MaxLength(128)
|
||||
@Transform(({ value, key, obj, type }) => {
|
||||
return obj.params[0] == null ? 'default' : obj.params[0]
|
||||
})
|
||||
public userAgent: string;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.method = eRequestMethod.SUBSCRIBE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user