use of com.publiccms.entities.log.LogUpload in project PublicCMS-preview by sanluan.
the class CmsWebFileAdminController method upload.
/**
* @param file
* @param path
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("doUpload")
public String upload(MultipartFile file, String path, HttpServletRequest request, HttpSession session, ModelMap model) {
if (null != file && !file.isEmpty()) {
try {
SysSite site = getSite(request);
path = path + SEPARATOR + file.getOriginalFilename();
fileComponent.upload(file, siteComponent.getWebFilePath(site, path));
logUploadService.save(new LogUpload(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, false, file.getSize(), RequestUtils.getIpAddress(request), CommonUtils.getDate(), path));
} catch (IOException e) {
model.addAttribute(ERROR, e.getMessage());
log.error(e.getMessage(), e);
return TEMPLATE_ERROR;
}
}
return TEMPLATE_DONE;
}
use of com.publiccms.entities.log.LogUpload in project PublicCMS-preview by sanluan.
the class UeditorAdminController method listfile.
/**
* @param start
* @param request
* @param session
* @return view name
*/
@SuppressWarnings("unchecked")
@RequestMapping(params = "action=" + ACTION_LISTFILE)
@ResponseBody
public Map<String, Object> listfile(Integer start, HttpServletRequest request, HttpSession session) {
if (CommonUtils.empty(start)) {
start = 0;
}
PageHandler page = logUploadService.getPage(getSite(request).getId(), getAdminFromSession(session).getId(), null, null, null, null, null, start / 20 + 1, 20);
Map<String, Object> map = getResultMap(true);
List<Map<String, Object>> list = new ArrayList<>();
for (LogUpload logUpload : ((List<LogUpload>) page.getList())) {
Map<String, Object> tempMap = getResultMap(true);
tempMap.put("url", logUpload.getFilePath());
list.add(tempMap);
}
map.put("list", list);
map.put("start", start);
map.put("total", page.getTotalCount());
return map;
}
use of com.publiccms.entities.log.LogUpload in project PublicCMS-preview by sanluan.
the class UeditorAdminController method catchimage.
/**
* @param request
* @param session
* @return view name
*/
@RequestMapping(params = "action=" + ACTION_CATCHIMAGE)
@ResponseBody
public Map<String, Object> catchimage(HttpServletRequest request, HttpSession session) {
SysSite site = getSite(request);
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
String[] files = request.getParameterValues(FIELD_NAME + "[]");
if (CommonUtils.notEmpty(files)) {
List<Map<String, Object>> list = new ArrayList<>();
for (String image : files) {
HttpGet httpget = new HttpGet(image);
CloseableHttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (null != entity) {
String suffix = null;
if (CommonUtils.notEmpty(entity.getContentType().getElements())) {
suffix = CONTENT_TYPE_MAP.get(entity.getContentType().getElements()[0].getName());
}
if (CommonUtils.empty(suffix)) {
suffix = ".jpg";
}
String fileName = fileComponent.getUploadFileName(suffix);
File dest = new File(siteComponent.getWebFilePath(site, fileName));
FileUtils.copyInputStreamToFile(entity.getContent(), dest);
logUploadService.save(new LogUpload(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, true, dest.length(), RequestUtils.getIpAddress(request), CommonUtils.getDate(), fileName));
Map<String, Object> map = getResultMap(true);
map.put("size", entity.getContentLength());
map.put("title", dest.getName());
map.put("url", fileName);
map.put("source", image);
list.add(map);
}
EntityUtils.consume(entity);
}
Map<String, Object> map = getResultMap(true);
map.put("list", list);
return map;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
return getResultMap(false);
}
return getResultMap(false);
}
use of com.publiccms.entities.log.LogUpload in project PublicCMS-preview by sanluan.
the class UeditorAdminController method upload.
/**
* @param file
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping(params = "action=" + ACTION_UPLOAD)
public String upload(MultipartFile file, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
if (null != file && !file.isEmpty()) {
String originalName = file.getOriginalFilename();
String suffix = fileComponent.getSuffix(originalName);
String fileName = fileComponent.getUploadFileName(suffix);
try {
fileComponent.upload(file, siteComponent.getWebFilePath(site, fileName));
logUploadService.save(new LogUpload(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, false, file.getSize(), RequestUtils.getIpAddress(request), CommonUtils.getDate(), fileName));
Map<String, Object> map = getResultMap(true);
map.put("size", file.getSize());
map.put("title", originalName);
map.put("url", fileName);
map.put("type", suffix);
map.put("original", originalName);
model.addAttribute("result", map);
} catch (IllegalStateException | IOException e) {
model.addAttribute("result", getResultMap(false));
}
} else {
model.addAttribute("result", getResultMap(false));
}
return "common/mapResult";
}
use of com.publiccms.entities.log.LogUpload in project PublicCMS-preview by sanluan.
the class CkeditorAdminController method upload.
/**
* @param upload
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("upload")
public String upload(MultipartFile upload, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
if (null != upload && !upload.isEmpty()) {
String originalName = upload.getOriginalFilename();
String suffix = fileComponent.getSuffix(originalName);
String fileName = fileComponent.getUploadFileName(suffix);
try {
fileComponent.upload(upload, siteComponent.getWebFilePath(site, fileName));
logUploadService.save(new LogUpload(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, false, upload.getSize(), RequestUtils.getIpAddress(request), CommonUtils.getDate(), fileName));
Map<String, Object> map = getResultMap(true);
map.put(RESULT_FILENAME, originalName);
map.put(RESULT_URL, fileName);
model.addAttribute("result", map);
} catch (IllegalStateException | IOException e) {
Map<String, Object> map = getResultMap(false);
Map<String, String> messageMap = new HashMap<>();
messageMap.put(MESSAGE, e.getMessage());
map.put(ERROR, messageMap);
model.addAttribute("result", map);
}
} else {
Map<String, Object> map = getResultMap(false);
Map<String, String> messageMap = new HashMap<>();
messageMap.put(MESSAGE, "no file");
map.put(ERROR, messageMap);
model.addAttribute("result", map);
}
return "common/ckuploadResult";
}
Aggregations