Skip to content

Commit

Permalink
修复上传视频展示为图片的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
atjiu committed May 13, 2021
1 parent 80328ee commit 2a3e67f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Optional;

/**
* Created by tomoya.
Expand Down Expand Up @@ -54,7 +55,7 @@ private HttpStatus getStatus(HttpServletRequest request) {
public ModelAndView defaultErrorHandler(HttpServletRequest request, HttpServletResponse response, Exception e) throws Exception {
// 当报错了,又不知道啥错的时候,把下面这行代码打开,就可以看到报错的堆信息了
e.printStackTrace();
log.error(e.getMessage());
// log.error(e.getMessage());
if (!HttpUtil.isApiRequest(request)) {
response.setCharacterEncoding("utf-8");
ModelAndView mav = new ModelAndView();
Expand All @@ -65,9 +66,9 @@ public ModelAndView defaultErrorHandler(HttpServletRequest request, HttpServletR
} else /*if (accept.contains("application/json"))*/ {
Result result = new Result();
result.setCode(201);
result.setDescription(e.getMessage());
result.setDescription("服务器出错啦~");
response.setContentType("application/json;charset=utf-8");
response.getWriter().write(JsonUtil.objectToJson(result));
response.getWriter().write(Optional.ofNullable(JsonUtil.objectToJson(result)).orElse(""));
}
return null;
}
Expand All @@ -82,6 +83,7 @@ public ModelAndView defaultErrorHandler(HttpServletRequest request, HttpServletR
@ExceptionHandler(value = ApiException.class)
@ResponseBody
public Result jsonErrorHandler(ApiException e) {
log.info("api exception: {}", e.getMessage());
Result result = new Result();
result.setCode(e.getCode());
result.setDescription(e.getMessage());
Expand Down
24 changes: 14 additions & 10 deletions src/main/resources/templates/theme/default/components/editor.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@
suc("上传成功");
cb(data);
} else {
var error = "";
for (var k = 0; k < data.detail.errors.length; k++) {
error += data.detail.errors[k] + "<br/>";
if (!data.detail) {
err(data.description)
} else {
var error = "";
for (var k = 0; k < data.detail.errors.length; k++) {
error += data.detail.errors[k] + "<br/>";
}
err(error);
}
err(error);
}
};
// 获取上传进度
Expand Down Expand Up @@ -106,10 +110,10 @@
});
window.editor.setSize('auto', '450px');
var uploadImageFileEle = document.getElementById("uploadImageFileEle");
var type = document.getElementById("type").value;
var type = document.getElementById("type");
function uploadFile(type) {
$("#type").val(type);
function uploadFile(t) {
type.value = t;
uploadImageFileEle.click();
}
Expand All @@ -120,17 +124,17 @@
var insertContent = "";
for (var j = 0; j < data.detail.urls.length; j++) {
var url = data.detail.urls[j];
if (type === "topic") {
if (type.value === "topic") {
insertContent += "![image](" + url + ")\n\n"
} else if (type === "video") {
} else if (type.value === "video") {
insertContent += "<video class='embed-responsive embed-responsive-16by9' controls><source src='" + url + "' type='video/mp4'></video>\n\n";
}
}
window.editor.getDoc().setValue(oldContent + insertContent);
window.editor.focus();
//定位到文档的最后一个字符的位置
window.editor.setCursor(window.editor.lineCount(), 0);
document.getElementById("uploadImageForm").reset();
uploadImageFileEle.value = "";
});
});
</script>
Expand Down

0 comments on commit 2a3e67f

Please sign in to comment.