feat(resource): 重构资源存储和加载机制

- 新增 AbstractResourceStore 类,实现 ResourceStore 接口的通用逻辑
- 创建 FontCache 类,用于缓存和管理字体资源
- 重构 DefaultImageCaptchaResourceManager 类,支持资源提供者和监听器
- 更新 Resource 和 ResourceMap 类,增加唯一 ID 字段
- 新增 ResourceListener 接口,用于扩展资源存储功能
- 创建 ResourceProviders 类,统一管理资源提供者
- 更新 TACBuilder 类,支持新的资源存储和加载机制
This commit is contained in:
天爱有情
2024-11-22 11:54:21 +08:00
parent 2be22591bf
commit 600878f6bd
20 changed files with 661 additions and 107 deletions
@@ -3,6 +3,8 @@ package cloud.tianai.captcha.resource;
import cloud.tianai.captcha.resource.common.model.dto.Resource;
import cloud.tianai.captcha.resource.common.model.dto.ResourceMap;
import java.util.List;
/**
* @Author: 天爱有情
* @date 2022/5/7 9:04
@@ -10,6 +12,14 @@ import cloud.tianai.captcha.resource.common.model.dto.ResourceMap;
*/
public interface ResourceStore {
void init(ImageCaptchaResourceManager resourceManager);
/**
* 给ResourceStore添加hook,用于一些扩展
*
* @param hook
*/
void addListener(ResourceListener hook);
/**
* 添加资源
*
@@ -27,6 +37,42 @@ public interface ResourceStore {
*/
void addTemplate(String type, ResourceMap template);
/**
* 删除资源
*
* @param type 验证码类型
* @param id 资源ID
* @return Resource
*/
Resource deleteResource(String type, String id);
/**
* 删除模板
*
* @param type 验证码类型
* @param id 资源ID
* @return ResourceMap
*/
ResourceMap deleteTemplate(String type, String id);
/**
* 获取某个资源列表
*
* @param type 验证码类型
* @param tag 资源标签(可为空)
* @return List<Resource>
*/
List<Resource> listResourcesByTypeAndTag(String type, String tag);
/**
* 获取某个模板列表
*
* @param type 验证码类型
* @param tag 资源标签(可为空)
* @return List<ResourceMap>
*/
List<ResourceMap> listTemplatesByTypeAndTag(String type, String tag);
/**
* 随机获取某个资源
*