package com.uas.report.controller;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

import org.apache.http.client.ClientProtocolException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.uas.report.model.Resource;
import com.uas.report.service.ResourceService;

@Controller
@RequestMapping("/resources")
public class ResourceController {
	@Autowired
	private ResourceService resourceService;

	@RequestMapping("/sync")
	@ResponseBody
	public List<Resource> syncResources(String userName)
			throws ClientProtocolException, URISyntaxException, IOException {
		userName = userName == null ? null : userName.toUpperCase();
		return resourceService.syncResources(userName);
	}

	@RequestMapping("")
	@ResponseBody
	public List<Resource> getResources(String folderPath)
			throws ClientProtocolException, URISyntaxException, IOException {
		return resourceService.getRemoteResources(folderPath);
	}

	@RequestMapping("/download")
	@ResponseBody
	public String downloadFile(String filePath, String mimeType, String exportPath)
			throws ClientProtocolException, URISyntaxException, IOException {
		resourceService.downloadFile(filePath, mimeType, exportPath);
		return "已下载文件至" + exportPath;
	}
}
