Commit 9cb4cad5 authored by nanahira's avatar nanahira

finish

parent d6ceb709
Pipeline #14534 passed with stages
in 1 minute and 6 seconds
......@@ -4,3 +4,4 @@ hamiUsername: 'Hamimelon7'
hamiBlacklistSearch: '#蔷蔷挂人板'
twintUrl: 'http://twint'
twintToken: 'twintToken'
cocurrency: 4
......@@ -11,6 +11,8 @@ import { BlacklistController } from './blacklist/blacklist.controller';
imports: [
ConfigModule.forRoot({
load: [loadConfig],
ignoreEnvVars: true,
ignoreEnvFile: true,
isGlobal: true,
}),
HttpModule.registerAsync({
......
......@@ -3,15 +3,17 @@ import { HttpService } from '@nestjs/axios';
import { lastValueFrom } from 'rxjs';
import { recognize } from 'node-tesseract-ocr';
import PQueue from 'p-queue';
import * as os from 'os';
import { ConfigService } from '@nestjs/config';
@Injectable()
export class OcrService extends ConsoleLogger {
constructor(private http: HttpService) {
constructor(private http: HttpService, private config: ConfigService) {
super('OcrService');
}
private queue = new PQueue({ concurrency: os.cpus().length });
private queue = new PQueue({
concurrency: parseInt(this.config.get('cocurrency')),
});
private async checkImageProcess(url: string): Promise<string[]> {
try {
......@@ -27,7 +29,7 @@ export class OcrService extends ConsoleLogger {
}
const exactMatches = text.match(/QQ: \d{5,10}/g);
if (exactMatches) {
return exactMatches.map((info) => info.slice(3));
return exactMatches.map((info) => info.slice(4));
}
return text.match(/\d{8,10}/g) || [];
} catch (e) {
......
import yaml from 'yaml';
import * as fs from 'fs';
import { HttpModuleOptions } from '@nestjs/axios';
import * as os from 'os';
export interface Config {
host: string;
......@@ -10,6 +11,7 @@ export interface Config {
hamiBlacklistSearch: string;
twintUrl: string;
twintToken: string;
cocurrency: number;
}
const defaultConfig: Config = {
......@@ -20,6 +22,7 @@ const defaultConfig: Config = {
hamiBlacklistSearch: '#蔷蔷挂人板',
twintUrl: 'http://twint',
twintToken: 'twintToken',
cocurrency: os.cpus().length,
};
export async function loadConfig(): Promise<Config> {
......@@ -33,5 +36,6 @@ export async function loadConfig(): Promise<Config> {
return {
...defaultConfig,
...readConfig,
...process.env,
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment