refactor: align ssl helper namespace and confirm usage

This commit is contained in:
邹永赫
2026-02-10 16:30:47 +09:00
parent 191b0c5f18
commit ba884f7643
12 changed files with 120 additions and 56 deletions
+3 -1
View File
@@ -4,7 +4,9 @@ import threading
import aiohttp
from http_ssl_common import build_ssl_context_with_certifi as _build_ssl_context
from astrbot.utils.http_ssl_common import (
build_ssl_context_with_certifi as _build_ssl_context,
)
logger = logging.getLogger("astrbot")
+62 -33
View File
@@ -49,6 +49,57 @@ def _cleanup_added_root_handlers(original_handlers: list[logging.Handler]) -> No
handler.close()
def _get_loader_for_package(package: object) -> object | None:
loader = getattr(package, "__loader__", None)
if loader is not None:
return loader
spec = getattr(package, "__spec__", None)
if spec is None:
return None
return getattr(spec, "loader", None)
def _try_register_distlib_finder(
distlib_resources: object,
finder_registry: dict[type, object],
register_finder,
resource_finder: object,
loader: object,
package_name: str,
) -> bool:
loader_type = type(loader)
if loader_type in finder_registry:
return False
try:
register_finder(loader_type, resource_finder)
except Exception as exc:
logger.warning(
"Failed to patch pip distlib finder for loader %s (%s): %s",
loader_type.__name__,
package_name,
exc,
)
return False
updated_registry = getattr(distlib_resources, "_finder_registry", finder_registry)
if isinstance(updated_registry, dict) and loader_type not in updated_registry:
logger.warning(
"Distlib finder patch did not take effect for loader %s (%s).",
loader_type.__name__,
package_name,
)
return False
logger.info(
"Patched pip distlib finder for frozen loader: %s (%s)",
loader_type.__name__,
package_name,
)
return True
def _patch_distlib_finder_for_frozen_runtime() -> None:
global _DISTLIB_FINDER_PATCH_ATTEMPTED
@@ -85,43 +136,21 @@ def _patch_distlib_finder_for_frozen_runtime() -> None:
except Exception:
continue
loader = getattr(package, "__loader__", None)
if loader is None:
loader = getattr(getattr(package, "__spec__", None), "loader", None)
loader = _get_loader_for_package(package)
if loader is None:
continue
loader_type = type(loader)
if loader_type in finder_registry:
continue
try:
register_finder(loader, resource_finder)
except Exception as exc:
logger.warning(
"Failed to patch pip distlib finder for loader %s (%s): %s",
loader_type.__name__,
package_name,
exc,
)
continue
finder_registry = getattr(
distlib_resources, "_finder_registry", finder_registry
)
if isinstance(finder_registry, dict) and loader_type not in finder_registry:
logger.warning(
"Distlib finder patch did not take effect for loader %s (%s).",
loader_type.__name__,
package_name,
)
continue
logger.info(
"Patched pip distlib finder for frozen loader: %s (%s)",
loader_type.__name__,
if _try_register_distlib_finder(
distlib_resources,
finder_registry,
register_finder,
resource_finder,
loader,
package_name,
)
):
finder_registry = getattr(
distlib_resources, "_finder_registry", finder_registry
)
class PipInstaller:
+1
View File
@@ -0,0 +1 @@
@@ -218,7 +218,10 @@ import axios from 'axios';
import { VueMonacoEditor } from '@guolao/vue-monaco-editor';
import ItemCard from '@/components/shared/ItemCard.vue';
import { useI18n, useModuleI18n } from '@/i18n/composables';
import { askForConfirmation as askForConfirmationDialog } from '@/utils/confirmDialog';
import {
askForConfirmation as askForConfirmationDialog,
useConfirmDialog
} from '@/utils/confirmDialog';
export default {
name: 'McpServersSection',
@@ -229,7 +232,8 @@ export default {
setup() {
const { t } = useI18n();
const { tm } = useModuleI18n('features/tooluse');
return { t, tm };
const confirmDialog = useConfirmDialog();
return { t, tm, confirmDialog };
},
data() {
return {
@@ -386,7 +390,7 @@ export default {
async deleteServer(server) {
const serverName = server.name || server;
const message = this.tm('dialogs.confirmDelete', { name: serverName });
if (!(await askForConfirmationDialog(message, this.$confirm))) {
if (!(await askForConfirmationDialog(message, this.confirmDialog))) {
return;
}
@@ -307,7 +307,10 @@
<script>
import axios from 'axios';
import { useModuleI18n } from '@/i18n/composables';
import { askForConfirmation as askForConfirmationDialog } from '@/utils/confirmDialog';
import {
askForConfirmation as askForConfirmationDialog,
useConfirmDialog
} from '@/utils/confirmDialog';
export default {
name: 'PersonaForm',
@@ -332,7 +335,8 @@ export default {
emits: ['update:modelValue', 'saved', 'error', 'deleted'],
setup() {
const { tm } = useModuleI18n('features/persona');
return { tm };
const confirmDialog = useConfirmDialog();
return { tm, confirmDialog };
},
data() {
return {
@@ -601,7 +605,7 @@ export default {
if (
!(await askForConfirmationDialog(
this.tm('messages.deleteConfirm', { id: this.editingPersona.persona_id }),
this.$confirm,
this.confirmDialog,
))
) {
return;
+8 -3
View File
@@ -190,7 +190,10 @@ import WaitingForRestart from '@/components/shared/WaitingForRestart.vue';
import StandaloneChat from '@/components/chat/StandaloneChat.vue';
import { VueMonacoEditor } from '@guolao/vue-monaco-editor'
import { useI18n, useModuleI18n } from '@/i18n/composables';
import { askForConfirmation as askForConfirmationDialog } from '@/utils/confirmDialog';
import {
askForConfirmation as askForConfirmationDialog,
useConfirmDialog
} from '@/utils/confirmDialog';
export default {
name: 'ConfigPage',
@@ -209,10 +212,12 @@ export default {
setup() {
const { t } = useI18n();
const { tm } = useModuleI18n('features/config');
const confirmDialog = useConfirmDialog();
return {
t,
tm
tm,
confirmDialog
};
},
@@ -476,7 +481,7 @@ export default {
},
async confirmDeleteConfig(config) {
const message = this.tm('configManagement.confirmDelete').replace('{name}', config.name);
if (await askForConfirmationDialog(message, this.$confirm)) {
if (await askForConfirmationDialog(message, this.confirmDialog)) {
this.deleteConfig(config.id);
}
},
+8 -3
View File
@@ -333,7 +333,10 @@ import { useCommonStore } from '@/stores/common';
import { useCustomizerStore } from '@/stores/customizer';
import { useI18n, useModuleI18n } from '@/i18n/composables';
import MessageList from '@/components/chat/MessageList.vue';
import { askForConfirmation as askForConfirmationDialog } from '@/utils/confirmDialog';
import {
askForConfirmation as askForConfirmationDialog,
useConfirmDialog
} from '@/utils/confirmDialog';
export default {
name: 'ConversationPage',
@@ -346,12 +349,14 @@ export default {
const { t, locale } = useI18n();
const { tm } = useModuleI18n('features/conversation');
const customizerStore = useCustomizerStore();
const confirmDialog = useConfirmDialog();
return {
t,
tm,
locale,
customizerStore
customizerStore,
confirmDialog
};
},
@@ -747,7 +752,7 @@ export default {
// 关闭对话历史对话框
async closeHistoryDialog() {
if (this.isEditingHistory) {
if (await askForConfirmationDialog(this.tm('dialogs.view.confirmClose'), this.$confirm)) {
if (await askForConfirmationDialog(this.tm('dialogs.view.confirmClose'), this.confirmDialog)) {
this.dialogView = false;
}
} else {
+8 -3
View File
@@ -197,7 +197,10 @@ import AddNewPlatform from '@/components/platform/AddNewPlatform.vue';
import { useCommonStore } from '@/stores/common';
import { useI18n, useModuleI18n } from '@/i18n/composables';
import { getPlatformIcon, getTutorialLink } from '@/utils/platformUtils';
import { askForConfirmation as askForConfirmationDialog } from '@/utils/confirmDialog';
import {
askForConfirmation as askForConfirmationDialog,
useConfirmDialog
} from '@/utils/confirmDialog';
export default {
name: 'PlatformPage',
@@ -211,10 +214,12 @@ export default {
setup() {
const { t } = useI18n();
const { tm } = useModuleI18n('features/platform');
const confirmDialog = useConfirmDialog();
return {
t,
tm
tm,
confirmDialog
};
},
data() {
@@ -454,7 +459,7 @@ export default {
async deletePlatform(platform) {
const message = `${this.messages.deleteConfirm} ${platform.id}?`;
if (!(await askForConfirmationDialog(message, this.$confirm))) {
if (!(await askForConfirmationDialog(message, this.confirmDialog))) {
return;
}
@@ -522,17 +522,22 @@
<script>
import axios from 'axios'
import { useI18n, useModuleI18n } from '@/i18n/composables'
import { askForConfirmation as askForConfirmationDialog } from '@/utils/confirmDialog'
import {
askForConfirmation as askForConfirmationDialog,
useConfirmDialog
} from '@/utils/confirmDialog'
export default {
name: 'SessionManagementPage',
setup() {
const { t } = useI18n()
const { tm } = useModuleI18n('features/session-management')
const confirmDialog = useConfirmDialog()
return {
t,
tm
tm,
confirmDialog
}
},
data() {
@@ -1505,7 +1510,7 @@ export default {
async deleteGroup(group) {
const message = `确定要删除分组 "${group.name}" 吗?`
if (!(await askForConfirmationDialog(message, this.$confirm))) return
if (!(await askForConfirmationDialog(message, this.confirmDialog))) return
try {
const response = await axios.post('/api/session/group/delete', { id: group.id })
@@ -260,7 +260,10 @@ import PersonaCard from './PersonaCard.vue';
import PersonaForm from '@/components/shared/PersonaForm.vue';
import CreateFolderDialog from './CreateFolderDialog.vue';
import MoveToFolderDialog from './MoveToFolderDialog.vue';
import { askForConfirmation as askForConfirmationDialog } from '@/utils/confirmDialog';
import {
askForConfirmation as askForConfirmationDialog,
useConfirmDialog
} from '@/utils/confirmDialog';
import type { Folder, FolderTreeNode } from '@/components/folder/types';
@@ -295,7 +298,8 @@ export default defineComponent({
setup() {
const { t } = useI18n();
const { tm } = useModuleI18n('features/persona');
return { t, tm };
const confirmDialog = useConfirmDialog();
return { t, tm, confirmDialog };
},
data() {
return {
@@ -424,7 +428,7 @@ export default defineComponent({
if (
!(await askForConfirmationDialog(
this.tm('messages.deleteConfirm', { id: persona.persona_id }),
this.$confirm,
this.confirmDialog,
))
) {
return;
+1 -1
View File
@@ -4,7 +4,7 @@ from typing import Any
import aiohttp.connector as aiohttp_connector
from http_ssl_common import build_ssl_context_with_certifi
from astrbot.utils.http_ssl_common import build_ssl_context_with_certifi
logger = logging.getLogger(__name__)