-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
1,133 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/main/java/io/github/yajuhua/podcast2/annotation/DatabaseAndPluginFileSync.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.github.yajuhua.podcast2.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* 数据库记录与插件文件同步注解 | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.METHOD}) | ||
public @interface DatabaseAndPluginFileSync { | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/io/github/yajuhua/podcast2/aop/PLuginManagerAOP.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.github.yajuhua.podcast2.aop; | ||
|
||
import io.github.yajuhua.podcast2.annotation.DatabaseAndPluginFileSync; | ||
import io.github.yajuhua.podcast2.plugin.PluginManager; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.reflect.MethodSignature; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
@Aspect | ||
@Component | ||
public class PLuginManagerAOP { | ||
|
||
@Autowired | ||
private PluginManager pluginManager; | ||
|
||
/** | ||
* 数据库记录与插件文件同步 | ||
* @param joinPoint | ||
*/ | ||
@Around("execution(* io.github.yajuhua.podcast2.plugin.PluginManager.*(..))") | ||
public Object pre(ProceedingJoinPoint joinPoint) throws Throwable { | ||
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); | ||
Method method = signature.getMethod(); | ||
if (method.isAnnotationPresent(DatabaseAndPluginFileSync.class)){ | ||
//调用databaseAndPluginFileSync | ||
pluginManager.databaseAndPluginFileSync(); | ||
} | ||
return joinPoint.proceed(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/io/github/yajuhua/podcast2/config/PluginManagerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.github.yajuhua.podcast2.config; | ||
|
||
import io.github.yajuhua.podcast2.common.properties.DataPathProperties; | ||
import io.github.yajuhua.podcast2.common.properties.RepoProperties; | ||
import io.github.yajuhua.podcast2.mapper.PluginMapper; | ||
import io.github.yajuhua.podcast2.plugin.PluginManager; | ||
import io.github.yajuhua.podcast2.pojo.entity.ExtendInfo; | ||
import io.github.yajuhua.podcast2.service.UserService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* 插件管理配置类 | ||
*/ | ||
@Configuration | ||
@Slf4j | ||
public class PluginManagerConfig { | ||
|
||
@Autowired | ||
private PluginMapper pluginMapper; | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
@Autowired | ||
private RepoProperties repoProperties; | ||
|
||
@Autowired | ||
private DataPathProperties dataPathProperties; | ||
@Bean | ||
public PluginManager pluginManager(){ | ||
String remotePluginUrl; | ||
String remotePluginUrlDefault = repoProperties.getPluginUrl(); | ||
String remotePluginUrlCustomzie = userService.getExtendInfo().getPluginUrl(); | ||
File pluginDir = new File(dataPathProperties.getLocalPluginPath()); | ||
|
||
if (remotePluginUrlCustomzie == null || remotePluginUrlCustomzie.isEmpty()){ | ||
remotePluginUrl = remotePluginUrlDefault; | ||
}else if (PluginManager.remoteRepoIsOK(remotePluginUrlCustomzie)){ | ||
remotePluginUrl = remotePluginUrlCustomzie; | ||
}else { | ||
remotePluginUrl = remotePluginUrlDefault; | ||
userService.updateExtendInfo(ExtendInfo.builder().pluginUrl("").build()); | ||
} | ||
|
||
PluginManager pluginManager = new PluginManager(pluginDir,remotePluginUrl,pluginMapper); | ||
return pluginManager; | ||
} | ||
|
||
} |
Oops, something went wrong.