Beispiel #1
0
  // -- v1.1 --//
  @RequestMapping(
      value = PREFIX_API_1_1_COMMENTS + "createWithMedia.json",
      method = RequestMethod.POST)
  @ResponseBody
  public Object createWithMedia_v1_1(
      @RequestParam(value = "videoUrl", required = false) String videoUrl,
      @RequestParam(value = "imageUrl", required = false) String imageUrl,
      @RequestParam(value = "audioUrl", required = false) String audioUrl,
      @RequestParam(value = "audioDuration", required = false) Long audioDuration,
      @RequestParam(value = "videoDuration", required = false) Long videoDuration,
      @RequestParam(value = "text", required = false) String text,
      @RequestParam(value = "postId", required = false) String postId,
      @RequestParam(value = "replyCommentId", required = false) String replyCommentId) {

    if (StringUtils.isBlank(postId) && StringUtils.isBlank(replyCommentId)) {
      return ErrorDto.badRequest("参数postId和replyCommentId不能都为空");
    }

    // 读取附件信息
    FileInfo videoFileInfo = null;
    FileInfo imageFileInfo = null;
    FileInfo audioFileInfo = null;

    // 视频评论
    if (StringUtils.isNotBlank(videoUrl) && StringUtils.isNotBlank(imageUrl)) {

      videoFileInfo = aLiYunStorageService.getTmpFileInfoFromUrl(videoUrl);
      videoFileInfo.setDuration(videoDuration);
      imageFileInfo = aLiYunStorageService.getTmpFileInfoFromUrl(imageUrl);

      try {

        uploadService.checkVideo(videoFileInfo);
        uploadService.checkImage(imageFileInfo);

      } catch (ServiceException e) {

        aLiYunStorageService.delete(videoFileInfo.getTmpKey());
        aLiYunStorageService.delete(imageFileInfo.getTmpKey());

        throw e;
      }
    }

    // 语音评论
    else if (StringUtils.isNotBlank(audioUrl)) {

      audioFileInfo = aLiYunStorageService.getTmpFileInfoFromUrl(audioUrl);
      audioFileInfo.setDuration(audioDuration);

      try {

        uploadService.checkAudio(audioFileInfo);

      } catch (ServiceException e) {

        aLiYunStorageService.delete(audioFileInfo.getTmpKey());

        throw e;
      }
    }

    // 参数错误
    else {
      return ErrorDto.badRequest("参数必须满足这个条件:(videoUrl不为空 && imageUrl不为空) || (audioUrl不为空)");
    }

    return createComment(text, replyCommentId, postId, videoFileInfo, imageFileInfo, audioFileInfo);
  }
Beispiel #2
0
  /** 视频评论 */
  @RequestMapping(value = PREFIX_API_1_COMMENTS + "createWithMedia", method = RequestMethod.POST)
  @ResponseBody
  public Object createWithMedia(
      @RequestParam(value = "video", required = false) MultipartFile video,
      @RequestParam(value = "image", required = false) MultipartFile image,
      @RequestParam(value = "audio", required = false) MultipartFile audio,
      @RequestParam(value = "audioDuration", required = false) Long audioDuration,
      @RequestParam(value = "text", required = false) String text,
      @RequestParam(value = "postId", required = false) String postId,
      @RequestParam(value = "replyCommentId", required = false) String replyCommentId) {
    try {
      logger.debug("正在发布视频评论:");
      if (video != null) {
        logger.debug("           video : {}", FileUtils.byteCountToDisplaySize(video.getSize()));
      }
      if (image != null) {
        logger.debug("           image : {}", FileUtils.byteCountToDisplaySize(image.getSize()));
      }
      if (audio != null) {
        logger.debug("           audio : {}", FileUtils.byteCountToDisplaySize(audio.getSize()));
      }
      logger.debug("            text : {}", text);
      logger.debug("          postId : {}", postId);
      logger.debug("  replyCommentId : {}", replyCommentId);

      // 参数检查
      if (StringUtils.isBlank(postId) && StringUtils.isBlank(replyCommentId)) {
        return ErrorDto.badRequest("参数postId和replyCommentId不能都为空");
      }

      // 文件大小限制
      if (video != null && video.getSize() > Setting.MAX_VIDEO_LENGTH_BYTES
          || image != null && image.getSize() > Setting.MAX_IMAGE_LENGTH_BYTES
          || audio != null && audio.getSize() > Setting.MAX_AUDIO_LENGTH_BYTES) {
        return ErrorDto.badRequest("上传的文件太大");
      }

      FileInfo videoFileInfo = null;
      FileInfo imageFileInfo = null;
      FileInfo audioFileInfo = null;

      // 视频评论
      if (video != null && image != null) {
        videoFileInfo = ControllerUtils.getFileInfo(video);
        imageFileInfo = ControllerUtils.getFileInfo(image);
      }
      // 语音评论
      else if (audio != null) {
        audioFileInfo = ControllerUtils.getFileInfo(audio);
        audioFileInfo.setDuration(audioDuration);
      }
      // 参数错误
      else {
        return ErrorDto.badRequest(
            "参数必须满足这个条件:(video != null && image != null) || (audio != null)");
      }

      return createComment(
          text, replyCommentId, postId, videoFileInfo, imageFileInfo, audioFileInfo);

    } catch (DuplicateException e) {
      return ErrorDto.duplicate();
    } catch (Exception e) {
      logger.info("发布评论失败", e);
      return ErrorDto.internalServerError(e.getMessage());
    }
  }