示例#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);
  }