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' ...@@ -4,3 +4,4 @@ hamiUsername: 'Hamimelon7'
hamiBlacklistSearch: '#蔷蔷挂人板' hamiBlacklistSearch: '#蔷蔷挂人板'
twintUrl: 'http://twint' twintUrl: 'http://twint'
twintToken: 'twintToken' twintToken: 'twintToken'
cocurrency: 4
...@@ -11,6 +11,8 @@ import { BlacklistController } from './blacklist/blacklist.controller'; ...@@ -11,6 +11,8 @@ import { BlacklistController } from './blacklist/blacklist.controller';
imports: [ imports: [
ConfigModule.forRoot({ ConfigModule.forRoot({
load: [loadConfig], load: [loadConfig],
ignoreEnvVars: true,
ignoreEnvFile: true,
isGlobal: true, isGlobal: true,
}), }),
HttpModule.registerAsync({ HttpModule.registerAsync({
......
...@@ -3,15 +3,17 @@ import { HttpService } from '@nestjs/axios'; ...@@ -3,15 +3,17 @@ import { HttpService } from '@nestjs/axios';
import { lastValueFrom } from 'rxjs'; import { lastValueFrom } from 'rxjs';
import { recognize } from 'node-tesseract-ocr'; import { recognize } from 'node-tesseract-ocr';
import PQueue from 'p-queue'; import PQueue from 'p-queue';
import * as os from 'os'; import { ConfigService } from '@nestjs/config';
@Injectable() @Injectable()
export class OcrService extends ConsoleLogger { export class OcrService extends ConsoleLogger {
constructor(private http: HttpService) { constructor(private http: HttpService, private config: ConfigService) {
super('OcrService'); 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[]> { private async checkImageProcess(url: string): Promise<string[]> {
try { try {
...@@ -27,7 +29,7 @@ export class OcrService extends ConsoleLogger { ...@@ -27,7 +29,7 @@ export class OcrService extends ConsoleLogger {
} }
const exactMatches = text.match(/QQ: \d{5,10}/g); const exactMatches = text.match(/QQ: \d{5,10}/g);
if (exactMatches) { if (exactMatches) {
return exactMatches.map((info) => info.slice(3)); return exactMatches.map((info) => info.slice(4));
} }
return text.match(/\d{8,10}/g) || []; return text.match(/\d{8,10}/g) || [];
} catch (e) { } catch (e) {
......
import yaml from 'yaml'; import yaml from 'yaml';
import * as fs from 'fs'; import * as fs from 'fs';
import { HttpModuleOptions } from '@nestjs/axios'; import { HttpModuleOptions } from '@nestjs/axios';
import * as os from 'os';
export interface Config { export interface Config {
host: string; host: string;
...@@ -10,6 +11,7 @@ export interface Config { ...@@ -10,6 +11,7 @@ export interface Config {
hamiBlacklistSearch: string; hamiBlacklistSearch: string;
twintUrl: string; twintUrl: string;
twintToken: string; twintToken: string;
cocurrency: number;
} }
const defaultConfig: Config = { const defaultConfig: Config = {
...@@ -20,6 +22,7 @@ const defaultConfig: Config = { ...@@ -20,6 +22,7 @@ const defaultConfig: Config = {
hamiBlacklistSearch: '#蔷蔷挂人板', hamiBlacklistSearch: '#蔷蔷挂人板',
twintUrl: 'http://twint', twintUrl: 'http://twint',
twintToken: 'twintToken', twintToken: 'twintToken',
cocurrency: os.cpus().length,
}; };
export async function loadConfig(): Promise<Config> { export async function loadConfig(): Promise<Config> {
...@@ -33,5 +36,6 @@ export async function loadConfig(): Promise<Config> { ...@@ -33,5 +36,6 @@ export async function loadConfig(): Promise<Config> {
return { return {
...defaultConfig, ...defaultConfig,
...readConfig, ...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