package com.ruoyi.file;

import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.annotation.Dev;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.Duration;

@Controller
@RequiredArgsConstructor
@RequestMapping("/file/test/")
public class FileDownloadTestController {

  private final FileService fileService;

  @GetMapping("/download")
  @SaIgnore
  @Dev
  public ModelAndView downloadFile(String url,String p, HttpServletRequest request, HttpServletResponse response) {
    fileService.setPlatform(p).download(url, Duration.ofHours(1), request, response);
    return null;
  }
}
