Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过缓存的图片特征验证其是否有效 #1401

Closed
yyuueexxiinngg opened this issue Jul 7, 2021 · 3 comments · Fixed by #1671
Closed

通过缓存的图片特征验证其是否有效 #1401

yyuueexxiinngg opened this issue Jul 7, 2021 · 3 comments · Fixed by #1671
Labels
N 优先级: 一般 t:feature 类型: 新特性
Milestone

Comments

@yyuueexxiinngg
Copy link
Contributor

通过缓存的图片元数据, 如md5结合size来查询是否图片存在于服务器

用例:
用户可仅缓存图片元数据而非源文件, 发送已缓存图片时查询缓存是否还有效
有效则直接通过md5, 即imageId构建, 无效则下载源文件发送并重新缓存元数据, 对于色图Bot而言可节省一大笔硬盘开销

另一用法为真实案例:
维护由用户设置的关键词回复时, 可仅缓存用户发送的图片元数据进数据库而非下载保存整个图片
触发回复时检测缓存是否有效, 如已失效则删除记录

目前onebot-mirai通过反射调用GroupPicUp判断FileExistsRequireUpload来检测缓存是否有效

@yyuueexxiinngg yyuueexxiinngg added the t:feature 类型: 新特性 label Jul 7, 2021
@Karlatemp
Copy link
Member

可以自行实现 ExternalResource 并将 inputStream 策略调整为 lazy 然后调用 uploadImage

@Him188
Copy link
Member

Him188 commented Jul 7, 2021

现在可以自行实现 ExternalResource 接口,实现其 size 和 md5,其余属性直接抛出一个特定异常。用该 resource 发送图片,捕获到特定异常就表示图片已过期,无异常则是图片还未过期。

@Him188 Him188 added the N 优先级: 一般 label Jul 7, 2021
@Him188 Him188 added this to the 2.9 milestone Jul 7, 2021
@khjxiaogu
Copy link

可以设计一个API查询服务器上面有无某个ExternalResource。

@Him188 Him188 modified the milestones: 2.9, 2.9.0-M1 Nov 9, 2021
Him188 added a commit that referenced this issue Nov 15, 2021
add member `Image.md5`,
add `Image.calculateImageMd5ByImageId`,
close #1401
Him188 added a commit that referenced this issue Nov 16, 2021
* Support `Image.isUploaded`,
add member `Image.md5`,
add `Image.calculateImageMd5ByImageId`,
close #1401

* Update docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
N 优先级: 一般 t:feature 类型: 新特性
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants