刘光辉
4 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package jnpf.bizcommon.onlyoffice.controller;
 
import jnpf.base.ActionResult;
import jnpf.bizcommon.onlyoffice.entity.OnlyOfficeCallbackParam;
import jnpf.bizcommon.onlyoffice.service.impl.OnlyOfficeCompareService;
import jnpf.bizcommon.onlyoffice.service.impl.OnlyOfficeComparisonRenderer;
import org.springframework.http.ResponseEntity;
import jnpf.util.UserProvider;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.Collections;
import java.util.Map;
 
@RestController
@RequestMapping("/onlyoffice/compare")
@RequiredArgsConstructor
public class OnlyOfficeCompareController {
    private final OnlyOfficeCompareService service;
 
    @PostMapping("/config")
    public ActionResult<Map<String, Object>> config(@RequestBody Map<String, String> request) {
        return ActionResult.success(service.createConfig(request.get("ticket"), UserProvider.getUser()));
    }
 
    @GetMapping(value = "/script.js", produces = "application/javascript")
    public String script() {
        return OnlyOfficeComparisonRenderer.SCRIPT;
    }
 
    @GetMapping("/result")
    public ResponseEntity<byte[]> result(@RequestParam String ticket) {
        return ResponseEntity.ok()
                .header("Content-Type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
                .header("Cache-Control", "no-store")
                .body(service.readResult(ticket));
    }
 
    @PostMapping("/callback")
    public Map<String, Object> callback(@RequestBody OnlyOfficeCallbackParam body,
            @RequestHeader(value = "Authorization", required = false) String authorization) {
        service.acknowledgeCallback(body, authorization);
        return Collections.singletonMap("error", 0);
    }
}