diff --git a/CHANGELOG.md b/CHANGELOG.md index 19c6de3..283a523 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,11 +20,25 @@ ``` ------ # 目录 +* [V 1.0.4]() * [V 1.0.3]() * [V 1.0.2]() * [V 1.0.1]() * [V 1.0.0]() +------ +## [V 1.0.4] - 2023.4.26 +### FileModule +- 🎈新增: 新增 `FileType`枚举类 用于`ConfigFile`的配置文件分类 +- 🎈新增: 新增 `ConfigVO`Config文件的前端渲染类 +- 🎈新增: 新增 `FileService,FileServiceImpl` 文件服务接口,目前拥有获取文件模块与获取配置文件 + +### console +- 🎈新增: 新增 `FileController` 文件接口 + +### console-ui +- 🎈新增: 新增文件管理页面 + ------ ## [V 1.0.3] - 2023.4.25 ### CreeperModule diff --git a/FileModule/src/main/java/org/example/cache/FileCache.java b/FileModule/src/main/java/org/example/cache/FileCache.java index 176d5ce..9530419 100644 --- a/FileModule/src/main/java/org/example/cache/FileCache.java +++ b/FileModule/src/main/java/org/example/cache/FileCache.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.example.common.ConfigFile; +import org.example.common.FileType; import org.example.exception.FileCacheException; import org.example.util.JsonFileUtil; import org.example.util.TimeUtil; @@ -71,7 +72,7 @@ public class FileCache { this.logger = LoggerFactory.getLogger("FileCache:"+this.configFile.getFileName()); this.autoSyncTime = autoSyncTime; - if(!load(getFileName())){ + if(!load(getFullFilePath())){ throw new FileCacheException("FileCache Init Error,please Check if your path is correct"); } @@ -240,7 +241,7 @@ public class FileCache { */ public void forceSync(){ if(writeByte.get()==0){ - logger.debug("未发生版本变化"); + logger.info("未发生版本变化"); return; } clearWriteBytes(); @@ -248,7 +249,7 @@ public class FileCache { try { syncChannel.put(temp); } catch (InterruptedException e) { - logger.debug("自动刷入失败"); + logger.error("自动刷入失败"); } } @@ -258,25 +259,40 @@ public class FileCache { */ private boolean sync(ConcurrentHashMap take){ configFile.updateConfigTime(); //刷新配置文件刷入时间 - String dir = getFileName(); + String dir = getFullFilePath(); configFile.onlyUpdateTime(take); File file = JsonFileUtil.writeJsonFile(dir, take); logger.debug("正在写入{}新版本",dir); return Objects.isNull(file); } + + + public BlockingQueue getFileChannel(){ return this.syncChannel; } - public String getFileName(){ + public String getFullFilePath(){ return Paths.get(this.configFile.getFilePath(), this.configFile.getFileName()).toString(); } + public String getFilePath(){ + return this.configFile.getFilePath(); + } + + public String getFileName(){ + return this.configFile.getFileName(); + } + public long getSyncTime(){ return this.autoSyncTime; } + public FileType getFileType(){ + return this.configFile.getFileType(); + } + class SyncMan implements Runnable{ @Override @@ -300,7 +316,7 @@ public class FileCache { @Override public boolean equals(Object obj) { if(obj instanceof FileCache){ - if(((FileCache) obj).getFileName().equals(this.getFileName())){ + if(((FileCache) obj).getFullFilePath().equals(this.getFullFilePath())){ return true; }else if(obj.hashCode() == this.hashCode()){ return true; diff --git a/FileModule/src/main/java/org/example/cache/FileCacheManager.java b/FileModule/src/main/java/org/example/cache/FileCacheManager.java index 8f91fca..cce49f8 100644 --- a/FileModule/src/main/java/org/example/cache/FileCacheManager.java +++ b/FileModule/src/main/java/org/example/cache/FileCacheManager.java @@ -75,6 +75,10 @@ public class FileCacheManager { return false; } + public List getRunnableFileCaches(){ + return this.fileCaches; + } + class Watcher implements Runnable{ @Override @@ -85,7 +89,7 @@ public class FileCacheManager { BlockingQueue fileChannel = cache.getFileChannel(); if(fileChannel.isEmpty()){ if(cache.needAutoSync()){ - logger.debug("检测到需要强制刷新的文件 {}",cache.getFileName()); + logger.info("检测到需要强制刷新的文件 {}",cache.getFileName()); autoSyncer.submit(new AutoSyncer(cache)); } } diff --git a/FileModule/src/main/java/org/example/init/FileCacheManagerInit.java b/FileModule/src/main/java/org/example/init/FileCacheManagerInit.java new file mode 100644 index 0000000..38aa4c0 --- /dev/null +++ b/FileModule/src/main/java/org/example/init/FileCacheManagerInit.java @@ -0,0 +1,16 @@ +package org.example.init; + +import org.example.cache.FileCacheManagerInstance; + +/** + * @author Genius + * @date 2023/04/26 02:09 + **/ +public class FileCacheManagerInit implements InitMachine{ + + @Override + public boolean init() { + FileCacheManagerInstance.getInstance().start(); + return true; + } +} diff --git a/FileModule/src/main/java/org/example/pojo/configfile/ModuleSrcConfigFile.java b/FileModule/src/main/java/org/example/pojo/configfile/ModuleSrcConfigFile.java index 650d2bb..3a1c426 100644 --- a/FileModule/src/main/java/org/example/pojo/configfile/ModuleSrcConfigFile.java +++ b/FileModule/src/main/java/org/example/pojo/configfile/ModuleSrcConfigFile.java @@ -1,6 +1,7 @@ package org.example.pojo.configfile; import org.example.common.ConfigFile; +import org.example.common.FileType; import org.example.constpool.ConstPool; import java.util.Map; @@ -44,7 +45,7 @@ public class ModuleSrcConfigFile extends ConfigFile packageConfig() { diff --git a/FileModule/src/main/java/org/example/pojo/vo/ConfigVO.java b/FileModule/src/main/java/org/example/pojo/vo/ConfigVO.java new file mode 100644 index 0000000..d687eb5 --- /dev/null +++ b/FileModule/src/main/java/org/example/pojo/vo/ConfigVO.java @@ -0,0 +1,20 @@ +package org.example.pojo.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.stereotype.Component; + +/** + * @author Genius + * @date 2023/04/26 02:07 + **/ +@Data +@Component +@AllArgsConstructor +@NoArgsConstructor +public class ConfigVO { + private String fileName; + private String filePath; + private String moduleType; +} diff --git a/FileModule/src/main/java/org/example/service/FileService.java b/FileModule/src/main/java/org/example/service/FileService.java new file mode 100644 index 0000000..a4f2e16 --- /dev/null +++ b/FileModule/src/main/java/org/example/service/FileService.java @@ -0,0 +1,19 @@ +package org.example.service; + +import org.example.pojo.vo.ConfigVO; + +import java.util.List; + +/** + * @author Genius + * @date 2023/04/26 00:59 + **/ + +public interface FileService { + + //获取所有模块 + List getAllModule(); + + //获取所有文件 + List getAllConfigs(); +} diff --git a/FileModule/src/main/java/org/example/service/impl/FileServiceImpl.java b/FileModule/src/main/java/org/example/service/impl/FileServiceImpl.java new file mode 100644 index 0000000..d65053b --- /dev/null +++ b/FileModule/src/main/java/org/example/service/impl/FileServiceImpl.java @@ -0,0 +1,49 @@ +package org.example.service.impl; + +import org.example.cache.FileCache; +import org.example.cache.FileCacheManager; +import org.example.cache.FileCacheManagerInstance; +import org.example.common.ConfigFile; +import org.example.common.FileType; +import org.example.pojo.vo.ConfigVO; +import org.example.service.FileService; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Genius + * @date 2023/04/26 01:01 + **/ + +@Service +public class FileServiceImpl implements FileService { + + @Override + public List getAllModule() { + List moduleList = new ArrayList<>(); + for (FileType value : FileType.values()) { + if(!value.equals(FileType.COMMON)){ + moduleList.add(value.getName()); + } + } + return moduleList; + } + + @Override + public List getAllConfigs() { + List configVOList = new ArrayList<>(); + List runnableFileCaches = FileCacheManagerInstance.getInstance().getRunnableFileCaches(); + for (FileCache runnableFileCache : runnableFileCaches) { + if (runnableFileCache.getFileType().equals(FileType.COMMON)) { + continue; + } + configVOList.add(new ConfigVO(runnableFileCache.getFileName() + ,runnableFileCache.getFullFilePath() + ,runnableFileCache.getFileType().getName())); + } + return configVOList; + } +} diff --git a/FileModule/target/classes/test.json b/FileModule/target/classes/test.json index eeda4e3..221426b 100644 --- a/FileModule/target/classes/test.json +++ b/FileModule/target/classes/test.json @@ -1,4 +1,65 @@ { - "data":[], - "updateTime":"2023-04-25 23:46:35" -} + "data":[ + { + "age":0, + "major":"major0", + "name":"0", + "school":"jsu0" + }, + { + "age":1, + "major":"major1", + "name":"1", + "school":"jsu1" + }, + { + "age":2, + "major":"major2", + "name":"2", + "school":"jsu2" + }, + { + "age":3, + "major":"major3", + "name":"3", + "school":"jsu3" + }, + { + "age":4, + "major":"major4", + "name":"4", + "school":"jsu4" + }, + { + "age":5, + "major":"major5", + "name":"5", + "school":"jsu5" + }, + { + "age":6, + "major":"major6", + "name":"6", + "school":"jsu6" + }, + { + "age":7, + "major":"major7", + "name":"7", + "school":"jsu7" + }, + { + "age":8, + "major":"major8", + "name":"8", + "school":"jsu8" + }, + { + "age":9, + "major":"major9", + "name":"9", + "school":"jsu9" + } + ], + "updateTime":"2023-04-26 00:24:47" +} \ No newline at end of file diff --git a/common/src/main/java/org/example/common/ConfigFile.java b/common/src/main/java/org/example/common/ConfigFile.java index 4232795..72f6f1b 100644 --- a/common/src/main/java/org/example/common/ConfigFile.java +++ b/common/src/main/java/org/example/common/ConfigFile.java @@ -12,6 +12,7 @@ import java.util.Map; //配置文件的抽象类,只负责构建配置文件最基础的架构,一般不用来存放配置文件本身的内容 public abstract class ConfigFile { + private FileType fileType; private String filePath; private String fileName; @@ -69,21 +70,34 @@ public abstract class ConfigFile { this.fileName = fileName; this.data = data; this.updateTime = LocalDateTime.now(); + this.fileType = FileType.COMMON; + } + + public ConfigFile(String filePath,String fileName,T data,FileType fileType){ + this.filePath = filePath; + this.fileName = fileName; + this.data = data; + this.updateTime = LocalDateTime.now(); + this.fileType = fileType; } public String getFilePath() { - return filePath; + return this.filePath; } public String getFileName() { - return fileName; + return this.fileName; } - public LocalDateTime getUpdateTime() {return updateTime;} + public LocalDateTime getUpdateTime() {return this.updateTime;} + + public FileType getFileType(){ + return this.fileType; + } //不推荐直接使用 public T getData() { - return data; + return this.data; } public void setData(T data){this.data = data;} diff --git a/common/src/main/java/org/example/common/FileType.java b/common/src/main/java/org/example/common/FileType.java new file mode 100644 index 0000000..8397fb0 --- /dev/null +++ b/common/src/main/java/org/example/common/FileType.java @@ -0,0 +1,21 @@ +package org.example.common; + +/** + * @author Genius + * @date 2023/04/26 01:48 + **/ +public enum FileType { + CHOPPER_BOT("ChopperBot"), + BARRAGE("弹幕设置"), + CREEPER("爬虫设置"), + VIDEO("文件下载"), + COMMON("普通文件"); + private final String name; + FileType(String name){ + this.name = name; + } + + public String getName(){ + return this.name; + } +} diff --git a/common/src/main/java/org/example/constpool/ConstPool.java b/common/src/main/java/org/example/constpool/ConstPool.java index a37b6fb..732fc14 100644 --- a/common/src/main/java/org/example/constpool/ConstPool.java +++ b/common/src/main/java/org/example/constpool/ConstPool.java @@ -16,5 +16,4 @@ public class ConstPool { public static final String HOT = "hot"; public static final String PUBLISH = "publish"; - } diff --git a/console-ui/src/api/FileController.ts b/console-ui/src/api/FileController.ts new file mode 100644 index 0000000..c2f33b6 --- /dev/null +++ b/console-ui/src/api/FileController.ts @@ -0,0 +1 @@ +import request from '@/utils/request'; export function getAllConfigModule() { return request({ url: '/config/allConfigModule/', method: 'get', params: { } }); } export function getAllConfigFiles() { return request({ url: '/config/allConfigFiles/', method: 'get', params: { } }); } \ No newline at end of file diff --git a/console-ui/src/api/aiApi.ts b/console-ui/src/api/aiApi.ts index 09f729f..36f9b7d 100644 --- a/console-ui/src/api/aiApi.ts +++ b/console-ui/src/api/aiApi.ts @@ -12,7 +12,7 @@ gptInstance.interceptors.response.use( (error) => { const snackbarStore = useSnackbarStore(); if (error.response) { - const status = error.response.status; + //const status = error.response.status; const data = error.response.data; snackbarStore.showErrorMessage(data.error); } else { diff --git a/console-ui/src/utils/request.ts b/console-ui/src/utils/request.ts new file mode 100644 index 0000000..2fa6c48 --- /dev/null +++ b/console-ui/src/utils/request.ts @@ -0,0 +1,40 @@ +import axios from "axios"; + +const request = axios.create({ + baseURL: "/appApi", + timeout: 100000, +}); + +request.interceptors.request.use(config => { + //config.headers['Content-Type'] = 'application/json'; + return config +}, error => { + return Promise.reject(error) +}); + +// response 拦截器 +// 可以在接口响应后统一处理结果 +request.interceptors.response.use( + response => { + let res = response.data; + + // 如果是返回的文件 + if (response.config.responseType === 'blob') { + return res + } + // 兼容服务端返回的字符串数据 + if (typeof res === 'string') { + res = res ? JSON.parse(res) : res + } + return res; + }, + error => { + console.log('err' + error) // for debug + // localStorage.removeItem('token') + //router.replace({path:'/login'}) + return Promise.reject(error) + } +) + + +export default request diff --git a/console-ui/src/views/utility/BoardPage.vue b/console-ui/src/views/utility/BoardPage.vue index f1b5f97..c86ef05 100644 --- a/console-ui/src/views/utility/BoardPage.vue +++ b/console-ui/src/views/utility/BoardPage.vue @@ -1,6 +1,6 @@