Search in sources :

Example 1 with LogUpload

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;
}
Also used : LogUpload(com.publiccms.entities.log.LogUpload) IOException(java.io.IOException) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with LogUpload

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;
}
Also used : PageHandler(com.publiccms.common.handler.PageHandler) ArrayList(java.util.ArrayList) LogUpload(com.publiccms.entities.log.LogUpload) HashMap(java.util.HashMap) ModelMap(org.springframework.ui.ModelMap) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with LogUpload

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);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SysSite(com.publiccms.entities.sys.SysSite) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) LogUpload(com.publiccms.entities.log.LogUpload) HashMap(java.util.HashMap) ModelMap(org.springframework.ui.ModelMap) Map(java.util.Map) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with LogUpload

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";
}
Also used : LogUpload(com.publiccms.entities.log.LogUpload) IOException(java.io.IOException) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with LogUpload

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";
}
Also used : HashMap(java.util.HashMap) LogUpload(com.publiccms.entities.log.LogUpload) IOException(java.io.IOException) HashMap(java.util.HashMap) ModelMap(org.springframework.ui.ModelMap) Map(java.util.Map) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

LogUpload (com.publiccms.entities.log.LogUpload)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 SysSite (com.publiccms.entities.sys.SysSite)7 IOException (java.io.IOException)7 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ModelMap (org.springframework.ui.ModelMap)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 PageHandler (com.publiccms.common.handler.PageHandler)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1