小编Mik*_*lis的帖子

如何覆盖控制器中的全局 ValidationPipe?

ValidationPipe我使用带有选项的全局{ transform: true, whitelist: true }。但是,在特定的控制器请求中,我想重用相同的类但具有不同的验证,应用类验证器的验证组技术。因此,我有必要覆盖管道的选项以应用新选项。

这是在 NestJS 6.2.4 上。我尝试在 处应用新管道@Query(new ValidationPipe({groups: ['res']})),但全局管道仍然应用。我应用了相同的逻辑,@UsePipes()但再次应用了全局管道。

另外,我尝试将always: false属性与组一起应用,以避免始终验证属性,但由于这是默认行为,因此没有太大帮助。

@IsNumberString({ groups: ['res'] })
resId: number;
Run Code Online (Sandbox Code Playgroud)

typescript class-validator nestjs

8
推荐指数
1
解决办法
4362
查看次数

Emit websocket event from a NestJS controller or service

I am trying to listen to model change events in TypeORM through a subscriber, and broadcast an event each time a new one is inserted. While external clients receive the event, the gateway's @SubscribeMessage() method is not receiving it, which suggests that the sender is not getting the event. However, according to socket.io, the of('namespace').emit('event') should be received to any client, including the sender.

网关被注入订阅者服务,没有任何问题,并且当我尝试使用它时,网关的服务器似乎已准备好,但没有发出任何事件。

在 NestJS 6.3.1 上运行,我也尝试从控制器发出事件,但没有结果。

@WebSocketGateway({ namespace: '/posts' })
export class PostGateway {

  @WebSocketServer()
  server: …
Run Code Online (Sandbox Code Playgroud)

websocket socket.io nestjs

8
推荐指数
1
解决办法
6076
查看次数

正则表达式适用于正则表达式测试器,但不适用于 C++

我正在尝试获取文件中引号之间的内容,并且我正在使用正则表达式。这是我正在使用的正则表达式:

id=\"([^\"]+)\"|title=\"([^\"]+)\"
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,每个特殊字符都被转义了。它在正则表达式测试器中完美运行,但在 C++ 代码中使用时找不到标题。ID总能找到就好。我尝试了几种变体,甚至删除了一半(之前|)

id="60973129" title="EPA"
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的 C++ 代码:

std::regex rgx("id=\"([^\"]+)\"|title=\"([^\"]+)\"");
std::smatch match;

if (std::regex_search(line, match, rgx)) {
    for (int i=0; i < match.size(); ++i) {
            std::cout << match[i];
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:我发现如果分开放置,title=\"(.+?)\"确实可以工作,但是我必须使用多个正则表达式,这违背了我的目的,因为稍后我需要扫描更长的行。

c++ regex quotes

5
推荐指数
1
解决办法
1万
查看次数

C++ getline()比Java的readLine()慢

我正在尝试读取250K行文件,并将regex应用于这些行中的每一行.但是代码比Java的readline函数慢得多.在Java中,所有解析都在大约10秒内完成,而在C++中则需要超过2分钟.我见过相对的C++ ifstream.getline()明显慢于Java的BufferedReader.readLine()?并在main上添加了这两行:

std::ifstream::sync_with_stdio(false);
std::ios::sync_with_stdio(false);
Run Code Online (Sandbox Code Playgroud)

其余的代码(我简化它以删除正则表达式可能导致的任何延迟):

#include "stdafx.h"
#include <ios>
#include <string>
#include <fstream>
#include <iostream>


int _tmain(int argc, _TCHAR* argv[])
{

    std::string libraryFile = "H:\\library.txt";
    std::ios::sync_with_stdio(false);
    std::string line;

    int i = 1;

    std::ifstream file(libraryFile);
    while (std::getline (file, line)) {
        std::cout << "\rStored " << i++ << " lines.";
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这个例子看起来很简单,但即使是大多数帖子中提出的修复似乎都不起作用.我使用VS2012中的发布设置多次运行.exe,但我无法达到Java的时间.

c++ java fstream

1
推荐指数
1
解决办法
1404
查看次数

Fire上的Firebase数据库获取id

我试图使用onWrite方法模仿Firebase上的插入触发器.插入是通过POST请求完成的,因为我正在测试它(我发现检查数据库触发器的最简单方法).触发器包括将Firebase生成的ID作为新属性写入插入的数据中.

我的云功能是这样的:

exports.onNewSeries = functions.database.ref('/series').onWrite(event => {
    "use strict";
    console.log(event.data.key);
    console.log(event.data.current.key);
    console.log(event.data.current);
});
Run Code Online (Sandbox Code Playgroud)

两个第一个日志都包含相同的key(series),它实际上是附加新数据的父节点的键,而不是新数据键(以古怪的形式-adfaa123sdfasdf).最后一个日志打印一个Firebase结构,其中包含新数据以及_data属性中生成的密钥,但是无法访问它.

虽然这可以在请求后手动完成,但我没有看到它以数据库触发方式自动完成.

javascript firebase firebase-realtime-database google-cloud-functions

0
推荐指数
1
解决办法
1654
查看次数