|
20 | 20 | from astrbot.core.astr_agent_runtime.computer.computer_client import ( |
21 | 21 | sync_skills_to_active_sandboxes, |
22 | 22 | ) |
| 23 | +from astrbot.core.config.default import PLUGIN_DEFAULT_REGISTRY_URL |
23 | 24 | from astrbot.core.repository import ( |
24 | 25 | GitUnavailableError, |
25 | 26 | normalize_repository_url, |
@@ -110,6 +111,7 @@ def __init__( |
110 | 111 | EventType.OnPluginErrorEvent: "插件报错时", |
111 | 112 | } |
112 | 113 | self._logo_cache: dict[str, str] = {} |
| 114 | + self._create_source_lock = asyncio.Lock() |
113 | 115 |
|
114 | 116 | @staticmethod |
115 | 117 | def _payload(data: object) -> dict[str, Any]: |
@@ -1091,9 +1093,9 @@ def build_registry_source(custom_url: str | None) -> RegistrySource: |
1091 | 1093 | urls = [custom_url] |
1092 | 1094 | else: |
1093 | 1095 | cache_file = os.path.join(data_dir, "plugins.json") |
1094 | | - md5_url = "https://api.soulter.top/astrbot/plugins-md5" |
| 1096 | + md5_url = PLUGIN_DEFAULT_REGISTRY_URL.removesuffix(".json") + "-md5.json" |
1095 | 1097 | urls = [ |
1096 | | - "https://api.soulter.top/astrbot/plugins", |
| 1098 | + PLUGIN_DEFAULT_REGISTRY_URL, |
1097 | 1099 | "https://github.com/AstrBotDevs/AstrBot_Plugins_Collection/raw/refs/heads/main/plugin_cache_original.json", |
1098 | 1100 | ] |
1099 | 1101 | return RegistrySource(urls=urls, cache_file=cache_file, md5_url=md5_url) |
@@ -2095,13 +2097,30 @@ def _custom_sources_from_payload(payload: dict[str, Any]) -> list: |
2095 | 2097 | raise PluginServiceError("sources fields must be a list") |
2096 | 2098 | return sources |
2097 | 2099 |
|
2098 | | - @staticmethod |
2099 | | - async def create_custom_source(data: object) -> list: |
| 2100 | + async def create_custom_source(self, data: object) -> list: |
| 2101 | + """Append a plugin source once, including when the request is retried. |
| 2102 | +
|
| 2103 | + Args: |
| 2104 | + data: Source fields from the add-source request. |
| 2105 | +
|
| 2106 | + Returns: |
| 2107 | + The saved list of custom sources. |
| 2108 | + """ |
2100 | 2109 | source = data if isinstance(data, dict) else {} |
2101 | | - sources = await PluginService.get_custom_sources() |
2102 | | - sources.append(source) |
2103 | | - await sp.global_put("custom_plugin_sources", sources) |
2104 | | - return sources |
| 2110 | + url = self.normalize_registry_url(source.get("url")) |
| 2111 | + async with self._create_source_lock: |
| 2112 | + sources = await self.get_custom_sources() |
| 2113 | + if url and any( |
| 2114 | + self.normalize_registry_url( |
| 2115 | + item.get("url") if isinstance(item, dict) else item |
| 2116 | + ) |
| 2117 | + == url |
| 2118 | + for item in sources |
| 2119 | + ): |
| 2120 | + return sources |
| 2121 | + sources.append(source) |
| 2122 | + await sp.global_put("custom_plugin_sources", sources) |
| 2123 | + return sources |
2105 | 2124 |
|
2106 | 2125 | @staticmethod |
2107 | 2126 | async def replace_custom_sources(data: object) -> list: |
|
0 commit comments