@
PostMapping(value = "/generate2",
consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Mono<GenerateResp> generate2(@RequestBody @
Valid GenerateReq generateReq) {
return Mono.just(generateReq)
.filter(_generateReq -> "dsadsadsasdadsadsa".equals(_generateReq.getToken()))
.switchIfEmpty(Mono.error(() -> new ResponseStatusException(UNAUTHORIZED, "token is invalid")))
.map(_generateReq -> Tuples.of(_generateReq.getUrl(), DigestUtils.sha256(_generateReq.getUrl())))
.flatMap(tuple -> redisTemplate.opsForValue().get(tuple.getT2())
.switchIfEmpty(Mono.defer(() -> Mono.just(RandomStringUtils.randomAlphanumeric(6))
.filterWhen(newPath -> redisTemplate.opsForValue()
.multiSet(ImmutableMap.of(newPath.getBytes(), tuple.getT1(), tuple.getT2(), newPath)))
.switchIfEmpty(Mono.error(() -> new ResponseStatusException(INTERNAL_SERVER_ERROR, "server error")))
)))
.map(path -> new GenerateResp(urlPrefix + path));
}