package ink.wgink.module.form.controller.staticfile;

import ink.wgink.util.ResourceUtil;
import ink.wgink.util.request.StaticResourceRequestUtil;
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 javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;

/**
 * @ClassName: FormStaticController
 * @Description: 表单静态资源
 * @Author: wanggeng
 * @Date: 2022/4/13 14:27
 * @Version: 1.0
 */

@Controller
@RequestMapping("static/form")
public class FormStaticController {

    @GetMapping("css/{fileName}")
    public void css(HttpServletResponse httpServletResponse, @PathVariable("fileName") String fileName) throws IOException {
        InputStream inputStream = ResourceUtil.getJarResourceInputStream("static/form/css/" + fileName);
        StaticResourceRequestUtil.download(httpServletResponse, inputStream, fileName);
    }

    @GetMapping("js/{fileName}")
    public void js(HttpServletResponse httpServletResponse, @PathVariable("fileName") String fileName) throws IOException {
        InputStream inputStream = ResourceUtil.getJarResourceInputStream("static/form/js/" + fileName);
        StaticResourceRequestUtil.download(httpServletResponse, inputStream, fileName);
    }

}
