package com.ruoyi.web.controller.webOffice;


import cn.ljserver.tool.weboffice.v3.exception.FileNotExist;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.framework.web.domain.server.Sys;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.webService.IWebofficeFjService;
import com.ruoyi.system.service.webService.QnFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/console")
public class ConsoleController {

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private IWebofficeFjService webofficeFjService;

    @PutMapping("/upload")
    public String upload(MultipartFile file) {
        return webofficeFjService.upload(file);
    }

    @PutMapping(value = "/upload/{file_id}")
    public String upload(@PathVariable("file_id") String fileId, @RequestBody byte[] content, HttpServletRequest request) {
        // ATTENTION a dirty version is written into storage
        System.out.println(fileId+"ooooooooooooooooooooooooooo");
        if (redisCache.getCacheObject(fileId)==null) throw new FileNotExist();
        // 从缓存中获取当前需要上传文件的文件类型
        String suffix = redisCache.getCacheObject(fileId);
        return webofficeFjService.upload(fileId,content, suffix,request);
    }

}
