<commit_before>package com.ukefu.webim.web.handler.resouce;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.ukefu.util.Menu;
import com.ukefu.util.UKTools;
import com.ukefu.webim.web.handler.Handler;
import com.ukefu.webim.web.model.UploadStatus;

@Controller
@RequestMapping("/res")
public class MediaController extends Handler{
	
	@Value("${web.upload-path}")
    private String path;
	
    @RequestMapping("/image")
    @Menu(type = "resouce" , subtype = "image" , access = true)
    public void index(HttpServletResponse response, @Valid String id) throws IOException {
    	File file = new File(path ,id) ;
    	if(id.endsWith("_original") && !file.exists()){
    		File orgFile = new File(path , id.substring(0 , id.indexOf("_original"))) ;
    		if(orgFile.exists()){
    			orgFile.renameTo(file) ;
    		}
    		UKTools.processImage(id, orgFile, path) ;
    	}else if(!StringUtils.isBlank(id) && file.exists() && !id.endsWith("_original")){
    		File destFile = new File(path , id+"_original") ;
    		file.renameTo(destFile) ;
    		UKTools.processImage(id, destFile, path) ;
    	}
    	if(file.exists() && file.isFile()){
    		response.getOutputStream().write(FileUtils.readFileToByteArray(new File(path ,id)));
    	}
    }
    
    @RequestMapping("/voice")
    @Menu(type = "resouce" , subtype = "voice" , access = true)
    public void voice(HttpServletResponse response, @Valid String id) throws IOException {
    	File file = new File(path ,id) ;
    	if(file.exists() && file.isFile()){
    		response.getOutputStream().write(FileUtils.readFileToByteArray(new File(path ,id)));
    	}
    }
    
    @RequestMapping("/url")
    @Menu(type = "resouce" , subtype = "image" , access = true)
    public void url(HttpServletResponse response, @Valid String url) throws IOException {
    	byte[] data = new byte[1024] ;
    	int length = 0 ;
    	OutputStream out = response.getOutputStream();
    	if(!StringUtils.isBlank(url)){
    		InputStream input = new URL(url).openStream() ;
    		while((length = input.read(data) )> 0){<commit_msg>no commit message<commit_after>package com.ukefu.webim.web.handler.resouce;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.ukefu.util.Menu;
import com.ukefu.util.UKTools;
import com.ukefu.webim.web.handler.Handler;
import com.ukefu.webim.web.model.UploadStatus;

@Controller
@RequestMapping("/res")
public class MediaController extends Handler{
	
	@Value("${web.upload-path}")
    private String path;
	
    @RequestMapping("/image")
    @Menu(type = "resouce" , subtype = "image" , access = true)
    public void index(HttpServletResponse response, @Valid String id) throws IOException {
    	File file = new File(path ,id) ;
    	if(id.endsWith("_original") && !file.exists()){
    		File orgFile = new File(path , id.substring(0 , id.indexOf("_original"))) ;
    		if(orgFile.exists()){
    			orgFile.renameTo(file) ;
    		}
    		UKTools.processImage(id, orgFile, path) ;
    	}else if(!StringUtils.isBlank(id) && file.exists() && !id.endsWith("_original")){
    		File destFile = new File(path , id+"_original") ;
    		file.renameTo(destFile) ;
    		UKTools.processImage(id, destFile, path) ;
    	}else if(!StringUtils.isBlank(id) && !file.exists() && !id.endsWith("_original")){
    		File destFile = new File(path , id+"_original") ;
    		if(destFile.exists()){
    			UKTools.processImage(id, destFile, path) ;
    		}
    		file = new File(path , id) ;
    	}
    	if(file.exists() && file.isFile()){
    		response.getOutputStream().write(FileUtils.readFileToByteArray(new File(path ,id)));
    	}
    }
    
    @RequestMapping("/voice")
    @Menu(type = "resouce" , subtype = "voice" , access = true)
    public void voice(HttpServletResponse response, @Valid String id) throws IOException {
    	File file = new File(path ,id) ;
    	if(file.exists() && file.isFile()){
    		response.getOutputStream().write(FileUtils.readFileToByteArray(new File(path ,id)));
    	}
    }
    
    @RequestMapping("/url")
    @Menu(type = "resouce" , subtype = "image" , access = true)
    public void url(HttpServletResponse response, @Valid String url) throws IOException {
    	byte[] data = new byte[1024] ;
    	int length = 0 ;
    	OutputStream out = response.getOutputStream();
    	if(!StringUtils.isBlank(url)){
    		InputStream input = new URL(url).openStream() ;
    		while((length = input.read(data) )> 0){
{'fraction_non_alphanumeric': 0.13718782073212452, 'fraction_numerical': 0.0027369141293191925, 'mean_word_length': 4.097646033129904, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4741705', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1855, 'n_words': 356}