将附件转换到当前handler并且更新post中的链接, Covert attachments to current Handler
Created by: XuCpeng
@PutMapping("covert_attachment_handler")
@ApiOperation("Covert all attachments to current Handler.")
public Future<String> covertAttachmentHandler(
@RequestParam(name = "sourceAttachmentTypeId", required = false, defaultValue = "-1") Integer sourceAttachmentTypeId,
@RequestParam(name = "deleteOldAttachment", required = false, defaultValue = "false") Boolean deleteOldAttachment,
@RequestParam(name = "uploadAllInAttachment", required = false, defaultValue = "false") Boolean uploadAllInAttachment,
@RequestParam(name = "uploadAllInPost", required = false, defaultValue = "false") Boolean uploadAllInPost) {
return attachmentHandlerCovertService.covertHandlerByPosts(
sourceAttachmentTypeId,
deleteOldAttachment,
uploadAllInAttachment,
uploadAllInPost);
}
添加了一个接口,能够将附件库中的附件或者文章中的图片上传到“当前的图床”,并且更新post中的链接。基本原理是:正则提取post中markdown的的所有图片链接,用新的链接进行替换和更新。并且根据参数的设置,与附件中的链接进行比对,实现旧附件的删除或新附件的下载。
主要功能及参数如下:
- @param
sourceAttachmentTypeId
: 源图床ID (e.g. 0,1,2), 默认值为 -1 (所有图床). - @param
deleteOldAttachment
: 是否从旧图床删除已经上传成功的附件,默认 false. - @param
uploadAllInAttachment
: 是否上传源图床中所有附件,默认 false. - @param
uploadAllInPost
: 是否抓取并上传post中的所有图片,默认 false. -
@return
AsyncResult<String>
-
sourceAttachmentTypeId
可以通过方法AttachmentType.getValue()
获得, 特别的是,-1
表示使用所有图床作为源图床。 - 若
deleteOldAttachment = true
, 旧的附件在上传成功后将从源图床删除。 - 若
uploadAllInAttachment = true
, 将会上传源图床所有附件,即使没有被post使用;若为false则只上传被post使用的附件。 - 若
uploadAllInPost = true
, 将会自动抓取下载post中的所有图片,并且上传到当前hanlder,无论是否在附件库中。
TODO:自动更新图库中的链接。当前还不能自动更新图库中的链接,所以对图库有强烈需求的不要删除旧附件。
未写前端,测试方法:
- 在网页端登录后台,获取headers中的tocken
-
在postman中创建一个PUT请求,请求地址为
<blog host>/api/admin/attachments/covert_attachment_handler
,并在Headers中加入该tocken,admin-authorization: <tocken>
,参数按照上述添加即可。 -
发送请求后将通过Async的方式执行,所以客户端会立即返回200,但实际的执行结果需要在
spring.log
中查看。方法完成后还会返回AsyncResult<String>
,前端可以通过轮询获取结果。
Added an interface to upload the attachments in the attachment library or the pictures in the article to the "current handler" and update the md link in the post.
- @param
sourceAttachmentTypeId
: source attachment type id (e.g. 0,1,2), default = -1 (All AttachmentTypes). - @param
deleteOldAttachment
: Whether to delete old attachments, default = false. - @param
uploadAllInAttachment
: Whether to upload all attachments, default = false. - @param
uploadAllInPost
: Whether to download and upload all pictures in the all posts, default = false. -
@return
AsyncResult<String>
-
sourceAttachmentTypeId
can be gotten byAttachmentType.getValue()
, In particular,-1
means to use all AttachmentTypes. - if
deleteOldAttachment = true
, Old attachments that have been successfully uploaded will be deleted from the specified Handler. - if
uploadAllInAttachment = true
, Will upload all attachments, even if they are not quoted by the post, default = false. - if
uploadAllInPost = true
, Will download and upload all pictures in the all posts, even if they are not in the attachment library.
No web, test method:
- Log in to the admin on the web page and get the token in the headers.
-
Create a PUT request in postman, the request address is
<blog host>/api/admin/attachments/covert_attachment_handler
,and add the token in Headers,admin-authorization: <tocken>
,the parameters can be added as described above. -
After sending the request, it will be executed by Async, so the client will immediately return 200,But the actual execution result needs to be checked in
spring.log
. After the method is completed, it will returnAsyncResult<String>
, and the web can get the result through polling.
TODO:Automatically update the links in the gallery. Currently, the links in the gallery cannot be automatically updated, so do not delete old attachments if you have a strong demand for the gallery.