package com.ruoyi.file.request;

import com.ruoyi.common.utils.StringUtils;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotBlank;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

@Data
public final class UploadRedirectReq
{
    @NotBlank(message = "重定向地址不能为空")
    private String              redirectUri;

    private String token;
    private Map<String, Object> formData;

    public void ParseToken(HttpServletRequest request)
    {
        token = request.getHeader("Authorization");
    }

    public void ParseFormData(HttpServletRequest request)
    {
        if(null == formData)
            formData = new LinkedHashMap<>();

        Enumeration<String> parameterNames = request.getParameterNames();
        while(parameterNames.hasMoreElements())
        {
            String s = parameterNames.nextElement();
            if("redirectUri".equals(s))
                continue;
            formData.put(s, request.getParameter(s));
        }
    }
}
