mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-09-14 11:06:13 +05:00
Keep plugin dependency selection server-side
This commit is contained in:
parent
c85149db13
commit
cbeeda9210
@ -93,7 +93,6 @@ from archivebox.core.routes_util import (
|
||||
from archivebox.core.forms import AddLinkForm
|
||||
from archivebox.plugins.forms import get_plugin_config_binary_urls
|
||||
from archivebox.crawls.models import Crawl
|
||||
from archivebox.plugins.discovery import discover_plugin_configs
|
||||
from archivebox.plugins.views import get_config_definition_link
|
||||
from archivebox.progressmonitor.views import live_progress_view, progress_endpoint
|
||||
|
||||
@ -1424,7 +1423,6 @@ class AddView(UserPassesTestMixin, FormView):
|
||||
request_config = get_request_config(self.request, resolve_plugins=True)
|
||||
required_search_plugin = f"search_backend_{request_config.SEARCH_BACKEND_ENGINE}".strip()
|
||||
can_override_crawl_config = self._can_override_crawl_config()
|
||||
plugin_configs = discover_plugin_configs() if can_override_crawl_config else {}
|
||||
public_persona_config_keys = {
|
||||
"CRAWL_MAX_CONCURRENT_SNAPSHOTS",
|
||||
"DELETE_AFTER",
|
||||
@ -1453,17 +1451,6 @@ class AddView(UserPassesTestMixin, FormView):
|
||||
"binary_urls": binary_urls,
|
||||
}
|
||||
recent_personas = list(persona_queryset.order_by("-created_at", "name")[:5])
|
||||
plugin_dependency_map = {}
|
||||
if can_override_crawl_config:
|
||||
plugin_dependency_map = {
|
||||
plugin_name: [
|
||||
str(required_plugin).strip()
|
||||
for required_plugin in (schema.get("required_plugins") or [])
|
||||
if str(required_plugin).strip()
|
||||
]
|
||||
for plugin_name, schema in plugin_configs.items()
|
||||
if isinstance(schema.get("required_plugins"), list) and schema.get("required_plugins")
|
||||
}
|
||||
return {
|
||||
**context,
|
||||
"title": "Create Crawl",
|
||||
@ -1473,7 +1460,6 @@ class AddView(UserPassesTestMixin, FormView):
|
||||
"VERSION": VERSION,
|
||||
"FOOTER_INFO": request_config.FOOTER_INFO,
|
||||
"required_search_plugin": required_search_plugin,
|
||||
"plugin_dependency_map_json": json.dumps(plugin_dependency_map, sort_keys=True),
|
||||
"persona_config_map_json": json.dumps(persona_config_map, sort_keys=True, default=str),
|
||||
"recent_personas": recent_personas,
|
||||
"can_override_crawl_config": can_override_crawl_config,
|
||||
|
||||
@ -374,7 +374,6 @@
|
||||
if (sameDomainToggleSlot && shortcutToggles.length) {
|
||||
shortcutToggles.forEach((toggle) => sameDomainToggleSlot.appendChild(toggle));
|
||||
}
|
||||
const pluginDependencyMap = JSON.parse('{{ plugin_dependency_map_json|default:"{}"|escapejs }}');
|
||||
const personaConfigMap = JSON.parse('{{ persona_config_map_json|default:"{}"|escapejs }}');
|
||||
const personaSelect = document.querySelector('select[name="persona"]');
|
||||
|
||||
@ -406,22 +405,6 @@
|
||||
return document.querySelector(`.plugin-section-toggle[value="${requiredSearchPlugin}"]`);
|
||||
}
|
||||
|
||||
function getPluginCheckbox(pluginName) {
|
||||
if (!pluginName) return null;
|
||||
return document.querySelector(`.plugin-section-toggle[value="${pluginName}"]`);
|
||||
}
|
||||
|
||||
function getRequiredPlugins(pluginName) {
|
||||
const requiredPlugins = pluginDependencyMap[pluginName];
|
||||
return Array.isArray(requiredPlugins) ? requiredPlugins : [];
|
||||
}
|
||||
|
||||
function getDependentPlugins(pluginName) {
|
||||
return Object.entries(pluginDependencyMap)
|
||||
.filter(([, requiredPlugins]) => Array.isArray(requiredPlugins) && requiredPlugins.includes(pluginName))
|
||||
.map(([dependentPlugin]) => dependentPlugin);
|
||||
}
|
||||
|
||||
function getConfigEditorRows() {
|
||||
return document.getElementById('id_config_rows');
|
||||
}
|
||||
@ -557,47 +540,6 @@
|
||||
updateURLPreview();
|
||||
}
|
||||
|
||||
function ensureRequiredPluginsChecked(pluginName, visited = new Set()) {
|
||||
if (!pluginName || visited.has(pluginName)) {
|
||||
return;
|
||||
}
|
||||
visited.add(pluginName);
|
||||
|
||||
getRequiredPlugins(pluginName).forEach(requiredPlugin => {
|
||||
const requiredCheckbox = getPluginCheckbox(requiredPlugin);
|
||||
if (!requiredCheckbox) {
|
||||
return;
|
||||
}
|
||||
requiredCheckbox.checked = true;
|
||||
dispatchChange(requiredCheckbox);
|
||||
ensureRequiredPluginsChecked(requiredPlugin, visited);
|
||||
});
|
||||
}
|
||||
|
||||
function uncheckDependentPlugins(pluginName, visited = new Set()) {
|
||||
if (!pluginName || visited.has(pluginName)) {
|
||||
return;
|
||||
}
|
||||
visited.add(pluginName);
|
||||
|
||||
getDependentPlugins(pluginName).forEach(dependentPlugin => {
|
||||
const dependentCheckbox = getPluginCheckbox(dependentPlugin);
|
||||
if (!dependentCheckbox) {
|
||||
return;
|
||||
}
|
||||
dependentCheckbox.checked = false;
|
||||
dispatchChange(dependentCheckbox);
|
||||
uncheckDependentPlugins(dependentPlugin, visited);
|
||||
});
|
||||
}
|
||||
|
||||
function normalizePluginSelections() {
|
||||
const checkedPlugins = Array.from(document.querySelectorAll('.plugin-section-toggle:checked'))
|
||||
.map(cb => cb.value)
|
||||
.filter(Boolean);
|
||||
checkedPlugins.forEach(pluginName => ensureRequiredPluginsChecked(pluginName));
|
||||
}
|
||||
|
||||
function applyRequiredSearchPlugin(preferredValue = undefined) {
|
||||
const requiredCheckbox = getRequiredSearchCheckbox();
|
||||
if (!requiredCheckbox) return;
|
||||
@ -1247,7 +1189,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
normalizePluginSelections();
|
||||
applyRequiredSearchPlugin(requiredSearchPreference);
|
||||
syncEnabledPluginsConfig();
|
||||
updateChromeToggleButton();
|
||||
@ -1281,7 +1222,6 @@
|
||||
dispatchChange(cb);
|
||||
});
|
||||
|
||||
normalizePluginSelections();
|
||||
applyRequiredSearchPlugin(requiredSearchPreference);
|
||||
syncEnabledPluginsConfig();
|
||||
updateChromeToggleButton();
|
||||
@ -1291,11 +1231,6 @@
|
||||
|
||||
document.querySelectorAll('.plugin-section-toggle').forEach(checkbox => {
|
||||
checkbox.addEventListener('change', function() {
|
||||
if (this.checked) {
|
||||
ensureRequiredPluginsChecked(this.value);
|
||||
} else {
|
||||
uncheckDependentPlugins(this.value);
|
||||
}
|
||||
syncEnabledPluginsConfig();
|
||||
updateChromeToggleButton();
|
||||
saveFormState();
|
||||
@ -1350,7 +1285,6 @@
|
||||
if (personaSelect) {
|
||||
applyPersonaConfig(personaSelect.value);
|
||||
}
|
||||
normalizePluginSelections();
|
||||
applyRequiredSearchPlugin();
|
||||
syncEnabledPluginsConfig();
|
||||
updateChromeToggleButton();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user