mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-14 15:31:30 +00:00
Compare commits
70 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e10bf89d6d | ||
|
|
23431d3d31 | ||
|
|
3431320d03 | ||
|
|
2ae433a74d | ||
|
|
a6ef9a58ec | ||
|
|
112e962239 | ||
|
|
47ab18175f | ||
|
|
7d27bff062 | ||
|
|
f3f93a8205 | ||
|
|
65a6f46369 | ||
|
|
cb669ad4ec | ||
|
|
2e8ab8190a | ||
|
|
98c978ff1b | ||
|
|
38779740ec | ||
|
|
9c6f9a25c5 | ||
|
|
28fc2a5a2c | ||
|
|
71fbbddbbe | ||
|
|
b50617bd10 | ||
|
|
6045b50af2 | ||
|
|
3ef4a83f4a | ||
|
|
2a6f6f4ed5 | ||
|
|
19d138632a | ||
|
|
83074a2403 | ||
|
|
1d1e3008aa | ||
|
|
ce2b7d11a9 | ||
|
|
0ddf4f903e | ||
|
|
673d5b5e83 | ||
|
|
d346708150 | ||
|
|
91bf8371ad | ||
|
|
3c9866e90d | ||
|
|
fcd598286a | ||
|
|
c09fc7d483 | ||
|
|
54cb43d235 | ||
|
|
b7cfdc3100 | ||
|
|
45ed095509 | ||
|
|
801e23e63b | ||
|
|
a15a5efdce | ||
|
|
21bad81262 | ||
|
|
db86b8c330 | ||
|
|
9c317db260 | ||
|
|
e437bb0b7b | ||
|
|
889aa08b4e | ||
|
|
aac5b8e0be | ||
|
|
a2b9ee764d | ||
|
|
e77b67445c | ||
|
|
fe4dc1f1e4 | ||
|
|
4137bde194 | ||
|
|
f13413a104 | ||
|
|
e576ded86b | ||
|
|
4cbb167e5c | ||
|
|
4f67f21b33 | ||
|
|
cf34de6772 | ||
|
|
5edcc60d41 | ||
|
|
ad096aa6ff | ||
|
|
0ca5a41298 | ||
|
|
7117926584 | ||
|
|
4a45b5d5a9 | ||
|
|
4dbd92ac4d | ||
|
|
af98fc1079 | ||
|
|
368dd14785 | ||
|
|
9d389309fc | ||
|
|
67cb6fb8a2 | ||
|
|
25ced0d660 | ||
|
|
18bf07b19f | ||
|
|
c9d2044949 | ||
|
|
2631ff4bee | ||
|
|
c0017d29a7 | ||
|
|
9cf16248e6 | ||
|
|
90d327fdaa | ||
|
|
6330b71bfb |
135 changed files with 12676 additions and 3924 deletions
14
.env
14
.env
|
|
@ -76,6 +76,12 @@ DISABLE_BACKUP_RESTORE=1
|
|||
# When enabled, users must confirm their password before downloading.
|
||||
DISABLE_BACKUP_DOWNLOAD=1
|
||||
|
||||
# Watchtower integration for Docker-based updates.
|
||||
# Set these to enable one-click updates via the Update Manager UI.
|
||||
# See https://containrrr.dev/watchtower/ for Watchtower setup.
|
||||
WATCHTOWER_API_URL=
|
||||
WATCHTOWER_API_TOKEN=
|
||||
|
||||
###################################################################################
|
||||
# SAML Single sign on-settings
|
||||
###################################################################################
|
||||
|
|
@ -155,3 +161,11 @@ APP_ENV=prod
|
|||
APP_SECRET=a03498528f5a5fc089273ec9ae5b2849
|
||||
APP_SHARE_DIR=var/share
|
||||
###< symfony/framework-bundle ###
|
||||
|
||||
###> symfony/ai-generic-platform ###
|
||||
# GENERIC_BASE_URL=https://api.example.com/v1
|
||||
###< symfony/ai-generic-platform ###
|
||||
|
||||
###> symfony/ai-open-router-platform ###
|
||||
OPENROUTER_API_KEY=
|
||||
###< symfony/ai-open-router-platform ###
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
[](https://scrutinizer-ci.com/g/Part-DB/Part-DB-symfony/?branch=master)
|
||||

|
||||

|
||||
[](https://codecov.io/gh/Part-DB/Part-DB-server)
|
||||
|
|
@ -62,6 +61,7 @@ for the first time.
|
|||
* Automatic thumbnail generation for pictures
|
||||
* Use cloud providers (like Octopart, Digikey, Farnell, LCSC or TME) to automatically get part information, datasheets, and
|
||||
prices for parts
|
||||
* Retrieve part information from arbitrary shop websites, using either conventional data extraction from structured metadata, or AI based data extraction
|
||||
* API to access Part-DB from other applications/scripts
|
||||
* [Integration with KiCad](https://docs.part-db.de/usage/eda_integration.html): Use Part-DB as the central datasource for your
|
||||
KiCad and see available parts from Part-DB directly inside KiCad.
|
||||
|
|
|
|||
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
|||
2.10.0
|
||||
2.11.1
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ export default class extends Controller {
|
|||
researchAllUrl: String,
|
||||
markCompletedUrl: String,
|
||||
markSkippedUrl: String,
|
||||
markPendingUrl: String
|
||||
markPendingUrl: String,
|
||||
quickApplyUrl: String,
|
||||
quickApplyAllUrl: String
|
||||
}
|
||||
|
||||
connect() {
|
||||
|
|
@ -119,13 +121,11 @@ export default class extends Controller {
|
|||
|
||||
async markSkipped(event) {
|
||||
const partId = event.currentTarget.dataset.partId
|
||||
const reason = prompt('Reason for skipping (optional):') || ''
|
||||
|
||||
try {
|
||||
const url = this.markSkippedUrlValue.replace('__PART_ID__', partId)
|
||||
const data = await this.fetchWithErrorHandling(url, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ reason })
|
||||
method: 'POST'
|
||||
})
|
||||
|
||||
if (data.success) {
|
||||
|
|
@ -321,6 +321,94 @@ export default class extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
async quickApply(event) {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
|
||||
const partId = event.currentTarget.dataset.partId
|
||||
const providerKey = event.currentTarget.dataset.providerKey
|
||||
const providerId = event.currentTarget.dataset.providerId
|
||||
const button = event.currentTarget
|
||||
const originalHtml = button.innerHTML
|
||||
|
||||
button.disabled = true
|
||||
button.innerHTML = '<span class="spinner-border spinner-border-sm"></span> Applying...'
|
||||
|
||||
try {
|
||||
const url = this.quickApplyUrlValue.replace('__PART_ID__', partId)
|
||||
const data = await this.fetchWithErrorHandling(url, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ providerKey, providerId })
|
||||
}, 60000)
|
||||
|
||||
if (data.success) {
|
||||
this.updateProgressDisplay(data)
|
||||
this.showSuccessMessage(data.message || 'Part updated successfully')
|
||||
sessionStorage.setItem('bulkImportScrollPosition', window.scrollY.toString())
|
||||
window.location.reload()
|
||||
} else {
|
||||
this.showErrorMessage(data.error || 'Quick apply failed')
|
||||
button.innerHTML = originalHtml
|
||||
button.disabled = false
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in quick apply:', error)
|
||||
this.showErrorMessage(error.message || 'Quick apply failed')
|
||||
button.innerHTML = originalHtml
|
||||
button.disabled = false
|
||||
}
|
||||
}
|
||||
|
||||
async quickApplyAll(event) {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
|
||||
if (!confirm('This will apply the top search result to all pending parts without individual review. Continue?')) {
|
||||
return
|
||||
}
|
||||
|
||||
const button = event.currentTarget
|
||||
const spinner = document.getElementById('quick-apply-all-spinner')
|
||||
const originalHtml = button.innerHTML
|
||||
|
||||
button.disabled = true
|
||||
if (spinner) {
|
||||
spinner.style.display = 'inline-block'
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await this.fetchWithErrorHandling(this.quickApplyAllUrlValue, {
|
||||
method: 'POST'
|
||||
}, 300000)
|
||||
|
||||
if (data.success) {
|
||||
this.updateProgressDisplay(data)
|
||||
|
||||
let message = data.message || 'Bulk apply completed'
|
||||
if (data.errors && data.errors.length > 0) {
|
||||
message += '\nErrors:\n' + data.errors.join('\n')
|
||||
}
|
||||
|
||||
this.showSuccessMessage(message)
|
||||
sessionStorage.setItem('bulkImportScrollPosition', window.scrollY.toString())
|
||||
window.location.reload()
|
||||
} else {
|
||||
this.showErrorMessage(data.error || 'Bulk apply failed')
|
||||
button.innerHTML = originalHtml
|
||||
button.disabled = false
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in quick apply all:', error)
|
||||
this.showErrorMessage(error.message || 'Bulk apply failed')
|
||||
button.innerHTML = originalHtml
|
||||
button.disabled = false
|
||||
} finally {
|
||||
if (spinner) {
|
||||
spinner.style.display = 'none'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
showSuccessMessage(message) {
|
||||
this.showToast('success', message)
|
||||
}
|
||||
|
|
|
|||
377
assets/controllers/docker_update_progress_controller.js
Normal file
377
assets/controllers/docker_update_progress_controller.js
Normal file
|
|
@ -0,0 +1,377 @@
|
|||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
/**
|
||||
* Stimulus controller for Docker update progress tracking.
|
||||
*
|
||||
* Polls the health check endpoint to detect when the container restarts
|
||||
* after a Watchtower-triggered update. Drives the step timeline UI
|
||||
* with timestamps, matching the git update progress style.
|
||||
*/
|
||||
export default class extends Controller {
|
||||
static values = {
|
||||
healthUrl: String,
|
||||
previousVersion: { type: String, default: 'unknown' },
|
||||
pollInterval: { type: Number, default: 5000 },
|
||||
maxWaitTime: { type: Number, default: 600000 }, // 10 minutes
|
||||
// Translated UI strings (passed from Twig template)
|
||||
textPulling: { type: String, default: 'Waiting for Watchtower to pull the new image...' },
|
||||
textPullingDetail: { type: String, default: 'Watchtower is checking for and downloading the latest Docker image...' },
|
||||
textRestarting: { type: String, default: 'Container is restarting with the new image...' },
|
||||
textRestartingDetail: { type: String, default: 'The container is being recreated with the updated image. This may take a moment...' },
|
||||
textSuccess: { type: String, default: 'Update Complete!' },
|
||||
textSuccessDetail: { type: String, default: 'Part-DB has been updated successfully via Docker.' },
|
||||
textTimeout: { type: String, default: 'Update Taking Longer Than Expected' },
|
||||
textTimeoutDetail: { type: String, default: 'The update may still be in progress. Check your Docker logs for details.' },
|
||||
textStepPull: { type: String, default: 'Pull Image' },
|
||||
textStepRestart: { type: String, default: 'Restart Container' },
|
||||
};
|
||||
|
||||
static targets = [
|
||||
// Header
|
||||
'headerWhale', 'titleIcon',
|
||||
'statusText', 'statusSubtext',
|
||||
'progressBar', 'elapsedTime',
|
||||
// Alerts
|
||||
'stepAlert', 'stepName', 'stepMessage',
|
||||
'successAlert', 'timeoutAlert', 'errorAlert', 'errorMessage', 'warningAlert',
|
||||
// Step timeline (multi-target arrays)
|
||||
'stepRow', 'stepIcon', 'stepDetail', 'stepTime',
|
||||
// Version display
|
||||
'newVersion', 'previousVersion',
|
||||
// Actions
|
||||
'actions',
|
||||
];
|
||||
|
||||
// Step definitions: name -> { index, progress% }
|
||||
static STEPS = {
|
||||
trigger: { index: 0, progress: 15 },
|
||||
pull: { index: 1, progress: 30 },
|
||||
stop: { index: 2, progress: 50 },
|
||||
restart: { index: 3, progress: 65 },
|
||||
health: { index: 4, progress: 80 },
|
||||
verify: { index: 5, progress: 100 },
|
||||
};
|
||||
|
||||
connect() {
|
||||
this.serverWentDown = false;
|
||||
this.serverCameBack = false;
|
||||
this.startTime = Date.now();
|
||||
this.timer = null;
|
||||
this.currentStep = 'pull'; // trigger is already done
|
||||
this.stepTimestamps = { trigger: this.formatTime(new Date()) };
|
||||
this.consecutiveSuccessCount = 0;
|
||||
|
||||
// Set the trigger step timestamp
|
||||
this.setStepTimestamp(0, this.stepTimestamps.trigger);
|
||||
|
||||
this.poll();
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
if (this.timer) {
|
||||
clearTimeout(this.timer);
|
||||
}
|
||||
}
|
||||
|
||||
createTimeoutSignal(ms) {
|
||||
if (typeof AbortSignal.timeout === 'function') {
|
||||
return AbortSignal.timeout(ms);
|
||||
}
|
||||
const controller = new AbortController();
|
||||
setTimeout(() => controller.abort(), ms);
|
||||
return controller.signal;
|
||||
}
|
||||
|
||||
async poll() {
|
||||
const elapsed = Date.now() - this.startTime;
|
||||
this.updateElapsedTime(elapsed);
|
||||
|
||||
if (elapsed > this.maxWaitTimeValue) {
|
||||
this.showTimeout();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(this.healthUrlValue, {
|
||||
cache: 'no-store',
|
||||
signal: this.createTimeoutSignal(4000),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
let data;
|
||||
try {
|
||||
data = await response.json();
|
||||
} catch (parseError) {
|
||||
this.schedulePoll();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.serverWentDown) {
|
||||
// Server came back! Move through health check -> verify
|
||||
if (!this.serverCameBack) {
|
||||
this.serverCameBack = true;
|
||||
this.advanceToStep('health');
|
||||
}
|
||||
|
||||
this.consecutiveSuccessCount++;
|
||||
|
||||
// Wait for 2 consecutive successes to confirm stability
|
||||
if (this.consecutiveSuccessCount >= 2) {
|
||||
this.showSuccess(data.version);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Server still up - Watchtower pulling image
|
||||
this.showPulling();
|
||||
}
|
||||
} else if (response.status === 503) {
|
||||
// Maintenance mode or shutting down
|
||||
this.serverWentDown = true;
|
||||
this.consecutiveSuccessCount = 0;
|
||||
this.advanceToStep('stop');
|
||||
} else {
|
||||
if (this.serverWentDown) {
|
||||
this.showRestarting();
|
||||
} else {
|
||||
this.showPulling();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Connection refused = container is down
|
||||
if (!this.serverWentDown) {
|
||||
this.serverWentDown = true;
|
||||
this.advanceToStep('stop');
|
||||
}
|
||||
this.consecutiveSuccessCount = 0;
|
||||
this.showRestarting();
|
||||
}
|
||||
|
||||
this.schedulePoll();
|
||||
}
|
||||
|
||||
schedulePoll() {
|
||||
this.timer = setTimeout(() => this.poll(), this.pollIntervalValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Advance the step timeline to a specific step.
|
||||
* Marks all previous steps as complete with timestamps.
|
||||
*/
|
||||
advanceToStep(stepName) {
|
||||
const steps = this.constructor.STEPS;
|
||||
const targetIndex = steps[stepName]?.index;
|
||||
if (targetIndex === undefined) return;
|
||||
|
||||
const stepNames = Object.keys(steps);
|
||||
const now = this.formatTime(new Date());
|
||||
|
||||
for (let i = 0; i < stepNames.length; i++) {
|
||||
const name = stepNames[i];
|
||||
|
||||
if (i < targetIndex) {
|
||||
// Completed step
|
||||
this.markStepComplete(i, this.stepTimestamps[name] || now);
|
||||
if (!this.stepTimestamps[name]) {
|
||||
this.stepTimestamps[name] = now;
|
||||
}
|
||||
} else if (i === targetIndex) {
|
||||
// Current active step
|
||||
this.markStepActive(i);
|
||||
this.stepTimestamps[name] = now;
|
||||
this.setStepTimestamp(i, now);
|
||||
this.currentStep = name;
|
||||
}
|
||||
// Steps after targetIndex remain pending (no change needed)
|
||||
}
|
||||
|
||||
// Update progress bar
|
||||
this.updateProgressBar(steps[stepName].progress);
|
||||
}
|
||||
|
||||
showPulling() {
|
||||
if (this.hasStatusTextTarget) {
|
||||
this.statusTextTarget.textContent = this.textPullingValue;
|
||||
}
|
||||
if (this.hasStepNameTarget) {
|
||||
this.stepNameTarget.textContent = this.textStepPullValue;
|
||||
}
|
||||
if (this.hasStepMessageTarget) {
|
||||
this.stepMessageTarget.textContent = this.textPullingDetailValue;
|
||||
}
|
||||
this.updateProgressBar(30);
|
||||
}
|
||||
|
||||
showRestarting() {
|
||||
// Advance to restart step if we haven't already
|
||||
if (this.currentStep !== 'restart' && this.currentStep !== 'health' && this.currentStep !== 'verify') {
|
||||
this.advanceToStep('restart');
|
||||
}
|
||||
|
||||
if (this.hasStatusTextTarget) {
|
||||
this.statusTextTarget.textContent = this.textRestartingValue;
|
||||
}
|
||||
if (this.hasStepNameTarget) {
|
||||
this.stepNameTarget.textContent = this.textStepRestartValue;
|
||||
}
|
||||
if (this.hasStepMessageTarget) {
|
||||
this.stepMessageTarget.textContent = this.textRestartingDetailValue;
|
||||
}
|
||||
}
|
||||
|
||||
showSuccess(newVersion) {
|
||||
// Advance all steps to complete
|
||||
const steps = this.constructor.STEPS;
|
||||
const stepNames = Object.keys(steps);
|
||||
const now = this.formatTime(new Date());
|
||||
|
||||
for (let i = 0; i < stepNames.length; i++) {
|
||||
const name = stepNames[i];
|
||||
this.markStepComplete(i, this.stepTimestamps[name] || now);
|
||||
}
|
||||
|
||||
this.updateProgressBar(100);
|
||||
|
||||
// Update whale animation
|
||||
if (this.hasHeaderWhaleTarget) {
|
||||
this.headerWhaleTarget.classList.add('success');
|
||||
}
|
||||
if (this.hasTitleIconTarget) {
|
||||
this.titleIconTarget.className = 'fas fa-check-circle text-success';
|
||||
}
|
||||
|
||||
if (this.hasStatusTextTarget) {
|
||||
this.statusTextTarget.textContent = this.textSuccessValue;
|
||||
}
|
||||
if (this.hasStatusSubtextTarget) {
|
||||
this.statusSubtextTarget.textContent = this.textSuccessDetailValue;
|
||||
}
|
||||
|
||||
// Hide step alert, show success alert
|
||||
this.toggleTarget('stepAlert', false);
|
||||
this.toggleTarget('successAlert', true);
|
||||
this.toggleTarget('warningAlert', false);
|
||||
this.toggleTarget('actions', true);
|
||||
|
||||
if (this.hasNewVersionTarget) {
|
||||
this.newVersionTarget.textContent = newVersion || 'latest';
|
||||
}
|
||||
if (this.hasPreviousVersionTarget) {
|
||||
this.previousVersionTarget.textContent = this.previousVersionValue;
|
||||
}
|
||||
}
|
||||
|
||||
showTimeout() {
|
||||
this.updateProgressBar(0);
|
||||
|
||||
if (this.hasHeaderWhaleTarget) {
|
||||
this.headerWhaleTarget.classList.add('timeout');
|
||||
}
|
||||
if (this.hasTitleIconTarget) {
|
||||
this.titleIconTarget.className = 'fas fa-exclamation-triangle text-warning';
|
||||
}
|
||||
|
||||
if (this.hasStatusTextTarget) {
|
||||
this.statusTextTarget.textContent = this.textTimeoutValue;
|
||||
}
|
||||
if (this.hasStatusSubtextTarget) {
|
||||
this.statusSubtextTarget.textContent = this.textTimeoutDetailValue;
|
||||
}
|
||||
|
||||
this.toggleTarget('stepAlert', false);
|
||||
this.toggleTarget('timeoutAlert', true);
|
||||
this.toggleTarget('warningAlert', false);
|
||||
this.toggleTarget('actions', true);
|
||||
}
|
||||
|
||||
// --- Step timeline helpers ---
|
||||
|
||||
markStepComplete(index, timestamp) {
|
||||
if (this.stepIconTargets[index]) {
|
||||
this.stepIconTargets[index].className = 'fas fa-check-circle text-success me-3';
|
||||
}
|
||||
if (this.stepRowTargets[index]) {
|
||||
this.stepRowTargets[index].classList.remove('text-muted');
|
||||
}
|
||||
if (timestamp) {
|
||||
this.setStepTimestamp(index, timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
markStepActive(index) {
|
||||
if (this.stepIconTargets[index]) {
|
||||
this.stepIconTargets[index].className = 'fas fa-spinner fa-spin text-primary me-3';
|
||||
}
|
||||
if (this.stepRowTargets[index]) {
|
||||
this.stepRowTargets[index].classList.remove('text-muted');
|
||||
}
|
||||
}
|
||||
|
||||
setStepTimestamp(index, time) {
|
||||
if (this.stepTimeTargets[index]) {
|
||||
this.stepTimeTargets[index].textContent = time;
|
||||
}
|
||||
}
|
||||
|
||||
// --- UI helpers ---
|
||||
|
||||
toggleTarget(name, show) {
|
||||
const hasMethod = 'has' + name.charAt(0).toUpperCase() + name.slice(1) + 'Target';
|
||||
if (this[hasMethod]) {
|
||||
this[name + 'Target'].classList.toggle('d-none', !show);
|
||||
}
|
||||
}
|
||||
|
||||
updateProgressBar(percent) {
|
||||
if (this.hasProgressBarTarget) {
|
||||
const bar = this.progressBarTarget;
|
||||
// Remove all width classes
|
||||
bar.classList.remove('progress-w-0', 'progress-w-15', 'progress-w-30', 'progress-w-50', 'progress-w-65', 'progress-w-80', 'progress-w-100');
|
||||
bar.classList.add('progress-w-' + percent);
|
||||
bar.textContent = percent + '%';
|
||||
bar.setAttribute('aria-valuenow', percent);
|
||||
|
||||
bar.classList.remove('bg-success', 'bg-danger', 'progress-bar-striped', 'progress-bar-animated');
|
||||
if (percent === 100) {
|
||||
bar.classList.add('bg-success');
|
||||
} else if (percent === 0) {
|
||||
bar.classList.add('bg-danger');
|
||||
} else {
|
||||
bar.classList.add('progress-bar-striped', 'progress-bar-animated');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateElapsedTime(elapsed) {
|
||||
if (this.hasElapsedTimeTarget) {
|
||||
const seconds = Math.floor(elapsed / 1000);
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const remainingSeconds = seconds % 60;
|
||||
this.elapsedTimeTarget.textContent = minutes > 0
|
||||
? `${minutes}m ${remainingSeconds}s`
|
||||
: `${remainingSeconds}s`;
|
||||
}
|
||||
}
|
||||
|
||||
formatTime(date) {
|
||||
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
||||
}
|
||||
}
|
||||
152
assets/controllers/elements/ai_model_autocomplete_controller.js
Normal file
152
assets/controllers/elements/ai_model_autocomplete_controller.js
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {Controller} from "@hotwired/stimulus";
|
||||
|
||||
import "tom-select/dist/css/tom-select.bootstrap5.css";
|
||||
import '../../css/components/tom-select_extensions.css';
|
||||
import TomSelect from "tom-select";
|
||||
|
||||
import TomSelect_click_to_edit from '../../tomselect/click_to_edit/click_to_edit'
|
||||
import TomSelect_autoselect_typed from '../../tomselect/autoselect_typed/autoselect_typed'
|
||||
|
||||
TomSelect.define('click_to_edit', TomSelect_click_to_edit)
|
||||
TomSelect.define('autoselect_typed', TomSelect_autoselect_typed)
|
||||
|
||||
export default class extends Controller {
|
||||
_tomSelect;
|
||||
|
||||
_platformSelector;
|
||||
|
||||
connect() {
|
||||
|
||||
let dropdownParent = "body";
|
||||
if (this.element.closest('.modal')) {
|
||||
dropdownParent = null
|
||||
}
|
||||
|
||||
//Try to find the platform selector
|
||||
const platformSelector = document.querySelector("select[data-platform-selector-label='" + this.element.dataset.platformSelector + "']");
|
||||
//Clear tomselect options, if the platform selector changes
|
||||
if (platformSelector) {
|
||||
this.platformSelector = platformSelector;
|
||||
platformSelector.addEventListener('change', () => {
|
||||
//Force reload of options by clearing the cache and options of TomSelect and triggering a search with an empty string
|
||||
this._tomSelect.clearOptions();
|
||||
this._tomSelect.clearCache();
|
||||
this._tomSelect.load('');
|
||||
});
|
||||
}
|
||||
|
||||
let settings = {
|
||||
persistent: false,
|
||||
create: true,
|
||||
maxItems: 1,
|
||||
preload: 'focus',
|
||||
createOnBlur: true,
|
||||
selectOnTab: true,
|
||||
clearAfterSelect: true,
|
||||
shouldLoad: ((query) => true),
|
||||
maxOptions: null,
|
||||
//This a an ugly solution to disable the delimiter parsing of the TomSelect plugin
|
||||
delimiter: 'VERY_L0NG_D€LIMITER_WHICH_WILL_NEVER_BE_ENCOUNTERED_IN_A_STRING',
|
||||
dropdownParent: dropdownParent,
|
||||
render: {
|
||||
item: (data, escape) => {
|
||||
return '<span>' + escape(data.label) + '</span>';
|
||||
},
|
||||
option: (data, escape) => {
|
||||
if (data.image) {
|
||||
return "<div class='row m-0'><div class='col-2 pl-0 pr-1'><img class='typeahead-image' src='" + data.image + "'/></div><div class='col-10'>" + data.label + "</div></div>"
|
||||
}
|
||||
return '<div>' + escape(data.label) + '</div>';
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
'autoselect_typed': {},
|
||||
'click_to_edit': {},
|
||||
'clear_button': {},
|
||||
"restore_on_backspace": {}
|
||||
}
|
||||
};
|
||||
|
||||
if(this.element.dataset.urlTemplate) {
|
||||
const base_url = this.element.dataset.urlTemplate;
|
||||
settings.searchField = "label";
|
||||
settings.sortField = "label";
|
||||
settings.valueField = "label";
|
||||
settings.load = (query, callback) => {
|
||||
|
||||
|
||||
if (!this.platformSelector) {
|
||||
console.error("Platform selector not found for AI model autocomplete");
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
//Platform is the selected option
|
||||
const platform = this.platformSelector.value;
|
||||
if (!platform) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
const self = this;
|
||||
|
||||
//Only fetch each platform once
|
||||
if(self.platformLoaded === platform) {
|
||||
callback();
|
||||
}
|
||||
|
||||
|
||||
const url = base_url.replace('__PLATFORM__', encodeURIComponent(platform));
|
||||
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
|
||||
self.platformLoaded = platform;
|
||||
|
||||
var data = [];
|
||||
|
||||
for (const name in json) {
|
||||
data.push({
|
||||
"label": name,
|
||||
"capabilities": json[name].capabilities,
|
||||
});
|
||||
}
|
||||
|
||||
callback(data);
|
||||
}).catch(()=>{
|
||||
callback();
|
||||
});
|
||||
};
|
||||
}
|
||||
this._tomSelect = new TomSelect(this.element, settings);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
super.disconnect();
|
||||
//Destroy the TomSelect instance
|
||||
this._tomSelect.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ import "ckeditor5/ckeditor5.css";;
|
|||
import "../../css/components/ckeditor.css";
|
||||
|
||||
const translationContext = require.context(
|
||||
'ckeditor5/translations',
|
||||
'ckeditor5-translations', //Alias defined in webpack.config.js
|
||||
false,
|
||||
//Only load the translation files we will really need
|
||||
/(de|it|fr|ru|ja|cs|da|zh|pl|hu)\.js$/
|
||||
|
|
|
|||
|
|
@ -83,8 +83,6 @@ export default class extends Controller {
|
|||
if (data) {
|
||||
//Do not save the start value (current page), as we want to always start at the first page on a page reload
|
||||
delete data.start;
|
||||
//Reset the data length to the default value by deleting the length property
|
||||
delete data.length;
|
||||
}
|
||||
|
||||
return data;
|
||||
|
|
@ -113,8 +111,16 @@ export default class extends Controller {
|
|||
return null;
|
||||
}
|
||||
|
||||
//The saved order index is visual (post-reorder). If colReorder state
|
||||
//exists, map it back to the original column index so the server sorts
|
||||
//the correct column. colReorder[visualIndex] == originalIndex.
|
||||
let columnIndex = order[0];
|
||||
if (saved_state.colReorder) {
|
||||
columnIndex = saved_state.colReorder[columnIndex];
|
||||
}
|
||||
|
||||
return {
|
||||
column: order[0],
|
||||
column: columnIndex,
|
||||
dir: order[1]
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -70,6 +70,13 @@ export default class extends Controller {
|
|||
newFieldSelect.addEventListener('change', this.updateFieldOptions.bind(this))
|
||||
}
|
||||
|
||||
// Auto-increment priority based on existing mappings
|
||||
const nextPriority = this.getNextPriority()
|
||||
const priorityInput = newRow.querySelector('input[name*="[priority]"]')
|
||||
if (priorityInput) {
|
||||
priorityInput.value = nextPriority
|
||||
}
|
||||
|
||||
this.updateFieldOptions()
|
||||
this.updateAddButtonState()
|
||||
}
|
||||
|
|
@ -119,6 +126,18 @@ export default class extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
getNextPriority() {
|
||||
const priorityInputs = this.tbodyTarget.querySelectorAll('input[name*="[priority]"]')
|
||||
let maxPriority = 0
|
||||
priorityInputs.forEach(input => {
|
||||
const val = parseInt(input.value, 10)
|
||||
if (!isNaN(val) && val > maxPriority) {
|
||||
maxPriority = val
|
||||
}
|
||||
})
|
||||
return Math.min(maxPriority + 1, 10)
|
||||
}
|
||||
|
||||
handleFormSubmit(event) {
|
||||
if (this.hasSubmitButtonTarget) {
|
||||
this.submitButtonTarget.disabled = true
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
"jbtronics/dompdf-font-loader-bundle": "^1.0.0",
|
||||
"jbtronics/settings-bundle": "^3.0.0",
|
||||
"jfcherng/php-diff": "^6.14",
|
||||
"jkphl/micrometa": "^v3.4.0",
|
||||
"knpuniversity/oauth2-client-bundle": "^2.15",
|
||||
"league/commonmark": "^2.7",
|
||||
"league/csv": "^9.8.0",
|
||||
|
|
@ -56,6 +57,9 @@
|
|||
"scheb/2fa-trusted-device": "^v7.11.0",
|
||||
"shivas/versioning-bundle": "^4.0",
|
||||
"spatie/db-dumper": "^3.3.1",
|
||||
"symfony/ai-bundle": "^0.8.0",
|
||||
"symfony/ai-lm-studio-platform": "^0.8.0",
|
||||
"symfony/ai-open-router-platform": "^0.8.0",
|
||||
"symfony/apache-pack": "^1.0",
|
||||
"symfony/asset": "7.4.*",
|
||||
"symfony/console": "7.4.*",
|
||||
|
|
|
|||
2121
composer.lock
generated
2121
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -33,4 +33,5 @@ return [
|
|||
Jbtronics\SettingsBundle\JbtronicsSettingsBundle::class => ['all' => true],
|
||||
Jbtronics\TranslationEditorBundle\JbtronicsTranslationEditorBundle::class => ['dev' => true],
|
||||
ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
|
||||
Symfony\AI\AiBundle\AiBundle::class => ['all' => true],
|
||||
];
|
||||
|
|
|
|||
27
config/packages/ai.yaml
Normal file
27
config/packages/ai.yaml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
ai:
|
||||
platform:
|
||||
# Inference Platform configuration
|
||||
# see https://github.com/symfony/ai/tree/main/src/platform#platform-bridges
|
||||
|
||||
# openai:
|
||||
# api_key: '%env(OPENAI_API_KEY)%'
|
||||
|
||||
agent:
|
||||
# Agent configuration
|
||||
# see https://symfony.com/doc/current/ai/bundles/ai-bundle.html
|
||||
|
||||
# default:
|
||||
# platform: 'ai.platform.openai'
|
||||
# model: 'gpt-5-mini'
|
||||
# prompt: |
|
||||
# You are a pirate and you write funny.
|
||||
# tools:
|
||||
# - 'Symfony\AI\Agent\Bridge\Clock\Clock'
|
||||
|
||||
store:
|
||||
# Store configuration
|
||||
|
||||
# chromadb:
|
||||
# default:
|
||||
# client: 'client.service.id'
|
||||
# collection: 'my_collection'
|
||||
5
config/packages/ai_generic_platform.yaml
Normal file
5
config/packages/ai_generic_platform.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
ai:
|
||||
platform:
|
||||
generic:
|
||||
default:
|
||||
base_url: '%env(GENERIC_BASE_URL)%'
|
||||
4
config/packages/ai_lm_studio_platform.yaml
Normal file
4
config/packages/ai_lm_studio_platform.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
ai:
|
||||
platform:
|
||||
lmstudio:
|
||||
host_url: '%env(string:settings:ai_lmstudio:hostURL)%'
|
||||
4
config/packages/ai_open_router_platform.yaml
Normal file
4
config/packages/ai_open_router_platform.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
ai:
|
||||
platform:
|
||||
openrouter:
|
||||
api_key: '%env(string:settings:ai_openrouter:apiKey)%'
|
||||
|
|
@ -8,7 +8,7 @@ datatables:
|
|||
|
||||
# Set options, as documented at https://datatables.net/reference/option/
|
||||
options:
|
||||
lengthMenu : [[10, 25, 50, 100], [10, 25, 50, 100]] # We add the "All" option, when part tables are generated
|
||||
lengthMenu : [[10, 25, 50, 100, 250, 500], [10, 25, 50, 100, 250, 500]] # We add the "All" option, when part tables are generated
|
||||
#pageLength: '%partdb.table.default_page_size%' # Set to -1 to disable pagination (i.e. show all rows) by default
|
||||
pageLength: 50 #TODO
|
||||
dom: " <'row' <'col mb-2 input-group flex-nowrap' B l > <'col-auto mb-2' < p >>>
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* @psalm-type FrameworkConfig = array{
|
||||
* secret?: scalar|Param|null,
|
||||
* http_method_override?: bool|Param, // Set true to enable support for the '_method' request parameter to determine the intended HTTP method on POST requests. // Default: false
|
||||
* allowed_http_method_override?: list<string|Param>|null,
|
||||
* allowed_http_method_override?: null|list<string|Param>,
|
||||
* trust_x_sendfile_type_header?: scalar|Param|null, // Set true to enable support for xsendfile in binary file responses. // Default: "%env(bool:default::SYMFONY_TRUST_X_SENDFILE_TYPE_HEADER)%"
|
||||
* ide?: scalar|Param|null, // Default: "%env(default::SYMFONY_IDE)%"
|
||||
* test?: bool|Param,
|
||||
|
|
@ -136,9 +136,9 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* set_locale_from_accept_language?: bool|Param, // Whether to use the Accept-Language HTTP header to set the Request locale (only when the "_locale" request attribute is not passed). // Default: false
|
||||
* set_content_language_from_locale?: bool|Param, // Whether to set the Content-Language HTTP header on the Response using the Request locale. // Default: false
|
||||
* enabled_locales?: list<scalar|Param|null>,
|
||||
* trusted_hosts?: list<scalar|Param|null>,
|
||||
* trusted_hosts?: string|list<scalar|Param|null>,
|
||||
* trusted_proxies?: mixed, // Default: ["%env(default::SYMFONY_TRUSTED_PROXIES)%"]
|
||||
* trusted_headers?: list<scalar|Param|null>,
|
||||
* trusted_headers?: string|list<scalar|Param|null>,
|
||||
* error_controller?: scalar|Param|null, // Default: "error_controller"
|
||||
* handle_all_throwables?: bool|Param, // HttpKernel will handle all kinds of \Throwable. // Default: true
|
||||
* csrf_protection?: bool|array{
|
||||
|
|
@ -202,23 +202,23 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* property?: scalar|Param|null,
|
||||
* service?: scalar|Param|null,
|
||||
* },
|
||||
* supports?: list<scalar|Param|null>,
|
||||
* supports?: string|list<scalar|Param|null>,
|
||||
* definition_validators?: list<scalar|Param|null>,
|
||||
* support_strategy?: scalar|Param|null,
|
||||
* initial_marking?: list<scalar|Param|null>,
|
||||
* events_to_dispatch?: list<string|Param>|null,
|
||||
* places?: list<array{ // Default: []
|
||||
* initial_marking?: \BackedEnum|string|list<scalar|Param|null>,
|
||||
* events_to_dispatch?: null|list<string|Param>,
|
||||
* places?: string|list<array{ // Default: []
|
||||
* name?: scalar|Param|null,
|
||||
* metadata?: array<string, mixed>,
|
||||
* }>,
|
||||
* transitions?: list<array{ // Default: []
|
||||
* name?: string|Param,
|
||||
* guard?: string|Param, // An expression to block the transition.
|
||||
* from?: list<array{ // Default: []
|
||||
* from?: \BackedEnum|string|list<array{ // Default: []
|
||||
* place?: string|Param,
|
||||
* weight?: int|Param, // Default: 1
|
||||
* }>,
|
||||
* to?: list<array{ // Default: []
|
||||
* to?: \BackedEnum|string|list<array{ // Default: []
|
||||
* place?: string|Param,
|
||||
* weight?: int|Param, // Default: 1
|
||||
* }>,
|
||||
|
|
@ -271,7 +271,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* version_format?: scalar|Param|null, // Default: "%%s?%%s"
|
||||
* json_manifest_path?: scalar|Param|null, // Default: null
|
||||
* base_path?: scalar|Param|null, // Default: ""
|
||||
* base_urls?: list<scalar|Param|null>,
|
||||
* base_urls?: string|list<scalar|Param|null>,
|
||||
* packages?: array<string, array{ // Default: []
|
||||
* strict_mode?: bool|Param, // Throw an exception if an entry is missing from the manifest.json. // Default: false
|
||||
* version_strategy?: scalar|Param|null, // Default: null
|
||||
|
|
@ -279,12 +279,12 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* version_format?: scalar|Param|null, // Default: null
|
||||
* json_manifest_path?: scalar|Param|null, // Default: null
|
||||
* base_path?: scalar|Param|null, // Default: ""
|
||||
* base_urls?: list<scalar|Param|null>,
|
||||
* base_urls?: string|list<scalar|Param|null>,
|
||||
* }>,
|
||||
* },
|
||||
* asset_mapper?: bool|array{ // Asset Mapper configuration
|
||||
* enabled?: bool|Param, // Default: false
|
||||
* paths?: array<string, scalar|Param|null>,
|
||||
* paths?: string|array<string, scalar|Param|null>,
|
||||
* excluded_patterns?: list<scalar|Param|null>,
|
||||
* exclude_dotfiles?: bool|Param, // If true, any files starting with "." will be excluded from the asset mapper. // Default: true
|
||||
* server?: bool|Param, // If true, a "dev server" will return the assets from the public directory (true in "debug" mode only by default). // Default: true
|
||||
|
|
@ -303,7 +303,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* },
|
||||
* translator?: bool|array{ // Translator configuration
|
||||
* enabled?: bool|Param, // Default: true
|
||||
* fallbacks?: list<scalar|Param|null>,
|
||||
* fallbacks?: string|list<scalar|Param|null>,
|
||||
* logging?: bool|Param, // Default: false
|
||||
* formatter?: scalar|Param|null, // Default: "translator.formatter.default"
|
||||
* cache_dir?: scalar|Param|null, // Default: "%kernel.cache_dir%/translations"
|
||||
|
|
@ -333,7 +333,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* enabled?: bool|Param, // Default: true
|
||||
* cache?: scalar|Param|null, // Deprecated: Setting the "framework.validation.cache.cache" configuration option is deprecated. It will be removed in version 8.0.
|
||||
* enable_attributes?: bool|Param, // Default: true
|
||||
* static_method?: list<scalar|Param|null>,
|
||||
* static_method?: string|list<scalar|Param|null>,
|
||||
* translation_domain?: scalar|Param|null, // Default: "validators"
|
||||
* email_validation_mode?: "html5"|"html5-allow-no-tld"|"strict"|"loose"|Param, // Default: "html5"
|
||||
* mapping?: array{
|
||||
|
|
@ -396,7 +396,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* default_doctrine_dbal_provider?: scalar|Param|null, // Default: "database_connection"
|
||||
* default_pdo_provider?: scalar|Param|null, // Default: null
|
||||
* pools?: array<string, array{ // Default: []
|
||||
* adapters?: list<scalar|Param|null>,
|
||||
* adapters?: string|list<scalar|Param|null>,
|
||||
* tags?: scalar|Param|null, // Default: null
|
||||
* public?: bool|Param, // Default: false
|
||||
* default_lifetime?: scalar|Param|null, // Default lifetime of the pool.
|
||||
|
|
@ -419,11 +419,11 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* },
|
||||
* lock?: bool|string|array{ // Lock configuration
|
||||
* enabled?: bool|Param, // Default: false
|
||||
* resources?: array<string, string|list<scalar|Param|null>>,
|
||||
* resources?: string|array<string, string|list<scalar|Param|null>>,
|
||||
* },
|
||||
* semaphore?: bool|string|array{ // Semaphore configuration
|
||||
* enabled?: bool|Param, // Default: false
|
||||
* resources?: array<string, scalar|Param|null>,
|
||||
* resources?: string|array<string, scalar|Param|null>,
|
||||
* },
|
||||
* messenger?: bool|array{ // Messenger configuration
|
||||
* enabled?: bool|Param, // Default: false
|
||||
|
|
@ -453,7 +453,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* rate_limiter?: scalar|Param|null, // Rate limiter name to use when processing messages. // Default: null
|
||||
* }>,
|
||||
* failure_transport?: scalar|Param|null, // Transport name to send failed messages to (after all retries have failed). // Default: null
|
||||
* stop_worker_on_signals?: list<scalar|Param|null>,
|
||||
* stop_worker_on_signals?: int|string|list<scalar|Param|null>,
|
||||
* default_bus?: scalar|Param|null, // Default: null
|
||||
* buses?: array<string, array{ // Default: {"messenger.bus.default":{"default_middleware":{"enabled":true,"allow_no_handlers":false,"allow_no_senders":true},"middleware":[]}}
|
||||
* default_middleware?: bool|string|array{
|
||||
|
|
@ -461,7 +461,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* allow_no_handlers?: bool|Param, // Default: false
|
||||
* allow_no_senders?: bool|Param, // Default: true
|
||||
* },
|
||||
* middleware?: list<string|array{ // Default: []
|
||||
* middleware?: string|list<string|array{ // Default: []
|
||||
* id?: scalar|Param|null,
|
||||
* arguments?: list<mixed>,
|
||||
* }>,
|
||||
|
|
@ -510,9 +510,9 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* retry_failed?: bool|array{
|
||||
* enabled?: bool|Param, // Default: false
|
||||
* retry_strategy?: scalar|Param|null, // service id to override the retry strategy. // Default: null
|
||||
* http_codes?: array<string, array{ // Default: []
|
||||
* http_codes?: int|string|array<string, array{ // Default: []
|
||||
* code?: int|Param,
|
||||
* methods?: list<string|Param>,
|
||||
* methods?: string|list<string|Param>,
|
||||
* }>,
|
||||
* max_retries?: int|Param, // Default: 3
|
||||
* delay?: int|Param, // Time in ms to delay (or the initial value when multiplier is used). // Default: 1000
|
||||
|
|
@ -563,9 +563,9 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* retry_failed?: bool|array{
|
||||
* enabled?: bool|Param, // Default: false
|
||||
* retry_strategy?: scalar|Param|null, // service id to override the retry strategy. // Default: null
|
||||
* http_codes?: array<string, array{ // Default: []
|
||||
* http_codes?: int|string|array<string, array{ // Default: []
|
||||
* code?: int|Param,
|
||||
* methods?: list<string|Param>,
|
||||
* methods?: string|list<string|Param>,
|
||||
* }>,
|
||||
* max_retries?: int|Param, // Default: 3
|
||||
* delay?: int|Param, // Time in ms to delay (or the initial value when multiplier is used). // Default: 1000
|
||||
|
|
@ -582,8 +582,8 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* transports?: array<string, scalar|Param|null>,
|
||||
* envelope?: array{ // Mailer Envelope configuration
|
||||
* sender?: scalar|Param|null,
|
||||
* recipients?: list<scalar|Param|null>,
|
||||
* allowed_recipients?: list<scalar|Param|null>,
|
||||
* recipients?: string|list<scalar|Param|null>,
|
||||
* allowed_recipients?: string|list<scalar|Param|null>,
|
||||
* },
|
||||
* headers?: array<string, string|array{ // Default: []
|
||||
* value?: mixed,
|
||||
|
|
@ -635,7 +635,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* cache_pool?: scalar|Param|null, // The cache pool to use for storing the current limiter state. // Default: "cache.rate_limiter"
|
||||
* storage_service?: scalar|Param|null, // The service ID of a custom storage implementation, this precedes any configured "cache_pool". // Default: null
|
||||
* policy?: "fixed_window"|"token_bucket"|"sliding_window"|"compound"|"no_limit"|Param, // The algorithm to be used by this limiter.
|
||||
* limiters?: list<scalar|Param|null>,
|
||||
* limiters?: string|list<scalar|Param|null>,
|
||||
* limit?: int|Param, // The maximum allowed hits in a fixed interval or burst.
|
||||
* interval?: scalar|Param|null, // Configures the fixed interval if "policy" is set to "fixed_window" or "sliding_window". The value must be a number followed by "second", "minute", "hour", "day", "week" or "month" (or their plural equivalent).
|
||||
* rate?: array{ // Configures the fill rate if "policy" is set to "token_bucket".
|
||||
|
|
@ -658,20 +658,20 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* allow_safe_elements?: bool|Param, // Allows "safe" elements and attributes. // Default: false
|
||||
* allow_static_elements?: bool|Param, // Allows all static elements and attributes from the W3C Sanitizer API standard. // Default: false
|
||||
* allow_elements?: array<string, mixed>,
|
||||
* block_elements?: list<string|Param>,
|
||||
* drop_elements?: list<string|Param>,
|
||||
* block_elements?: string|list<string|Param>,
|
||||
* drop_elements?: string|list<string|Param>,
|
||||
* allow_attributes?: array<string, mixed>,
|
||||
* drop_attributes?: array<string, mixed>,
|
||||
* force_attributes?: array<string, array<string, string|Param>>,
|
||||
* force_https_urls?: bool|Param, // Transforms URLs using the HTTP scheme to use the HTTPS scheme instead. // Default: false
|
||||
* allowed_link_schemes?: list<string|Param>,
|
||||
* allowed_link_hosts?: list<string|Param>|null,
|
||||
* allowed_link_schemes?: string|list<string|Param>,
|
||||
* allowed_link_hosts?: null|string|list<string|Param>,
|
||||
* allow_relative_links?: bool|Param, // Allows relative URLs to be used in links href attributes. // Default: false
|
||||
* allowed_media_schemes?: list<string|Param>,
|
||||
* allowed_media_hosts?: list<string|Param>|null,
|
||||
* allowed_media_schemes?: string|list<string|Param>,
|
||||
* allowed_media_hosts?: null|string|list<string|Param>,
|
||||
* allow_relative_medias?: bool|Param, // Allows relative URLs to be used in media source attributes (img, audio, video, ...). // Default: false
|
||||
* with_attribute_sanitizers?: list<string|Param>,
|
||||
* without_attribute_sanitizers?: list<string|Param>,
|
||||
* with_attribute_sanitizers?: string|list<string|Param>,
|
||||
* without_attribute_sanitizers?: string|list<string|Param>,
|
||||
* max_input_length?: int|Param, // The maximum length allowed for the sanitized input. // Default: 0
|
||||
* }>,
|
||||
* },
|
||||
|
|
@ -958,7 +958,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* },
|
||||
* password_hashers?: array<string, string|array{ // Default: []
|
||||
* algorithm?: scalar|Param|null,
|
||||
* migrate_from?: list<scalar|Param|null>,
|
||||
* migrate_from?: string|list<scalar|Param|null>,
|
||||
* hash_algorithm?: scalar|Param|null, // Name of hashing algorithm for PBKDF2 (i.e. sha256, sha512, etc..) See hash_algos() for a list of supported algorithms. // Default: "sha512"
|
||||
* key_length?: scalar|Param|null, // Default: 40
|
||||
* ignore_case?: bool|Param, // Default: false
|
||||
|
|
@ -972,7 +972,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* providers?: array<string, array{ // Default: []
|
||||
* id?: scalar|Param|null,
|
||||
* chain?: array{
|
||||
* providers?: list<scalar|Param|null>,
|
||||
* providers?: string|list<scalar|Param|null>,
|
||||
* },
|
||||
* entity?: array{
|
||||
* class?: scalar|Param|null, // The full entity class name of your user class.
|
||||
|
|
@ -982,7 +982,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* memory?: array{
|
||||
* users?: array<string, array{ // Default: []
|
||||
* password?: scalar|Param|null, // Default: null
|
||||
* roles?: list<scalar|Param|null>,
|
||||
* roles?: string|list<scalar|Param|null>,
|
||||
* }>,
|
||||
* },
|
||||
* ldap?: array{
|
||||
|
|
@ -991,7 +991,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* search_dn?: scalar|Param|null, // Default: null
|
||||
* search_password?: scalar|Param|null, // Default: null
|
||||
* extra_fields?: list<scalar|Param|null>,
|
||||
* default_roles?: list<scalar|Param|null>,
|
||||
* default_roles?: string|list<scalar|Param|null>,
|
||||
* role_fetcher?: scalar|Param|null, // Default: null
|
||||
* uid_key?: scalar|Param|null, // Default: "sAMAccountName"
|
||||
* filter?: scalar|Param|null, // Default: "({uid_key}={user_identifier})"
|
||||
|
|
@ -1005,7 +1005,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* firewalls?: array<string, array{ // Default: []
|
||||
* pattern?: scalar|Param|null,
|
||||
* host?: scalar|Param|null,
|
||||
* methods?: list<scalar|Param|null>,
|
||||
* methods?: string|list<scalar|Param|null>,
|
||||
* security?: bool|Param, // Default: true
|
||||
* user_checker?: scalar|Param|null, // The UserChecker to use when authenticating users in this firewall. // Default: "security.user_checker"
|
||||
* request_matcher?: scalar|Param|null,
|
||||
|
|
@ -1024,8 +1024,8 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* path?: scalar|Param|null, // Default: "/logout"
|
||||
* target?: scalar|Param|null, // Default: "/"
|
||||
* invalidate_session?: bool|Param, // Default: true
|
||||
* clear_site_data?: list<"*"|"cache"|"cookies"|"storage"|"executionContexts"|Param>,
|
||||
* delete_cookies?: array<string, array{ // Default: []
|
||||
* clear_site_data?: string|list<"*"|"cache"|"cookies"|"storage"|"executionContexts"|Param>,
|
||||
* delete_cookies?: string|array<string, array{ // Default: []
|
||||
* path?: scalar|Param|null, // Default: null
|
||||
* domain?: scalar|Param|null, // Default: null
|
||||
* secure?: scalar|Param|null, // Default: false
|
||||
|
|
@ -1092,6 +1092,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* },
|
||||
* registration?: bool|array{
|
||||
* enabled?: bool|Param, // Default: false
|
||||
* hide_existing_credentials?: bool|Param, // Default: true
|
||||
* profile?: scalar|Param|null, // Default: "default"
|
||||
* options_builder?: scalar|Param|null, // Default: null
|
||||
* routes?: array{
|
||||
|
|
@ -1239,7 +1240,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* success_handler?: scalar|Param|null,
|
||||
* failure_handler?: scalar|Param|null,
|
||||
* realm?: scalar|Param|null, // Default: null
|
||||
* token_extractors?: list<scalar|Param|null>,
|
||||
* token_extractors?: string|list<scalar|Param|null>,
|
||||
* token_handler?: string|array{
|
||||
* id?: scalar|Param|null,
|
||||
* oidc_user_info?: string|array{
|
||||
|
|
@ -1254,7 +1255,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* },
|
||||
* oidc?: array{
|
||||
* discovery?: array{ // Enable the OIDC discovery.
|
||||
* base_uri?: list<scalar|Param|null>,
|
||||
* base_uri?: string|list<scalar|Param|null>,
|
||||
* cache?: array{
|
||||
* id?: scalar|Param|null, // Cache service id to use to cache the OIDC discovery configuration.
|
||||
* },
|
||||
|
|
@ -1297,7 +1298,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* remember_me?: array{
|
||||
* secret?: scalar|Param|null, // Default: "%kernel.secret%"
|
||||
* service?: scalar|Param|null,
|
||||
* user_providers?: list<scalar|Param|null>,
|
||||
* user_providers?: string|list<scalar|Param|null>,
|
||||
* catch_exceptions?: bool|Param, // Default: true
|
||||
* signature_properties?: list<scalar|Param|null>,
|
||||
* token_provider?: string|array{
|
||||
|
|
@ -1325,12 +1326,12 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* path?: scalar|Param|null, // Use the urldecoded format. // Default: null
|
||||
* host?: scalar|Param|null, // Default: null
|
||||
* port?: int|Param, // Default: null
|
||||
* ips?: list<scalar|Param|null>,
|
||||
* ips?: string|list<scalar|Param|null>,
|
||||
* attributes?: array<string, scalar|Param|null>,
|
||||
* route?: scalar|Param|null, // Default: null
|
||||
* methods?: list<scalar|Param|null>,
|
||||
* methods?: string|list<scalar|Param|null>,
|
||||
* allow_if?: scalar|Param|null, // Default: null
|
||||
* roles?: list<scalar|Param|null>,
|
||||
* roles?: string|list<scalar|Param|null>,
|
||||
* }>,
|
||||
* role_hierarchy?: array<string, string|list<scalar|Param|null>>,
|
||||
* }
|
||||
|
|
@ -1351,7 +1352,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* auto_reload?: scalar|Param|null,
|
||||
* optimizations?: int|Param,
|
||||
* default_path?: scalar|Param|null, // The default path used to load templates. // Default: "%kernel.project_dir%/templates"
|
||||
* file_name_pattern?: list<scalar|Param|null>,
|
||||
* file_name_pattern?: string|list<scalar|Param|null>,
|
||||
* paths?: array<string, mixed>,
|
||||
* date?: array{ // The default format options used by the date filter.
|
||||
* format?: scalar|Param|null, // Default: "F j, Y H:i"
|
||||
|
|
@ -1452,7 +1453,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* delay_between_messages?: bool|Param, // Default: false
|
||||
* topic?: int|Param, // Default: null
|
||||
* factor?: int|Param, // Default: 1
|
||||
* tags?: list<scalar|Param|null>,
|
||||
* tags?: string|list<scalar|Param|null>,
|
||||
* console_formatter_options?: mixed, // Default: []
|
||||
* formatter?: scalar|Param|null,
|
||||
* nested?: bool|Param, // Default: false
|
||||
|
|
@ -1496,7 +1497,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* host?: scalar|Param|null,
|
||||
* },
|
||||
* from_email?: scalar|Param|null,
|
||||
* to_email?: list<scalar|Param|null>,
|
||||
* to_email?: string|list<scalar|Param|null>,
|
||||
* subject?: scalar|Param|null,
|
||||
* content_type?: scalar|Param|null, // Default: null
|
||||
* headers?: list<scalar|Param|null>,
|
||||
|
|
@ -1586,7 +1587,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* },
|
||||
* filesystem?: array{
|
||||
* locator?: "filesystem"|"filesystem_insecure"|Param, // Using the "filesystem_insecure" locator is not recommended due to a less secure resolver mechanism, but is provided for those using heavily symlinked projects. // Default: "filesystem"
|
||||
* data_root?: list<scalar|Param|null>,
|
||||
* data_root?: string|list<scalar|Param|null>,
|
||||
* allow_unresolvable_data_roots?: bool|Param, // Default: false
|
||||
* bundle_resources?: array{
|
||||
* enabled?: bool|Param, // Default: false
|
||||
|
|
@ -1930,7 +1931,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* script-src?: list<scalar|Param|null>,
|
||||
* style-src?: list<scalar|Param|null>,
|
||||
* upgrade-insecure-requests?: bool|Param, // Default: false
|
||||
* report-uri?: list<scalar|Param|null>,
|
||||
* report-uri?: string|list<scalar|Param|null>,
|
||||
* worker-src?: list<scalar|Param|null>,
|
||||
* prefetch-src?: list<scalar|Param|null>,
|
||||
* report-to?: scalar|Param|null,
|
||||
|
|
@ -1958,7 +1959,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* script-src?: list<scalar|Param|null>,
|
||||
* style-src?: list<scalar|Param|null>,
|
||||
* upgrade-insecure-requests?: bool|Param, // Default: false
|
||||
* report-uri?: list<scalar|Param|null>,
|
||||
* report-uri?: string|list<scalar|Param|null>,
|
||||
* worker-src?: list<scalar|Param|null>,
|
||||
* prefetch-src?: list<scalar|Param|null>,
|
||||
* report-to?: scalar|Param|null,
|
||||
|
|
@ -1966,7 +1967,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* },
|
||||
* referrer_policy?: bool|array{
|
||||
* enabled?: bool|Param, // Default: false
|
||||
* policies?: list<scalar|Param|null>,
|
||||
* policies?: string|list<scalar|Param|null>,
|
||||
* },
|
||||
* permissions_policy?: bool|array{
|
||||
* enabled?: bool|Param, // Default: false
|
||||
|
|
@ -2097,10 +2098,10 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* secured_rp_ids?: array<string, scalar|Param|null>,
|
||||
* counter_checker?: scalar|Param|null, // This service will check if the counter is valid. By default it throws an exception (recommended). // Default: "Webauthn\\Counter\\ThrowExceptionIfInvalid"
|
||||
* top_origin_validator?: scalar|Param|null, // For cross origin (e.g. iframe), this service will be in charge of verifying the top origin. // Default: null
|
||||
* creation_profiles?: array<string, array{ // Default: []
|
||||
* creation_profiles?: bool|array<string, array{ // Default: []
|
||||
* rp?: array{
|
||||
* id?: scalar|Param|null, // Default: null
|
||||
* name?: scalar|Param|null,
|
||||
* name?: scalar|Param|null, // Deprecated: The child node "name" at path "webauthn.creation_profiles..rp.name" is deprecated and will be removed in the next major release. // Default: ""
|
||||
* icon?: scalar|Param|null, // Deprecated: The child node "icon" at path "webauthn.creation_profiles..rp.icon" is deprecated and has no effect. // Default: null
|
||||
* },
|
||||
* challenge_length?: int|Param, // Default: 32
|
||||
|
|
@ -2114,14 +2115,40 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* extensions?: array<string, scalar|Param|null>,
|
||||
* public_key_credential_parameters?: list<int|Param>,
|
||||
* attestation_conveyance?: scalar|Param|null, // Default: "none"
|
||||
* conditional_create?: bool|Param, // Enable Conditional Create (auto-register) for this profile. When true, user presence can be false after password authentication. See https://github.com/w3c/webauthn/wiki/Explainer:-Conditional-Create // Default: false
|
||||
* }>,
|
||||
* request_profiles?: array<string, array{ // Default: []
|
||||
* request_profiles?: bool|array<string, array{ // Default: []
|
||||
* rp_id?: scalar|Param|null, // Default: null
|
||||
* challenge_length?: int|Param, // Default: 32
|
||||
* timeout?: int|Param, // Default: null
|
||||
* user_verification?: scalar|Param|null, // Default: "preferred"
|
||||
* extensions?: array<string, scalar|Param|null>,
|
||||
* }>,
|
||||
* client_override_policy?: array{ // Configuration for allowing client request values to override profile configuration
|
||||
* user_verification?: array{
|
||||
* enabled?: bool|Param, // Whether to allow client requests to override the user verification requirement // Default: false
|
||||
* allowed_values?: list<scalar|Param|null>,
|
||||
* },
|
||||
* authenticator_attachment?: array{
|
||||
* enabled?: bool|Param, // Whether to allow client requests to override the authenticator attachment // Default: true
|
||||
* allowed_values?: list<scalar|Param|null>,
|
||||
* },
|
||||
* resident_key?: array{
|
||||
* enabled?: bool|Param, // Whether to allow client requests to override the resident key requirement // Default: true
|
||||
* allowed_values?: list<scalar|Param|null>,
|
||||
* },
|
||||
* attestation_conveyance?: array{
|
||||
* enabled?: bool|Param, // Whether to allow client requests to override the attestation conveyance preference // Default: true
|
||||
* allowed_values?: list<scalar|Param|null>,
|
||||
* },
|
||||
* extensions?: array{
|
||||
* enabled?: bool|Param, // Whether to allow client requests to override extensions // Default: true
|
||||
* },
|
||||
* mediation?: array{
|
||||
* enabled?: bool|Param, // Whether to allow client requests to request the conditional mediation flow (auto-register). // Default: false
|
||||
* allowed_values?: list<scalar|Param|null>,
|
||||
* },
|
||||
* },
|
||||
* metadata?: bool|array{ // Enable the support of the Metadata Statements. Please read the documentation for this feature.
|
||||
* enabled?: bool|Param, // Default: false
|
||||
* mds_repository?: scalar|Param|null, // The Metadata Statement repository.
|
||||
|
|
@ -2165,6 +2192,21 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* secured_rp_ids?: array<string, scalar|Param|null>,
|
||||
* }>,
|
||||
* },
|
||||
* passkey_endpoints?: bool|array{ // Enable the .well-known/passkey-endpoints discovery endpoint as defined in the W3C Passkey Endpoints specification.
|
||||
* enabled?: bool|Param, // Default: false
|
||||
* enroll?: string|array{ // URL to the passkey enrollment/creation interface.
|
||||
* path?: scalar|Param|null, // The absolute HTTPS URL or Symfony route name.
|
||||
* params?: list<mixed>,
|
||||
* },
|
||||
* manage?: string|array{ // URL to the passkey management interface.
|
||||
* path?: scalar|Param|null, // The absolute HTTPS URL or Symfony route name.
|
||||
* params?: list<mixed>,
|
||||
* },
|
||||
* prf_usage_details?: string|array{ // URL to informational page about PRF (Pseudo-Random Function) extension usage.
|
||||
* path?: scalar|Param|null, // The absolute HTTPS URL or Symfony route name.
|
||||
* params?: list<mixed>,
|
||||
* },
|
||||
* },
|
||||
* }
|
||||
* @psalm-type NbgrpOneloginSamlConfig = array{ // nb:group OneLogin PHP Symfony Bundle configuration
|
||||
* onelogin_settings?: array<string, array{ // Default: []
|
||||
|
|
@ -2293,7 +2335,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* type?: scalar|Param|null,
|
||||
* elements?: list<scalar|Param|null>,
|
||||
* },
|
||||
* keys_patterns?: list<scalar|Param|null>,
|
||||
* keys_patterns?: string|list<scalar|Param|null>,
|
||||
* }
|
||||
* @psalm-type DompdfFontLoaderConfig = array{
|
||||
* autodiscovery?: bool|array{
|
||||
|
|
@ -2353,6 +2395,8 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* proxy_namespace?: scalar|Param|null, // Default: "Jbtronics\\SettingsBundle\\Proxies"
|
||||
* default_storage_adapter?: scalar|Param|null, // Default: null
|
||||
* save_after_migration?: bool|Param, // Default: true
|
||||
* yaml_mapping_paths?: list<scalar|Param|null>,
|
||||
* metadata_compiler_providers?: list<scalar|Param|null>,
|
||||
* file_storage?: array{
|
||||
* storage_directory?: scalar|Param|null, // Default: "%kernel.project_dir%/var/jbtronics_settings/"
|
||||
* default_filename?: scalar|Param|null, // Default: "settings"
|
||||
|
|
@ -2672,6 +2716,465 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* ...<string, mixed>
|
||||
* },
|
||||
* }
|
||||
* @psalm-type AiConfig = array{
|
||||
* platform?: array{
|
||||
* albert?: array{
|
||||
* api_key?: string|Param,
|
||||
* base_url?: string|Param,
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* amazeeai?: array{
|
||||
* base_url?: string|Param,
|
||||
* api_key?: string|Param,
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* anthropic?: array{
|
||||
* api_key?: string|Param,
|
||||
* version?: string|Param, // Default: null
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* cache_retention?: "none"|"short"|"long"|Param, // Prompt cache retention policy for Anthropic models // Default: "short"
|
||||
* },
|
||||
* azure?: array<string, array{ // Default: []
|
||||
* api_key?: string|Param,
|
||||
* base_url?: string|Param,
|
||||
* deployment?: string|Param,
|
||||
* api_version?: string|Param, // The used API version
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* }>,
|
||||
* bedrock?: array<string, array{ // Default: []
|
||||
* bedrock_runtime_client?: string|Param, // Service ID of the Bedrock runtime client to use // Default: null
|
||||
* model_catalog?: string|Param, // Default: null
|
||||
* }>,
|
||||
* cache?: array<string, array{ // Default: []
|
||||
* platform?: string|Param,
|
||||
* service?: string|Param, // The cache service id as defined under the "cache" configuration key // Default: "cache.app"
|
||||
* cache_key?: string|Param, // Key used to store platform results, if not set, the current platform name will be used, the "prompt_cache_key" can be set during platform call to override this value
|
||||
* ttl?: int|Param,
|
||||
* }>,
|
||||
* cartesia?: array{
|
||||
* api_key?: string|Param,
|
||||
* version?: string|Param,
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* cerebras?: array{
|
||||
* api_key?: string|Param,
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* cohere?: array{
|
||||
* api_key?: string|Param,
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* decart?: array{
|
||||
* api_key?: string|Param,
|
||||
* host?: string|Param, // Default: "https://api.decart.ai/v1"
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* deepseek?: array{
|
||||
* api_key?: string|Param,
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* dockermodelrunner?: array{
|
||||
* host_url?: string|Param, // Default: "http://127.0.0.1:12434"
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* elevenlabs?: array{
|
||||
* api_key?: string|Param,
|
||||
* endpoint?: string|Param, // Default: "https://api.elevenlabs.io/v1/"
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* failover?: array<string, array{ // Default: []
|
||||
* platforms?: list<scalar|Param|null>,
|
||||
* rate_limiter?: string|Param,
|
||||
* }>,
|
||||
* gemini?: array{
|
||||
* api_key?: string|Param,
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* generic?: array<string, array{ // Default: []
|
||||
* base_url?: string|Param,
|
||||
* api_key?: string|Param,
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* model_catalog?: string|Param, // Service ID of the model catalog to use
|
||||
* supports_completions?: bool|Param, // Default: true
|
||||
* supports_embeddings?: bool|Param, // Default: true
|
||||
* completions_path?: string|Param, // Default: "/v1/chat/completions"
|
||||
* embeddings_path?: string|Param, // Default: "/v1/embeddings"
|
||||
* }>,
|
||||
* huggingface?: array{
|
||||
* api_key?: string|Param,
|
||||
* provider?: string|Param, // Default: "hf-inference"
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* lmstudio?: array{
|
||||
* host_url?: string|Param, // Default: "http://127.0.0.1:1234"
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* mistral?: array{
|
||||
* api_key?: string|Param,
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* ollama?: array{
|
||||
* endpoint?: string|Param, // Endpoint for Ollama (e.g. "http://127.0.0.1:11434" for local, or a cloud endpoint). If null, the http_client is used as-is and must already be configured with a base URI.
|
||||
* api_key?: string|Param, // API key for Ollama Cloud authentication (optional for local usage)
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use. When "endpoint" is null, this client must be pre-configured (e.g. with a base_uri). // Default: "http_client"
|
||||
* },
|
||||
* openai?: array{
|
||||
* api_key?: string|Param,
|
||||
* region?: scalar|Param|null, // The region for OpenAI API (EU, US, or null for default) // Default: null
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* openrouter?: array{
|
||||
* api_key?: string|Param,
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* ovh?: array{
|
||||
* api_key?: scalar|Param|null,
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* perplexity?: array{
|
||||
* api_key?: string|Param,
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* scaleway?: array{
|
||||
* api_key?: scalar|Param|null,
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* transformersphp?: array<mixed>,
|
||||
* vertexai?: array{
|
||||
* location?: string|Param, // Required for the project-scoped endpoint. Must be set together with "project_id". // Default: null
|
||||
* project_id?: string|Param, // Required for the project-scoped endpoint. Must be set together with "location". // Default: null
|
||||
* api_key?: string|Param, // When set without "location" and "project_id", uses the global endpoint. Note: API keys only identify the project for billing and do not provide identity-based access control. For production use with IAM, audit logging, or data residency, prefer the project-scoped endpoint with service account authentication. // Default: null
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* voyage?: array{
|
||||
* api_key?: string|Param,
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* },
|
||||
* },
|
||||
* model?: array<string, array<string, array{ // Default: []
|
||||
* class?: string|Param, // The fully qualified class name of the model (must extend Symfony\AI\Platform\Model) // Default: "Symfony\\AI\\Platform\\Model"
|
||||
* capabilities?: list<value-of<\Symfony\AI\Platform\Capability>|\Symfony\AI\Platform\Capability|Param>,
|
||||
* }>>,
|
||||
* agent?: array<string, array{ // Default: []
|
||||
* platform?: string|Param, // Service name of platform // Default: "Symfony\\AI\\Platform\\PlatformInterface"
|
||||
* model?: mixed,
|
||||
* memory?: mixed, // Memory configuration: string for static memory, or array with "service" key for service reference // Default: null
|
||||
* prompt?: string|array{ // The system prompt configuration
|
||||
* text?: string|Param, // The system prompt text
|
||||
* file?: string|Param, // Path to file containing the system prompt
|
||||
* include_tools?: bool|Param, // Include tool definitions at the end of the system prompt // Default: false
|
||||
* enable_translation?: bool|Param, // Enable translation for the system prompt // Default: false
|
||||
* translation_domain?: string|Param, // The translation domain for the system prompt // Default: null
|
||||
* },
|
||||
* tools?: bool|array{
|
||||
* enabled?: bool|Param, // Default: true
|
||||
* services?: list<string|array{ // Default: []
|
||||
* service?: string|Param,
|
||||
* agent?: string|Param,
|
||||
* name?: string|Param,
|
||||
* description?: string|Param,
|
||||
* method?: string|Param,
|
||||
* }>,
|
||||
* },
|
||||
* keep_tool_messages?: bool|Param, // Keep tool messages in the conversation history // Default: false
|
||||
* include_sources?: bool|Param, // Include sources exposed by tools as part of the tool result metadata // Default: false
|
||||
* fault_tolerant_toolbox?: bool|Param, // Continue the agent run even if a tool call fails // Default: true
|
||||
* speech?: bool|array{ // Speech (TTS/STT) decorator configuration
|
||||
* enabled?: bool|Param, // Default: true
|
||||
* text_to_speech_platform?: string|Param, // Service name of the TTS platform (e.g. ai.platform.elevenlabs). // Default: null
|
||||
* speech_to_text_platform?: string|Param, // Service name of the STT platform (e.g. ai.platform.openai). // Default: null
|
||||
* tts_model?: string|Param, // Text-to-speech model name // Default: null
|
||||
* tts_options?: mixed, // Provider-specific TTS options // Default: []
|
||||
* stt_model?: string|Param, // Speech-to-text model name // Default: null
|
||||
* stt_options?: mixed, // Provider-specific STT options // Default: []
|
||||
* },
|
||||
* }>,
|
||||
* multi_agent?: array<string, array{ // Default: []
|
||||
* orchestrator?: string|Param, // Service ID of the orchestrator agent
|
||||
* handoffs?: array<string, list<scalar|Param|null>>,
|
||||
* fallback?: string|Param, // Service ID of the fallback agent for unmatched requests
|
||||
* }>,
|
||||
* store?: array{
|
||||
* azuresearch?: array<string, array{ // Default: []
|
||||
* endpoint?: string|Param,
|
||||
* api_key?: string|Param,
|
||||
* api_version?: string|Param,
|
||||
* index_name?: string|Param, // The name of the store will be used if the "index_name" option is not set
|
||||
* http_client?: string|Param, // Default: "http_client"
|
||||
* vector_field?: string|Param, // Default: "vector"
|
||||
* }>,
|
||||
* cache?: array<string, array{ // Default: []
|
||||
* service?: string|Param, // Default: "cache.app"
|
||||
* cache_key?: string|Param, // The name of the store will be used if the key is not set.
|
||||
* strategy?: string|Param, // Default: "cosine"
|
||||
* }>,
|
||||
* chromadb?: array<string, array{ // Default: []
|
||||
* client?: string|Param, // Default: "Codewithkyrian\\ChromaDB\\Client"
|
||||
* collection?: string|Param,
|
||||
* }>,
|
||||
* clickhouse?: array<string, array{ // Default: []
|
||||
* dsn?: string|Param,
|
||||
* http_client?: string|Param,
|
||||
* database?: string|Param,
|
||||
* table?: string|Param,
|
||||
* }>,
|
||||
* cloudflare?: array<string, array{ // Default: []
|
||||
* account_id?: string|Param,
|
||||
* api_key?: string|Param,
|
||||
* index_name?: string|Param,
|
||||
* dimensions?: int|Param, // Default: 1536
|
||||
* metric?: string|Param, // Default: "cosine"
|
||||
* endpoint?: string|Param,
|
||||
* }>,
|
||||
* elasticsearch?: array<string, array{ // Default: []
|
||||
* endpoint?: string|Param,
|
||||
* index_name?: string|Param,
|
||||
* vectors_field?: string|Param, // Default: "_vectors"
|
||||
* dimensions?: int|Param, // Default: 1536
|
||||
* similarity?: string|Param, // Default: "cosine"
|
||||
* http_client?: string|Param, // Default: "http_client"
|
||||
* }>,
|
||||
* manticoresearch?: array<string, array{ // Default: []
|
||||
* endpoint?: string|Param,
|
||||
* table?: string|Param,
|
||||
* field?: string|Param, // Default: "_vectors"
|
||||
* type?: string|Param, // Default: "hnsw"
|
||||
* similarity?: string|Param, // Default: "cosine"
|
||||
* dimensions?: int|Param, // Default: 1536
|
||||
* quantization?: string|Param,
|
||||
* }>,
|
||||
* mariadb?: array<string, array{ // Default: []
|
||||
* connection?: string|Param,
|
||||
* table_name?: string|Param,
|
||||
* index_name?: string|Param,
|
||||
* vector_field_name?: string|Param,
|
||||
* setup_options?: array{
|
||||
* dimensions?: int|Param,
|
||||
* },
|
||||
* distance?: "cosine"|"euclidean"|"distance"|Param, // Distance metric to use for vector similarity search // Default: "euclidean"
|
||||
* }>,
|
||||
* meilisearch?: array<string, array{ // Default: []
|
||||
* endpoint?: string|Param,
|
||||
* api_key?: string|Param,
|
||||
* index_name?: string|Param,
|
||||
* embedder?: string|Param, // Default: "default"
|
||||
* vector_field?: string|Param, // Default: "_vectors"
|
||||
* dimensions?: int|Param, // Default: 1536
|
||||
* semantic_ratio?: float|Param, // The ratio between semantic (vector) and full-text search (0.0 to 1.0). Default: 1.0 (100% semantic) // Default: 1.0
|
||||
* }>,
|
||||
* memory?: array<string, array{ // Default: []
|
||||
* strategy?: string|Param,
|
||||
* }>,
|
||||
* milvus?: array<string, array{ // Default: []
|
||||
* endpoint?: string|Param,
|
||||
* api_key?: string|Param,
|
||||
* database?: string|Param,
|
||||
* collection?: string|Param,
|
||||
* vector_field?: string|Param, // Default: "_vectors"
|
||||
* dimensions?: int|Param, // Default: 1536
|
||||
* metric_type?: string|Param, // Default: "COSINE"
|
||||
* }>,
|
||||
* mongodb?: array<string, array{ // Default: []
|
||||
* client?: string|Param, // Default: "MongoDB\\Client"
|
||||
* database?: string|Param,
|
||||
* collection?: string|Param,
|
||||
* index_name?: string|Param,
|
||||
* vector_field?: string|Param, // Default: "vector"
|
||||
* bulk_write?: bool|Param, // Default: false
|
||||
* setup_options?: array{
|
||||
* fields?: mixed, // Default: []
|
||||
* },
|
||||
* }>,
|
||||
* neo4j?: array<string, array{ // Default: []
|
||||
* endpoint?: string|Param,
|
||||
* username?: string|Param,
|
||||
* password?: string|Param,
|
||||
* database?: string|Param,
|
||||
* vector_index_name?: string|Param,
|
||||
* node_name?: string|Param,
|
||||
* vector_field?: string|Param, // Default: "embeddings"
|
||||
* dimensions?: int|Param, // Default: 1536
|
||||
* distance?: string|Param, // Default: "cosine"
|
||||
* quantization?: bool|Param,
|
||||
* }>,
|
||||
* opensearch?: array<string, array{ // Default: []
|
||||
* endpoint?: string|Param,
|
||||
* index_name?: string|Param,
|
||||
* vectors_field?: string|Param, // Default: "_vectors"
|
||||
* dimensions?: int|Param, // Default: 1536
|
||||
* space_type?: string|Param, // Default: "l2"
|
||||
* http_client?: string|Param, // Default: "http_client"
|
||||
* }>,
|
||||
* pinecone?: array<string, array{ // Default: []
|
||||
* client?: string|Param, // Default: "Probots\\Pinecone\\Client"
|
||||
* index_name?: string|Param,
|
||||
* namespace?: string|Param,
|
||||
* filter?: list<scalar|Param|null>,
|
||||
* top_k?: int|Param,
|
||||
* }>,
|
||||
* postgres?: array<string, array{ // Default: []
|
||||
* dsn?: string|Param,
|
||||
* username?: string|Param,
|
||||
* password?: string|Param,
|
||||
* table_name?: string|Param,
|
||||
* vector_field?: string|Param, // Default: "embedding"
|
||||
* distance?: "cosine"|"inner_product"|"l1"|"l2"|Param, // Distance metric to use for vector similarity search // Default: "l2"
|
||||
* dbal_connection?: string|Param,
|
||||
* setup_options?: array{
|
||||
* vector_type?: string|Param, // Default: "vector"
|
||||
* vector_size?: int|Param, // Default: 1536
|
||||
* index_method?: string|Param, // Default: "ivfflat"
|
||||
* index_opclass?: string|Param, // Default: "vector_cosine_ops"
|
||||
* },
|
||||
* }>,
|
||||
* qdrant?: array<string, array{ // Default: []
|
||||
* endpoint?: string|Param,
|
||||
* api_key?: string|Param,
|
||||
* collection_name?: string|Param, // The name of the store will be used if the "collection_name" is not set
|
||||
* http_client?: string|Param, // Default: "http_client"
|
||||
* dimensions?: int|Param, // Default: 1536
|
||||
* distance?: string|Param, // Default: "Cosine"
|
||||
* async?: bool|Param, // Default: false
|
||||
* }>,
|
||||
* redis?: array<string, array{ // Default: []
|
||||
* connection_parameters?: mixed, // see https://github.com/phpredis/phpredis?tab=readme-ov-file#example-1
|
||||
* client?: string|Param, // a service id of a Redis client
|
||||
* index_name?: string|Param,
|
||||
* key_prefix?: string|Param, // Default: "vector:"
|
||||
* distance?: "COSINE"|"L2"|"IP"|Param, // Distance metric to use for vector similarity search // Default: "COSINE"
|
||||
* }>,
|
||||
* s3vectors?: array<string, array{ // Default: []
|
||||
* client?: string|Param, // Service reference to an existing S3VectorsClient
|
||||
* configuration?: array<mixed>,
|
||||
* vector_bucket_name?: string|Param,
|
||||
* index_name?: string|Param,
|
||||
* filter?: array<mixed>,
|
||||
* top_k?: int|Param, // Default number of results to return // Default: 3
|
||||
* }>,
|
||||
* sqlite?: array<string, array{ // Default: []
|
||||
* dsn?: string|Param,
|
||||
* connection?: string|Param,
|
||||
* table_name?: string|Param,
|
||||
* strategy?: string|Param,
|
||||
* vec?: bool|Param, // Default: false
|
||||
* distance?: "cosine"|"L2"|Param, // Default: "cosine"
|
||||
* vector_dimension?: int|Param, // Default: 1536
|
||||
* }>,
|
||||
* supabase?: array<string, array{ // Default: []
|
||||
* http_client?: string|Param, // Service ID of the HTTP client to use // Default: "http_client"
|
||||
* url?: string|Param,
|
||||
* api_key?: string|Param,
|
||||
* table?: string|Param,
|
||||
* vector_field?: string|Param, // Default: "embedding"
|
||||
* vector_dimension?: int|Param, // Default: 1536
|
||||
* function_name?: string|Param, // Default: "match_documents"
|
||||
* }>,
|
||||
* surrealdb?: array<string, array{ // Default: []
|
||||
* endpoint?: string|Param,
|
||||
* username?: string|Param,
|
||||
* password?: string|Param,
|
||||
* namespace?: string|Param,
|
||||
* database?: string|Param,
|
||||
* table?: string|Param,
|
||||
* vector_field?: string|Param, // Default: "_vectors"
|
||||
* strategy?: string|Param, // Default: "cosine"
|
||||
* dimensions?: int|Param, // Default: 1536
|
||||
* namespaced_user?: bool|Param,
|
||||
* }>,
|
||||
* typesense?: array<string, array{ // Default: []
|
||||
* endpoint?: string|Param,
|
||||
* api_key?: string|Param,
|
||||
* collection?: string|Param,
|
||||
* vector_field?: string|Param, // Default: "_vectors"
|
||||
* dimensions?: int|Param, // Default: 1536
|
||||
* }>,
|
||||
* weaviate?: array<string, array{ // Default: []
|
||||
* endpoint?: string|Param,
|
||||
* api_key?: string|Param,
|
||||
* http_client?: string|Param, // Default: "http_client"
|
||||
* collection?: string|Param, // The name of the store will be used if the "collection" is not set
|
||||
* }>,
|
||||
* vektor?: array<string, array{ // Default: []
|
||||
* storage_path?: string|Param, // Default: "%kernel.project_dir%/var/share"
|
||||
* dimensions?: int|Param, // Default: 1536
|
||||
* }>,
|
||||
* },
|
||||
* message_store?: array{
|
||||
* cache?: array<string, array{ // Default: []
|
||||
* service?: string|Param, // Default: "cache.app"
|
||||
* key?: string|Param, // The name of the message store will be used if the key is not set
|
||||
* ttl?: int|Param,
|
||||
* }>,
|
||||
* cloudflare?: array<string, array{ // Default: []
|
||||
* account_id?: string|Param,
|
||||
* api_key?: string|Param,
|
||||
* namespace?: string|Param,
|
||||
* endpoint_url?: string|Param, // If the version of the Cloudflare API is updated, use this key to support it.
|
||||
* }>,
|
||||
* doctrine?: array{
|
||||
* dbal?: array<string, array{ // Default: []
|
||||
* connection?: string|Param,
|
||||
* table_name?: string|Param, // The name of the message store will be used if the table_name is not set
|
||||
* }>,
|
||||
* },
|
||||
* meilisearch?: array<string, array{ // Default: []
|
||||
* endpoint?: string|Param,
|
||||
* api_key?: string|Param,
|
||||
* index_name?: string|Param,
|
||||
* }>,
|
||||
* memory?: array<string, array{ // Default: []
|
||||
* identifier?: string|Param,
|
||||
* }>,
|
||||
* mongodb?: array<string, array{ // Default: []
|
||||
* client?: string|Param, // Default: "MongoDB\\Client"
|
||||
* database?: string|Param,
|
||||
* collection?: string|Param,
|
||||
* }>,
|
||||
* pogocache?: array<string, array{ // Default: []
|
||||
* endpoint?: string|Param,
|
||||
* password?: string|Param,
|
||||
* key?: string|Param,
|
||||
* }>,
|
||||
* redis?: array<string, array{ // Default: []
|
||||
* connection_parameters?: mixed, // see https://github.com/phpredis/phpredis?tab=readme-ov-file#example-1
|
||||
* client?: string|Param, // a service id of a Redis client
|
||||
* endpoint?: string|Param,
|
||||
* index_name?: string|Param,
|
||||
* }>,
|
||||
* session?: array<string, array{ // Default: []
|
||||
* identifier?: string|Param,
|
||||
* }>,
|
||||
* surrealdb?: array<string, array{ // Default: []
|
||||
* endpoint?: string|Param,
|
||||
* username?: string|Param,
|
||||
* password?: string|Param,
|
||||
* namespace?: string|Param,
|
||||
* database?: string|Param,
|
||||
* table?: string|Param,
|
||||
* namespaced_user?: bool|Param, // Using a namespaced user is a good practice to prevent any undesired access to a specific table, see https://surrealdb.com/docs/surrealdb/reference-guide/security-best-practices
|
||||
* }>,
|
||||
* },
|
||||
* chat?: array<string, array{ // Default: []
|
||||
* agent?: string|Param,
|
||||
* message_store?: string|Param,
|
||||
* }>,
|
||||
* vectorizer?: array<string, array{ // Default: []
|
||||
* platform?: string|Param, // Service name of platform // Default: "Symfony\\AI\\Platform\\PlatformInterface"
|
||||
* model?: mixed,
|
||||
* }>,
|
||||
* indexer?: array<string, array{ // Default: []
|
||||
* loader?: string|Param, // Service name of loader // Default: null
|
||||
* source?: mixed, // Source identifier (file path, URL, etc.) or array of sources // Default: null
|
||||
* transformers?: list<scalar|Param|null>,
|
||||
* filters?: list<scalar|Param|null>,
|
||||
* vectorizer?: scalar|Param|null, // Service name of vectorizer // Default: "Symfony\\AI\\Store\\Document\\VectorizerInterface"
|
||||
* store?: string|Param, // Service name of store // Default: "Symfony\\AI\\Store\\StoreInterface"
|
||||
* }>,
|
||||
* retriever?: array<string, array{ // Default: []
|
||||
* vectorizer?: scalar|Param|null, // Service name of vectorizer // Default: "Symfony\\AI\\Store\\Document\\VectorizerInterface"
|
||||
* store?: string|Param, // Service name of store // Default: "Symfony\\AI\\Store\\StoreInterface"
|
||||
* }>,
|
||||
* }
|
||||
* @psalm-type ConfigType = array{
|
||||
* imports?: ImportsConfig,
|
||||
* parameters?: ParametersConfig,
|
||||
|
|
@ -2701,6 +3204,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* nelmio_cors?: NelmioCorsConfig,
|
||||
* jbtronics_settings?: JbtronicsSettingsConfig,
|
||||
* api_platform?: ApiPlatformConfig,
|
||||
* ai?: AiConfig,
|
||||
* "when@dev"?: array{
|
||||
* imports?: ImportsConfig,
|
||||
* parameters?: ParametersConfig,
|
||||
|
|
@ -2734,6 +3238,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* jbtronics_settings?: JbtronicsSettingsConfig,
|
||||
* jbtronics_translation_editor?: JbtronicsTranslationEditorConfig,
|
||||
* api_platform?: ApiPlatformConfig,
|
||||
* ai?: AiConfig,
|
||||
* },
|
||||
* "when@docker"?: array{
|
||||
* imports?: ImportsConfig,
|
||||
|
|
@ -2764,6 +3269,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* nelmio_cors?: NelmioCorsConfig,
|
||||
* jbtronics_settings?: JbtronicsSettingsConfig,
|
||||
* api_platform?: ApiPlatformConfig,
|
||||
* ai?: AiConfig,
|
||||
* },
|
||||
* "when@prod"?: array{
|
||||
* imports?: ImportsConfig,
|
||||
|
|
@ -2794,6 +3300,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* nelmio_cors?: NelmioCorsConfig,
|
||||
* jbtronics_settings?: JbtronicsSettingsConfig,
|
||||
* api_platform?: ApiPlatformConfig,
|
||||
* ai?: AiConfig,
|
||||
* },
|
||||
* "when@test"?: array{
|
||||
* imports?: ImportsConfig,
|
||||
|
|
@ -2827,6 +3334,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||
* nelmio_cors?: NelmioCorsConfig,
|
||||
* jbtronics_settings?: JbtronicsSettingsConfig,
|
||||
* api_platform?: ApiPlatformConfig,
|
||||
* ai?: AiConfig,
|
||||
* },
|
||||
* ...<string, ExtensionType|array{ // extra keys must follow the when@%env% pattern or match an extension alias
|
||||
* imports?: ImportsConfig,
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ It is installed on a web server and so can be accessed with any browser without
|
|||
* Easy migration from an existing PartKeepr instance (see [here]({%link partkeepr_migration.md %}))
|
||||
* Use cloud providers (like Octopart, Digikey, Farnell, Mouser, or TME) to automatically get part information, datasheets, and
|
||||
prices for parts (see [here]({% link usage/information_provider_system.md %}))
|
||||
* Retrieve part information from arbitrary shop websites, using either conventional data extraction from structured metadata, or AI based data extraction
|
||||
* API to access Part-DB from other applications/scripts
|
||||
* [Integration with KiCad]({%link usage/eda_integration.md %}): Use Part-DB as the central datasource for your
|
||||
KiCad and see available parts from Part-DB directly inside KiCad.
|
||||
|
|
|
|||
|
|
@ -224,6 +224,52 @@ docker-compose up -d
|
|||
docker exec --user=www-data partdb php bin/console doctrine:migrations:migrate
|
||||
```
|
||||
|
||||
### Automatic updates via Watchtower (Web UI)
|
||||
|
||||
Part-DB supports triggering Docker container updates directly from the web interface using [Watchtower](https://github.com/nicholas-fedor/watchtower).
|
||||
When configured, administrators can check for and apply updates from the **System > Update Manager** page.
|
||||
|
||||
{: .info }
|
||||
> The original `containrrr/watchtower` project is no longer maintained (last release November 2023). These docs use the actively maintained community fork at [`nicholas-fedor/watchtower`](https://github.com/nicholas-fedor/watchtower), which is drop-in compatible with the original HTTP API.
|
||||
|
||||
To enable this feature, add a Watchtower service to your `docker-compose.yaml` and configure the connection:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
partdb:
|
||||
container_name: partdb
|
||||
image: jbtronics/part-db1:latest
|
||||
labels:
|
||||
- com.centurylinklabs.watchtower.enable=true
|
||||
environment:
|
||||
# ... your existing environment variables ...
|
||||
|
||||
# Watchtower integration for web-based updates
|
||||
- WATCHTOWER_API_URL=http://watchtower:8080
|
||||
- WATCHTOWER_API_TOKEN=your-secret-token
|
||||
# ... your existing ports/volumes ...
|
||||
|
||||
watchtower:
|
||||
image: ghcr.io/nicholas-fedor/watchtower:latest
|
||||
container_name: watchtower
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
environment:
|
||||
- WATCHTOWER_HTTP_API_UPDATE=true
|
||||
- WATCHTOWER_HTTP_API_TOKEN=your-secret-token
|
||||
- WATCHTOWER_LABEL_ENABLE=true
|
||||
- WATCHTOWER_CLEANUP=true
|
||||
```
|
||||
|
||||
{: .important }
|
||||
> Replace `your-secret-token` with a strong, unique token. The same token must be set in both the Part-DB (`WATCHTOWER_API_TOKEN`) and Watchtower (`WATCHTOWER_HTTP_API_TOKEN`) environment variables.
|
||||
|
||||
{: .info }
|
||||
> `WATCHTOWER_LABEL_ENABLE=true` ensures Watchtower only manages containers with the `com.centurylinklabs.watchtower.enable=true` label, preventing it from updating other containers on the same host.
|
||||
|
||||
Once configured, the Update Manager page will show the Watchtower connection status and provide an **Update via Watchtower** button when a new version is available. Clicking it triggers Watchtower to pull the latest image and recreate the Part-DB container automatically.
|
||||
|
||||
## Direct use of docker image
|
||||
|
||||
You can use the `jbtronics/part-db1:master` image directly. You have to expose port 80 to a host port and configure
|
||||
|
|
|
|||
27
docs/usage/ai.md
Normal file
27
docs/usage/ai.md
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
layout: default
|
||||
title: AI features
|
||||
nav_order: 6
|
||||
parent: Usage
|
||||
---
|
||||
|
||||
# AI features
|
||||
|
||||
Part-DB can utilize large language Models (LLMs) to provide AI-powered features that can assist you in managing your parts and projects.
|
||||
For now this is mostly the ability to extract part information from websites without any structured data.
|
||||
|
||||
## AI platforms
|
||||
|
||||
Part-DB is platform agnostic and can work with different AI platforms, both locally and in the cloud. They can be configured in the "AI" tab in the system settings.
|
||||
Currently, the following platforms are supported:
|
||||
|
||||
### OpenRouter
|
||||
|
||||
[OpenRouter](https://openrouter.ai/) is a platform that provides access to various LLMs, including models from OpenAI, Anthropic, and more.
|
||||
You can use OpenRouter to connect to different LLMs and use them for Part-DB's AI features.
|
||||
You need to supply an API key for OpenRouter to use it as an AI platform in Part-DB.
|
||||
|
||||
### LMStudio
|
||||
|
||||
[LMStudio](https://lmstudio.ai/) is a local LLM hosting solution that allows you to run LLMs on your own hardware. You can use LMStudio to host your own LLM and connect it to Part-DB for AI features.
|
||||
Currently only LMStudio without any authentication is supported. Supply your LMStudio instance URL (including the port) to use it as an AI platform in Part-DB.
|
||||
|
|
@ -111,6 +111,19 @@ may have privacy and security implications.
|
|||
Following env configuration options are available:
|
||||
* `PROVIDER_GENERIC_WEB_ENABLED`: Set this to `1` to enable the Generic Web URL Provider (optional, default: `0`)
|
||||
|
||||
### AI Web Extractor
|
||||
The AI web extractor provider can extract part information from any webpage using AI-based techniques. It is designed to handle unstructured data and can extract relevant information even from websites that do not use structured data formats like Schema.org.
|
||||
This provider can be particularly useful for extracting information from websites that have complex layouts or do not follow standard e-commerce practices.
|
||||
It also potentially extracts more detailed information than the Generic Web URL Provider, as it is not limited to the fields defined in the Schema.org format.
|
||||
|
||||
To use the AI Web Extractor, you need to setup an AI platform, in the AI settings tab, and chose a model, which support structured output.
|
||||
For many use cases a small and cheap model like `google/gemini-2.5-flash-lite` will be sufficient, coming down to costs like 0.001$ per request.
|
||||
For more complex websites, or if you wanna use the LLM for translation purposes too, you should consider a more powerful model.
|
||||
|
||||
You can add some additional instructions for the model, which gets added to the system prompt, to tweak the output of the model.
|
||||
|
||||
The provider will download the HTML of the given URL, convert it to markdown and send it to the LLM toghether with structured data extracted from the webpage via conventional methods.
|
||||
|
||||
### Octopart
|
||||
|
||||
The Octopart provider uses the [Octopart / Nexar API](https://nexar.com/api) to search for parts and get information.
|
||||
|
|
|
|||
|
|
@ -36,8 +36,6 @@
|
|||
"@algolia/autocomplete-js": "^1.17.0",
|
||||
"@algolia/autocomplete-plugin-recent-searches": "^1.17.0",
|
||||
"@algolia/autocomplete-theme-classic": "^1.17.0",
|
||||
"@ckeditor/ckeditor5-dev-translations": "^53",
|
||||
"@ckeditor/ckeditor5-dev-utils": "^53",
|
||||
"@jbtronics/bs-treeview": "^1.0.1",
|
||||
"@part-db/html5-qrcode": "^4.0.0",
|
||||
"@zxcvbn-ts/core": "^3.0.2",
|
||||
|
|
@ -51,7 +49,7 @@
|
|||
"bootbox": "^6.0.0",
|
||||
"bootswatch": "^5.1.3",
|
||||
"bs-custom-file-input": "^1.3.4",
|
||||
"ckeditor5": "^47.0.0",
|
||||
"ckeditor5": "^48.0.0",
|
||||
"clipboard": "^2.0.4",
|
||||
"compression-webpack-plugin": "^11.1.0",
|
||||
"datatables.net": "^2.0.0",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Generated on Mon Apr 13 05:19:27 UTC 2026
|
||||
# Generated on Mon May 4 05:40:05 UTC 2026
|
||||
# This file contains all footprints available in the offical KiCAD library
|
||||
Audio_Module:Reverb_BTDR-1H
|
||||
Audio_Module:Reverb_BTDR-1V
|
||||
|
|
@ -8366,6 +8366,7 @@ Converter_DCDC:Converter_DCDC_TRACO_TMR-1SM_SMD
|
|||
Converter_DCDC:Converter_DCDC_TRACO_TMR10-24xxWIR_48xxWIR_72xxWIR_THT
|
||||
Converter_DCDC:Converter_DCDC_TRACO_TMR2-xxxxWI_THT
|
||||
Converter_DCDC:Converter_DCDC_TRACO_TMR4-xxxxWI_THT
|
||||
Converter_DCDC:Converter_DCDC_TRACO_TMR8-xxxxWI_THT
|
||||
Converter_DCDC:Converter_DCDC_TRACO_TMU3-05xx_12xx_THT
|
||||
Converter_DCDC:Converter_DCDC_TRACO_TMU3-24xx_THT
|
||||
Converter_DCDC:Converter_DCDC_TRACO_TMV-051xD_121xD_Dual_THT
|
||||
|
|
@ -11978,6 +11979,8 @@ Package_DFN_QFN:VQFN-48-1EP_7x7mm_P0.5mm_EP4.2x4.2mm
|
|||
Package_DFN_QFN:VQFN-48-1EP_7x7mm_P0.5mm_EP4.2x4.2mm_ThermalVias
|
||||
Package_DFN_QFN:VQFN-48-1EP_7x7mm_P0.5mm_EP5.15x5.15mm
|
||||
Package_DFN_QFN:VQFN-48-1EP_7x7mm_P0.5mm_EP5.15x5.15mm_ThermalVias
|
||||
Package_DFN_QFN:VQFN-52-1EP_6x6mm_P0.4mm_EP4.7x4.7mm
|
||||
Package_DFN_QFN:VQFN-52-1EP_6x6mm_P0.4mm_EP4.7x4.7mm_ThermalVias
|
||||
Package_DFN_QFN:VQFN-56-1EP_8x8mm_P0.5mm_EP5.1x4.96mm
|
||||
Package_DFN_QFN:VQFN-56-1EP_8x8mm_P0.5mm_EP5.1x4.96mm_ThermalVias
|
||||
Package_DFN_QFN:VQFN-56-1EP_8x8mm_P0.5mm_EP5.5x5.06mm
|
||||
|
|
@ -12028,6 +12031,8 @@ Package_DFN_QFN:WQFN-24-1EP_4x4mm_P0.5mm_EP2.45x2.45mm
|
|||
Package_DFN_QFN:WQFN-24-1EP_4x4mm_P0.5mm_EP2.45x2.45mm_ThermalVias
|
||||
Package_DFN_QFN:WQFN-24-1EP_4x4mm_P0.5mm_EP2.6x2.6mm
|
||||
Package_DFN_QFN:WQFN-24-1EP_4x4mm_P0.5mm_EP2.6x2.6mm_ThermalVias
|
||||
Package_DFN_QFN:WQFN-28-1EP_3.5x5.5mm_P0.5mm_EP2.05x4.05mm
|
||||
Package_DFN_QFN:WQFN-28-1EP_3.5x5.5mm_P0.5mm_EP2.05x4.05mm_ThermalVias
|
||||
Package_DFN_QFN:WQFN-28-1EP_4x4mm_P0.4mm_EP2.7x2.7mm
|
||||
Package_DFN_QFN:WQFN-28-1EP_4x4mm_P0.4mm_EP2.7x2.7mm_ThermalVias
|
||||
Package_DFN_QFN:WQFN-32-1EP_5x5mm_P0.5mm_EP3.1x3.1mm
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Generated on Mon Apr 13 05:20:06 UTC 2026
|
||||
# Generated on Mon May 4 05:40:43 UTC 2026
|
||||
# This file contains all symbols available in the offical KiCAD library
|
||||
4xxx:14528
|
||||
4xxx:14529
|
||||
|
|
@ -8845,6 +8845,7 @@ Interface_USB:CH343G
|
|||
Interface_USB:CH343P
|
||||
Interface_USB:CH344Q
|
||||
Interface_USB:CH9102F
|
||||
Interface_USB:CP2102C-Axx-xQFN24
|
||||
Interface_USB:CP2102N-Axx-xQFN20
|
||||
Interface_USB:CP2102N-Axx-xQFN24
|
||||
Interface_USB:CP2102N-Axx-xQFN28
|
||||
|
|
|
|||
|
|
@ -229,24 +229,37 @@ class DBPlatformConvertCommand extends Command
|
|||
|
||||
if ($platform instanceof PostgreSQLPlatform) {
|
||||
$connection->executeStatement(
|
||||
//From: https://wiki.postgresql.org/wiki/Fixing_Sequences
|
||||
//See https://github.com/Part-DB/Part-DB-server/issues/1362
|
||||
<<<SQL
|
||||
SELECT 'SELECT SETVAL(' ||
|
||||
quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) ||
|
||||
', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' ||
|
||||
quote_ident(PGT.schemaname)|| '.'||quote_ident(T.relname)|| ';'
|
||||
FROM pg_class AS S,
|
||||
pg_depend AS D,
|
||||
pg_class AS T,
|
||||
pg_attribute AS C,
|
||||
pg_tables AS PGT
|
||||
WHERE S.relkind = 'S'
|
||||
AND S.oid = D.objid
|
||||
AND D.refobjid = T.oid
|
||||
AND D.refobjid = C.attrelid
|
||||
AND D.refobjsubid = C.attnum
|
||||
AND T.relname = PGT.tablename
|
||||
ORDER BY S.relname;
|
||||
DO $$
|
||||
DECLARE
|
||||
rec RECORD;
|
||||
max_id BIGINT;
|
||||
seq TEXT;
|
||||
BEGIN
|
||||
FOR rec IN
|
||||
SELECT c.table_name
|
||||
FROM information_schema.columns c
|
||||
JOIN pg_tables t
|
||||
ON t.tablename = c.table_name AND t.schemaname = 'public'
|
||||
WHERE c.column_name = 'id'
|
||||
AND c.table_schema = 'public'
|
||||
LOOP
|
||||
BEGIN
|
||||
seq := pg_get_serial_sequence(rec.table_name, 'id');
|
||||
IF seq IS NOT NULL THEN
|
||||
EXECUTE format('SELECT MAX(id) FROM %I', rec.table_name) INTO max_id;
|
||||
IF max_id IS NOT NULL THEN
|
||||
PERFORM setval(seq, max_id);
|
||||
RAISE NOTICE 'Reset: %.id → %', rec.table_name, max_id;
|
||||
END IF;
|
||||
END IF;
|
||||
EXCEPTION WHEN OTHERS THEN
|
||||
RAISE NOTICE 'Skipped %: %', rec.table_name, SQLERRM;
|
||||
END;
|
||||
END LOOP;
|
||||
END;
|
||||
$$;
|
||||
SQL);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ use App\Entity\Base\PartsContainingRepositoryInterface;
|
|||
use App\Entity\LabelSystem\LabelProcessMode;
|
||||
use App\Entity\LabelSystem\LabelProfile;
|
||||
use App\Entity\Parameters\AbstractParameter;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Exceptions\AttachmentDownloadException;
|
||||
use App\Exceptions\TwigModeException;
|
||||
use App\Form\AdminPages\ImportType;
|
||||
|
|
@ -196,7 +197,9 @@ abstract class BaseAdminController extends AbstractController
|
|||
$this->commentHelper->setMessage($form['log_comment']->getData());
|
||||
|
||||
//In principle, the form should be disabled, if the edit permission is not granted, but for good measure, we also check it here, before saving changes.
|
||||
$this->denyAccessUnlessGranted('edit', $entity);
|
||||
if (!$entity instanceof User) { //Users entities does not have a simple edit permission, so we skip the check for them
|
||||
$this->denyAccessUnlessGranted('edit', $entity);
|
||||
}
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
$this->addFlash('success', 'entity.edit_flash');
|
||||
|
|
|
|||
|
|
@ -29,11 +29,14 @@ use App\Entity\Parts\Part;
|
|||
use App\Entity\Parts\Supplier;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Form\InfoProviderSystem\GlobalFieldMappingType;
|
||||
use App\Services\EntityMergers\Mergers\PartMerger;
|
||||
use App\Services\InfoProviderSystem\BulkInfoProviderService;
|
||||
use App\Services\InfoProviderSystem\DTOs\BulkSearchFieldMappingDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\BulkSearchPartResultsDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\BulkSearchResponseDTO;
|
||||
use App\Services\InfoProviderSystem\PartInfoRetriever;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\ORMInvalidArgumentException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
|
|
@ -66,6 +69,10 @@ class BulkInfoProviderImportController extends AbstractController
|
|||
{
|
||||
$dtos = [];
|
||||
foreach ($fieldMappings as $mapping) {
|
||||
// Skip entries where field is null/empty (e.g. user added a row but didn't select a field)
|
||||
if (empty($mapping['field'])) {
|
||||
continue;
|
||||
}
|
||||
$dtos[] = new BulkSearchFieldMappingDTO(field: $mapping['field'], providers: $mapping['providers'], priority: $mapping['priority'] ?? 1);
|
||||
}
|
||||
return $dtos;
|
||||
|
|
@ -276,8 +283,8 @@ class BulkInfoProviderImportController extends AbstractController
|
|||
$updatedJobs = true;
|
||||
}
|
||||
|
||||
// Mark jobs with no results for deletion (failed searches)
|
||||
if ($job->getResultCount() === 0 && $job->isInProgress()) {
|
||||
// Mark jobs with no results for deletion (failed searches or stale pending)
|
||||
if ($job->getResultCount() === 0 && ($job->isInProgress() || $job->isPending())) {
|
||||
$jobsToDelete[] = $job;
|
||||
}
|
||||
}
|
||||
|
|
@ -297,9 +304,23 @@ class BulkInfoProviderImportController extends AbstractController
|
|||
}
|
||||
}
|
||||
|
||||
// Refetch after cleanup and split into active vs finished
|
||||
$allJobs = $this->entityManager->getRepository(BulkInfoProviderImportJob::class)
|
||||
->findBy([], ['createdAt' => 'DESC']);
|
||||
|
||||
$activeJobs = [];
|
||||
$finishedJobs = [];
|
||||
foreach ($allJobs as $job) {
|
||||
if ($job->isCompleted() || $job->isFailed() || $job->isStopped()) {
|
||||
$finishedJobs[] = $job;
|
||||
} else {
|
||||
$activeJobs[] = $job;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('info_providers/bulk_import/manage.html.twig', [
|
||||
'jobs' => $this->entityManager->getRepository(BulkInfoProviderImportJob::class)
|
||||
->findBy([], ['createdAt' => 'DESC']) // Refetch after cleanup
|
||||
'active_jobs' => $activeJobs,
|
||||
'finished_jobs' => $finishedJobs,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -470,22 +491,13 @@ class BulkInfoProviderImportController extends AbstractController
|
|||
$fieldMappingDtos = $job->getFieldMappings();
|
||||
$prefetchDetails = $job->isPrefetchDetails();
|
||||
|
||||
try {
|
||||
$searchResultsDto = $this->bulkService->performBulkSearch([$part], $fieldMappingDtos, $prefetchDetails);
|
||||
} catch (\Exception $searchException) {
|
||||
// Handle "no search results found" as a normal case, not an error
|
||||
if (str_contains($searchException->getMessage(), 'No search results found')) {
|
||||
$searchResultsDto = null;
|
||||
} else {
|
||||
throw $searchException;
|
||||
}
|
||||
}
|
||||
$searchResultsDto = $this->bulkService->performBulkSearch([$part], $fieldMappingDtos, $prefetchDetails);
|
||||
|
||||
// Update the job's search results for this specific part efficiently
|
||||
$this->updatePartSearchResults($job, $searchResultsDto[0] ?? null);
|
||||
|
||||
// Prefetch details if requested
|
||||
if ($prefetchDetails && $searchResultsDto !== null) {
|
||||
if ($prefetchDetails) {
|
||||
$this->bulkService->prefetchDetailsForResults($searchResultsDto);
|
||||
}
|
||||
|
||||
|
|
@ -515,6 +527,191 @@ class BulkInfoProviderImportController extends AbstractController
|
|||
}
|
||||
}
|
||||
|
||||
#[Route('/job/{jobId}/part/{partId}/quick-apply', name: 'bulk_info_provider_quick_apply', methods: ['POST'])]
|
||||
public function quickApply(
|
||||
int $jobId,
|
||||
int $partId,
|
||||
Request $request,
|
||||
PartInfoRetriever $infoRetriever,
|
||||
PartMerger $partMerger
|
||||
): JsonResponse {
|
||||
$job = $this->validateJobAccess($jobId);
|
||||
if (!$job) {
|
||||
return $this->createErrorResponse('Job not found or access denied', 404, ['job_id' => $jobId]);
|
||||
}
|
||||
|
||||
/** @var Part $part */
|
||||
$part = $this->entityManager->getRepository(Part::class)->find($partId);
|
||||
if (!$part) {
|
||||
return $this->createErrorResponse('Part not found', 404, ['part_id' => $partId]);
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('edit', $part);
|
||||
|
||||
// Get provider key/id from request body, or fall back to top search result
|
||||
$body = $request->toArray();
|
||||
$providerKey = $body['providerKey'] ?? null;
|
||||
$providerId = $body['providerId'] ?? null;
|
||||
|
||||
if (!$providerKey || !$providerId) {
|
||||
$searchResults = $job->getSearchResults($this->entityManager);
|
||||
foreach ($searchResults->partResults as $partResult) {
|
||||
if ($partResult->part->getId() === $partId) {
|
||||
$sorted = $partResult->getResultsSortedByPriority();
|
||||
if (!empty($sorted)) {
|
||||
$providerKey = $sorted[0]->searchResult->provider_key;
|
||||
$providerId = $sorted[0]->searchResult->provider_id;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$providerKey || !$providerId) {
|
||||
return $this->createErrorResponse('No search result available for this part', 400, ['part_id' => $partId]);
|
||||
}
|
||||
|
||||
try {
|
||||
$dto = $infoRetriever->getDetails($providerKey, $providerId);
|
||||
$providerPart = $infoRetriever->dtoToPart($dto);
|
||||
$partMerger->merge($part, $providerPart);
|
||||
|
||||
//Persist part manufacturer and supplier if they are new, to avoid issues with detached entities during merge
|
||||
//Do not footprints here, as it might pollute the database with unwanted formatting footprints from the provider,
|
||||
$this->entityManager->persist($part->getManufacturer());
|
||||
foreach ($part->getOrderdetails() as $orderdetail) {
|
||||
$this->entityManager->persist($orderdetail->getSupplier());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->entityManager->flush();
|
||||
} catch (ORMInvalidArgumentException $exception) {
|
||||
if (str_contains($exception->getMessage(), 'not configured to cascade persist operations')) {
|
||||
throw new \RuntimeException('Failed to persist merged part, as it would create new datastructures! Review the provider data by yourself.');
|
||||
}
|
||||
|
||||
throw $exception; // Re-throw if it's a different ORM error
|
||||
}
|
||||
|
||||
$job->markPartAsCompleted($partId);
|
||||
if ($job->isAllPartsCompleted() && !$job->isCompleted()) {
|
||||
$job->markAsCompleted();
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
|
||||
return $this->json([
|
||||
'success' => true,
|
||||
'message' => sprintf('Applied provider data to "%s"', $part->getName()),
|
||||
'part_id' => $partId,
|
||||
'provider_key' => $providerKey,
|
||||
'provider_id' => $providerId,
|
||||
'progress' => $job->getProgressPercentage(),
|
||||
'completed_count' => $job->getCompletedPartsCount(),
|
||||
'total_count' => $job->getPartCount(),
|
||||
'job_completed' => $job->isCompleted(),
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error($e);
|
||||
|
||||
return $this->createErrorResponse(
|
||||
'Quick apply failed: ' . $e->getMessage(),
|
||||
500,
|
||||
['job_id' => $jobId, 'part_id' => $partId, 'exception' => $e->getMessage()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[Route('/job/{jobId}/quick-apply-all', name: 'bulk_info_provider_quick_apply_all', methods: ['POST'])]
|
||||
public function quickApplyAll(
|
||||
int $jobId,
|
||||
PartInfoRetriever $infoRetriever,
|
||||
PartMerger $partMerger
|
||||
): JsonResponse {
|
||||
set_time_limit(600);
|
||||
|
||||
$job = $this->validateJobAccess($jobId);
|
||||
if (!$job) {
|
||||
return $this->createErrorResponse('Job not found or access denied', 404, ['job_id' => $jobId]);
|
||||
}
|
||||
|
||||
$searchResults = $job->getSearchResults($this->entityManager);
|
||||
$applied = 0;
|
||||
$failed = 0;
|
||||
$noResults = 0;
|
||||
$errors = [];
|
||||
|
||||
foreach ($job->getJobParts() as $jobPart) {
|
||||
if ($jobPart->isCompleted() || $jobPart->isSkipped()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$part = $jobPart->getPart();
|
||||
|
||||
if (!$this->isGranted('edit', $part)) {
|
||||
$errors[] = sprintf('No edit permission for "%s"', $part->getName());
|
||||
$failed++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find top search result for this part
|
||||
$providerKey = null;
|
||||
$providerId = null;
|
||||
foreach ($searchResults->partResults as $partResult) {
|
||||
if ($partResult->part->getId() === $part->getId()) {
|
||||
$sorted = $partResult->getResultsSortedByPriority();
|
||||
if (!empty($sorted)) {
|
||||
$providerKey = $sorted[0]->searchResult->provider_key;
|
||||
$providerId = $sorted[0]->searchResult->provider_id;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$providerKey || !$providerId) {
|
||||
$noResults++;
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$dto = $infoRetriever->getDetails($providerKey, $providerId);
|
||||
$providerPart = $infoRetriever->dtoToPart($dto);
|
||||
$partMerger->merge($part, $providerPart);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$job->markPartAsCompleted($part->getId());
|
||||
$applied++;
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('Quick apply failed for part', [
|
||||
'part_id' => $part->getId(),
|
||||
'part_name' => $part->getName(),
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
$errors[] = sprintf('Failed for "%s": %s', $part->getName(), $e->getMessage());
|
||||
$failed++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($job->isAllPartsCompleted() && !$job->isCompleted()) {
|
||||
$job->markAsCompleted();
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->json([
|
||||
'success' => true,
|
||||
'applied' => $applied,
|
||||
'failed' => $failed,
|
||||
'no_results' => $noResults,
|
||||
'errors' => $errors,
|
||||
'message' => sprintf('Applied to %d parts, %d failed, %d had no results', $applied, $failed, $noResults),
|
||||
'progress' => $job->getProgressPercentage(),
|
||||
'completed_count' => $job->getCompletedPartsCount(),
|
||||
'total_count' => $job->getPartCount(),
|
||||
'job_completed' => $job->isCompleted(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/job/{jobId}/research-all', name: 'bulk_info_provider_research_all', methods: ['POST'])]
|
||||
public function researchAllParts(int $jobId): JsonResponse
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,11 +26,14 @@ namespace App\Controller;
|
|||
use App\Entity\Parts\Manufacturer;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Exceptions\OAuthReconnectRequiredException;
|
||||
use App\Form\InfoProviderSystem\FromURLFormType;
|
||||
use App\Form\InfoProviderSystem\PartSearchType;
|
||||
use App\Services\InfoProviderSystem\ExistingPartFinder;
|
||||
use App\Services\InfoProviderSystem\CreateFromUrlHelper;
|
||||
use App\Services\InfoProviderSystem\PartInfoRetriever;
|
||||
use App\Services\InfoProviderSystem\ProviderRegistry;
|
||||
use App\Services\InfoProviderSystem\Providers\GenericWebProvider;
|
||||
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
|
||||
use App\Settings\AppSettings;
|
||||
use App\Settings\InfoProviderSystem\InfoProviderGeneralSettings;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
|
@ -172,10 +175,15 @@ class InfoProviderController extends AbstractController
|
|||
$keyword = $form->get('keyword')->getData();
|
||||
$providers = $form->get('providers')->getData();
|
||||
|
||||
$no_cache_search = $form->get('no_cache_search')->getData();
|
||||
$no_cache_details = $form->get('no_cache_details')->getData();
|
||||
|
||||
$dtos = [];
|
||||
|
||||
try {
|
||||
$dtos = $this->infoRetriever->searchByKeyword(keyword: $keyword, providers: $providers);
|
||||
$dtos = $this->infoRetriever->searchByKeyword(keyword: $keyword, providers: $providers, options: [
|
||||
InfoProviderInterface::OPTION_NO_CACHE => $no_cache_search
|
||||
]);
|
||||
} catch (ClientException $e) {
|
||||
$this->addFlash('error', t('info_providers.search.error.client_exception'));
|
||||
$this->addFlash('error',$e->getMessage());
|
||||
|
|
@ -207,40 +215,41 @@ class InfoProviderController extends AbstractController
|
|||
return $this->render('info_providers/search/part_search.html.twig', [
|
||||
'form' => $form,
|
||||
'results' => $results,
|
||||
'update_target' => $update_target
|
||||
'update_target' => $update_target,
|
||||
'no_cache_details' => $no_cache_details ?? false,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/from_url', name: 'info_providers_from_url')]
|
||||
public function fromURL(Request $request, GenericWebProvider $provider): Response
|
||||
public function fromURL(Request $request, GenericWebProvider $provider, CreateFromUrlHelper $fromUrlHelper): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('@info_providers.create_parts');
|
||||
|
||||
if (!$provider->isActive()) {
|
||||
if (!$fromUrlHelper->canCreateFromUrl()) {
|
||||
$this->addFlash('error', "Generic Web Provider is not active. Please enable it in the provider settings.");
|
||||
return $this->redirectToRoute('info_providers_list');
|
||||
}
|
||||
|
||||
$formBuilder = $this->createFormBuilder();
|
||||
$formBuilder->add('url', UrlType::class, [
|
||||
'label' => 'info_providers.from_url.url.label',
|
||||
'required' => true,
|
||||
]);
|
||||
$formBuilder->add('submit', SubmitType::class, [
|
||||
'label' => 'info_providers.search.submit',
|
||||
]);
|
||||
|
||||
$form = $formBuilder->getForm();
|
||||
$form = $this->createForm(FromURLFormType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
$partDetail = null;
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
//Try to retrieve the part detail from the given URL
|
||||
$url = $form->get('url')->getData();
|
||||
|
||||
$method = $form->get('method')->getData();
|
||||
$no_cache = $form->get('no_cache')->getData();
|
||||
$skip_delegation = $form->get('skip_delegation')->getData();
|
||||
|
||||
try {
|
||||
//It's okay if we use the cached results here, as its just for convenience
|
||||
$searchResult = $this->infoRetriever->searchByKeyword(
|
||||
keyword: $url,
|
||||
providers: [$provider]
|
||||
providers: [$method],
|
||||
options: [
|
||||
InfoProviderInterface::OPTION_SKIP_DELEGATION => $skip_delegation,
|
||||
]
|
||||
);
|
||||
|
||||
if (count($searchResult) === 0) {
|
||||
|
|
@ -251,6 +260,8 @@ class InfoProviderController extends AbstractController
|
|||
return $this->redirectToRoute('info_providers_create_part', [
|
||||
'providerKey' => $searchResult->provider_key,
|
||||
'providerId' => $searchResult->provider_id,
|
||||
'no_cache' => $no_cache ? 1 : null,
|
||||
'skip_delegation' => $skip_delegation ? 1 : null,
|
||||
]);
|
||||
}
|
||||
} catch (ExceptionInterface $e) {
|
||||
|
|
|
|||
|
|
@ -36,10 +36,12 @@ use App\Entity\PriceInformations\Orderdetail;
|
|||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Exceptions\AttachmentDownloadException;
|
||||
use App\Form\Part\PartBaseType;
|
||||
use App\Form\Part\PartLotType;
|
||||
use App\Services\Attachments\AttachmentSubmitHandler;
|
||||
use App\Services\Attachments\PartPreviewGenerator;
|
||||
use App\Services\EntityMergers\Mergers\PartMerger;
|
||||
use App\Services\InfoProviderSystem\PartInfoRetriever;
|
||||
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
|
||||
use App\Services\LogSystem\EventCommentHelper;
|
||||
use App\Services\LogSystem\HistoryHelper;
|
||||
use App\Services\LogSystem\TimeTravel;
|
||||
|
|
@ -127,6 +129,17 @@ final class PartController extends AbstractController
|
|||
$table = null;
|
||||
}
|
||||
|
||||
// Build the add-lot form for the INFO page modal (only when not in time-travel mode)
|
||||
$addLotForm = null;
|
||||
if ($timeTravel_timestamp === null && $this->isGranted('edit', $part)) {
|
||||
$newLot = new PartLot();
|
||||
$newLot->setPart($part);
|
||||
$addLotForm = $this->createForm(PartLotType::class, $newLot, [
|
||||
'measurement_unit' => $part->getPartUnit(),
|
||||
'action' => $this->generateUrl('part_lot_add', ['id' => $part->getID()]),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'parts/info/show_part_info.html.twig',
|
||||
[
|
||||
|
|
@ -139,10 +152,39 @@ final class PartController extends AbstractController
|
|||
'comment_params' => $this->partInfoSettings->extractParamsFromNotes ? $parameterExtractor->extractParameters($part->getComment()) : [],
|
||||
'withdraw_add_helper' => $withdrawAddHelper,
|
||||
'highlightLotId' => $request->query->getInt('highlightLot', 0),
|
||||
'add_lot_form' => $addLotForm,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[Route(path: '/{id}/add_lot', name: 'part_lot_add', methods: ['POST'])]
|
||||
public function addLot(Part $part, Request $request, EntityManagerInterface $em): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('edit', $part);
|
||||
|
||||
$newLot = new PartLot();
|
||||
$newLot->setPart($part);
|
||||
|
||||
$form = $this->createForm(PartLotType::class, $newLot, [
|
||||
'measurement_unit' => $part->getPartUnit(),
|
||||
]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em->persist($newLot);
|
||||
$em->flush();
|
||||
$this->addFlash('success', 'part.edited_flash');
|
||||
return $this->redirectToRoute('part_info', [
|
||||
'id' => $part->getID(),
|
||||
'highlightLot' => $newLot->getID(),
|
||||
]);
|
||||
}
|
||||
|
||||
$this->addFlash('error', 'part.created_flash.invalid');
|
||||
return $this->redirectToRoute('part_info', ['id' => $part->getID()]);
|
||||
}
|
||||
|
||||
#[Route(path: '/{id}/edit', name: 'part_edit')]
|
||||
public function edit(Part $part, Request $request): Response
|
||||
{
|
||||
|
|
@ -283,7 +325,14 @@ final class PartController extends AbstractController
|
|||
{
|
||||
$this->denyAccessUnlessGranted('@info_providers.create_parts');
|
||||
|
||||
$dto = $infoRetriever->getDetails($providerKey, $providerId);
|
||||
//Force info providers to not use cache, when retrieving part details for creating a new part, because otherwise we might end up with outdated information
|
||||
$no_cache = $request->query->getBoolean('no_cache', false);
|
||||
$skip_delegation = $request->query->getBoolean('skip_delegation', false);
|
||||
|
||||
$dto = $infoRetriever->getDetails($providerKey, $providerId, [
|
||||
InfoProviderInterface::OPTION_NO_CACHE => $no_cache,
|
||||
InfoProviderInterface::OPTION_SKIP_DELEGATION => $skip_delegation,
|
||||
]);
|
||||
$new_part = $infoRetriever->dtoToPart($dto);
|
||||
|
||||
if ($new_part->getCategory() === null || $new_part->getCategory()->getID() === null) {
|
||||
|
|
@ -342,10 +391,13 @@ final class PartController extends AbstractController
|
|||
$this->denyAccessUnlessGranted('edit', $part);
|
||||
$this->denyAccessUnlessGranted('@info_providers.create_parts');
|
||||
|
||||
//Force info providers to not use cache, when retrieving part details for creating a new part, because otherwise we might end up with outdated information
|
||||
$no_cache = $request->query->getBoolean('no_cache', false);
|
||||
|
||||
//Save the old name of the target part for the template
|
||||
$old_name = $part->getName();
|
||||
|
||||
$dto = $infoRetriever->getDetails($providerKey, $providerId);
|
||||
$dto = $infoRetriever->getDetails($providerKey, $providerId, [InfoProviderInterface::OPTION_NO_CACHE => $no_cache]);
|
||||
$provider_part = $infoRetriever->dtoToPart($dto);
|
||||
|
||||
$part = $partMerger->merge($part, $provider_part);
|
||||
|
|
|
|||
|
|
@ -22,38 +22,43 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Parameters\AbstractParameter;
|
||||
use App\Settings\MiscSettings\IpnSuggestSettings;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Parts\Category;
|
||||
use App\Entity\Parts\Footprint;
|
||||
use App\Entity\Parameters\AbstractParameter;
|
||||
use App\Entity\Parameters\AttachmentTypeParameter;
|
||||
use App\Entity\Parameters\CategoryParameter;
|
||||
use App\Entity\Parameters\ProjectParameter;
|
||||
use App\Entity\Parameters\FootprintParameter;
|
||||
use App\Entity\Parameters\GroupParameter;
|
||||
use App\Entity\Parameters\ManufacturerParameter;
|
||||
use App\Entity\Parameters\MeasurementUnitParameter;
|
||||
use App\Entity\Parameters\PartParameter;
|
||||
use App\Entity\Parameters\ProjectParameter;
|
||||
use App\Entity\Parameters\StorageLocationParameter;
|
||||
use App\Entity\Parameters\SupplierParameter;
|
||||
use App\Entity\Parts\Category;
|
||||
use App\Entity\Parts\Footprint;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\PriceInformations\Currency;
|
||||
use App\Repository\ParameterRepository;
|
||||
use App\Services\AI\AIPlatformRegistry;
|
||||
use App\Services\AI\AIPlatforms;
|
||||
use App\Services\Attachments\AttachmentURLGenerator;
|
||||
use App\Services\Attachments\BuiltinAttachmentsFinder;
|
||||
use App\Services\Attachments\PartPreviewGenerator;
|
||||
use App\Services\Tools\TagFinder;
|
||||
use App\Settings\MiscSettings\IpnSuggestSettings;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\AI\Platform\Capability;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Asset\Packages;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
|
||||
/**
|
||||
* In this controller the endpoints for the typeaheads are collected.
|
||||
|
|
@ -121,9 +126,12 @@ class TypeaheadController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route(path: '/parts/search/{query}', name: 'typeahead_parts')]
|
||||
public function parts(EntityManagerInterface $entityManager, PartPreviewGenerator $previewGenerator,
|
||||
AttachmentURLGenerator $attachmentURLGenerator, string $query = ""): JsonResponse
|
||||
{
|
||||
public function parts(
|
||||
EntityManagerInterface $entityManager,
|
||||
PartPreviewGenerator $previewGenerator,
|
||||
AttachmentURLGenerator $attachmentURLGenerator,
|
||||
string $query = ""
|
||||
): JsonResponse {
|
||||
$this->denyAccessUnlessGranted('@parts.read');
|
||||
|
||||
$repo = $entityManager->getRepository(Part::class);
|
||||
|
|
@ -134,7 +142,7 @@ class TypeaheadController extends AbstractController
|
|||
foreach ($parts as $part) {
|
||||
//Determine the picture to show:
|
||||
$preview_attachment = $previewGenerator->getTablePreviewAttachment($part);
|
||||
if($preview_attachment instanceof Attachment) {
|
||||
if ($preview_attachment instanceof Attachment) {
|
||||
$preview_url = $attachmentURLGenerator->getThumbnailURL($preview_attachment, 'thumbnail_sm');
|
||||
} else {
|
||||
$preview_url = '';
|
||||
|
|
@ -148,7 +156,7 @@ class TypeaheadController extends AbstractController
|
|||
'footprint' => $part->getFootprint() instanceof Footprint ? $part->getFootprint()->getName() : '',
|
||||
'description' => mb_strimwidth($part->getDescription(), 0, 127, '...'),
|
||||
'image' => $preview_url,
|
||||
];
|
||||
];
|
||||
}
|
||||
|
||||
return new JsonResponse($data);
|
||||
|
|
@ -219,8 +227,36 @@ class TypeaheadController extends AbstractController
|
|||
|
||||
|
||||
$partRepository = $entityManager->getRepository(Part::class);
|
||||
$ipnSuggestions = $partRepository->autoCompleteIpn($clonedPart, $description, $this->ipnSuggestSettings->suggestPartDigits);
|
||||
$ipnSuggestions = $partRepository->autoCompleteIpn($clonedPart, $description,
|
||||
$this->ipnSuggestSettings->suggestPartDigits);
|
||||
|
||||
return new JsonResponse($ipnSuggestions);
|
||||
}
|
||||
|
||||
#[Route(path: '/ai/{platform}/models', name: 'typeahead_ai_models', requirements: ['platform' => '.+'])]
|
||||
public function aiModels(
|
||||
AIPlatforms $platform,
|
||||
Request $request,
|
||||
AIPlatformRegistry $platformRegistry,
|
||||
CacheInterface $cache,
|
||||
): JsonResponse {
|
||||
$this->denyAccessUnlessGranted('@config.change_system_settings');
|
||||
|
||||
$capability_filter = $request->query->getEnum('capability', Capability::class);
|
||||
|
||||
$models = $cache->get('ai_models_'.$platform->value.'_'.($capability_filter->value ?? 'all'),
|
||||
function (ItemInterface $item) use ($platformRegistry, $platform, $capability_filter) {
|
||||
$item->expiresAfter(3600); //Cache for 1 hour
|
||||
if ($capability_filter === null) {
|
||||
return $platformRegistry->getPlatform($platform)->getModelCatalog()->getModels();
|
||||
}
|
||||
|
||||
//Otherwise filter the models by the capability
|
||||
return array_filter($platformRegistry->getPlatform($platform)->getModelCatalog()->getModels(),
|
||||
static fn(array $model) => in_array($capability_filter, $model['capabilities'], true)
|
||||
);
|
||||
});
|
||||
|
||||
return new JsonResponse($models);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ use App\Services\System\BackupManager;
|
|||
use App\Services\System\InstallationTypeDetector;
|
||||
use App\Services\System\UpdateChecker;
|
||||
use App\Services\System\UpdateExecutor;
|
||||
use App\Services\System\WatchtowerClient;
|
||||
use Shivas\VersioningBundle\Service\VersionManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
|
|
@ -56,6 +57,7 @@ class UpdateManagerController extends AbstractController
|
|||
private readonly BackupManager $backupManager,
|
||||
private readonly InstallationTypeDetector $installationTypeDetector,
|
||||
private readonly UserPasswordHasherInterface $passwordHasher,
|
||||
private readonly WatchtowerClient $watchtowerClient,
|
||||
#[Autowire(env: 'bool:DISABLE_WEB_UPDATES')]
|
||||
private readonly bool $webUpdatesDisabled = false,
|
||||
#[Autowire(env: 'bool:DISABLE_BACKUP_RESTORE')]
|
||||
|
|
@ -504,4 +506,100 @@ class UpdateManagerController extends AbstractController
|
|||
|
||||
return $this->redirectToRoute('admin_update_manager');
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a Docker update via Watchtower.
|
||||
*/
|
||||
#[Route('/start-docker', name: 'admin_update_manager_start_docker', methods: ['POST'])]
|
||||
public function startDockerUpdate(Request $request): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
|
||||
$this->denyAccessUnlessGranted('@system.manage_updates');
|
||||
$this->denyIfWebUpdatesDisabled();
|
||||
|
||||
// Validate CSRF token
|
||||
if (!$this->isCsrfTokenValid('update_manager_start_docker', $request->request->get('_token'))) {
|
||||
$this->addFlash('error', 'Invalid CSRF token');
|
||||
return $this->redirectToRoute('admin_update_manager');
|
||||
}
|
||||
|
||||
// Check if Watchtower is configured and available
|
||||
if (!$this->watchtowerClient->isConfigured()) {
|
||||
$this->addFlash('error', 'Watchtower is not configured. Please set WATCHTOWER_API_URL and WATCHTOWER_API_TOKEN.');
|
||||
return $this->redirectToRoute('admin_update_manager');
|
||||
}
|
||||
|
||||
if (!$this->watchtowerClient->isAvailable()) {
|
||||
$this->addFlash('error', 'Watchtower is not reachable. Please check that the Watchtower container is running and accessible.');
|
||||
return $this->redirectToRoute('admin_update_manager');
|
||||
}
|
||||
|
||||
// Create backup if requested
|
||||
$createBackup = $request->request->getBoolean('backup', true);
|
||||
if ($createBackup) {
|
||||
try {
|
||||
$this->backupManager->createBackup();
|
||||
} catch (\Throwable $e) {
|
||||
$this->addFlash('error', 'Failed to create backup before update: ' . $e->getMessage());
|
||||
return $this->redirectToRoute('admin_update_manager');
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger Watchtower update
|
||||
$success = $this->watchtowerClient->triggerUpdate();
|
||||
|
||||
if (!$success) {
|
||||
$this->addFlash('error', 'Failed to trigger Watchtower update. Check the logs for details.');
|
||||
return $this->redirectToRoute('admin_update_manager');
|
||||
}
|
||||
|
||||
$currentVersion = $this->versionManager->getVersion()->toString();
|
||||
|
||||
// Redirect to Docker progress page
|
||||
return $this->redirectToRoute('admin_update_manager_docker_progress', [
|
||||
'previous_version' => $currentVersion,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Docker update progress page.
|
||||
* This page contains client-side JavaScript that polls until the container restarts.
|
||||
*/
|
||||
#[Route('/progress/docker', name: 'admin_update_manager_docker_progress', methods: ['GET'])]
|
||||
public function dockerProgress(Request $request): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('@system.manage_updates');
|
||||
|
||||
$previousVersion = $request->query->get('previous_version', 'unknown');
|
||||
|
||||
return $this->render('admin/update_manager/docker_progress.html.twig', [
|
||||
'previous_version' => $previousVersion,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lightweight health check endpoint used by Docker update progress page.
|
||||
* Returns current version so the client-side JS can detect when the container restarts with a new version.
|
||||
*
|
||||
* Intentionally unauthenticated: after a Docker container restart, the user's session may not survive
|
||||
* (depends on session storage backend). The version string is non-sensitive public information.
|
||||
* This endpoint is also whitelisted in MaintenanceModeSubscriber.
|
||||
*/
|
||||
#[Route('/health', name: 'admin_update_manager_health', methods: ['GET'])]
|
||||
public function healthCheck(): JsonResponse
|
||||
{
|
||||
//Only show version if user is logged in and has permission
|
||||
|
||||
$response = [
|
||||
'status' => 'ok',
|
||||
];
|
||||
|
||||
if ($this->isGranted('@system.show_updates')) {
|
||||
$response['version'] = $this->versionManager->getVersion()->toString();
|
||||
} else {
|
||||
$response['version'] = "not authorized";
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
|
||||
final class PartsDataTable implements DataTableTypeInterface
|
||||
{
|
||||
const LENGTH_MENU = [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]];
|
||||
public const LENGTH_MENU = [[10, 25, 50, 100, 250, 500, -1], [10, 25, 50, 100, 250, 500, "All"]];
|
||||
|
||||
public function __construct(
|
||||
private readonly EntityURLGenerator $urlGenerator,
|
||||
|
|
|
|||
|
|
@ -208,6 +208,15 @@ class Category extends AbstractPartsContainingDBElement
|
|||
$this->eda_info = new EDACategoryInfo();
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
if ($this->id) {
|
||||
//Clone EDA info to prevent changes to the original EDA info when changing the cloned category
|
||||
$this->eda_info = clone $this->eda_info;
|
||||
}
|
||||
parent::__clone();
|
||||
}
|
||||
|
||||
public function getPartnameHint(): string
|
||||
{
|
||||
return $this->partname_hint;
|
||||
|
|
|
|||
|
|
@ -152,6 +152,15 @@ class Footprint extends AbstractPartsContainingDBElement
|
|||
$this->eda_info = new EDAFootprintInfo();
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
if ($this->id) {
|
||||
//Clone EDA info to prevent changes to the original EDA info when changing the cloned category
|
||||
$this->eda_info = clone $this->eda_info;
|
||||
}
|
||||
parent::__clone();
|
||||
}
|
||||
|
||||
/****************************************
|
||||
* Getters
|
||||
****************************************/
|
||||
|
|
|
|||
|
|
@ -62,8 +62,8 @@ readonly class MaintenanceModeSubscriber implements EventSubscriberInterface
|
|||
return;
|
||||
}
|
||||
|
||||
//Allow to view the progress page
|
||||
if (preg_match('#^/\w{2}/system/update-manager/progress#', $event->getRequest()->getPathInfo())) {
|
||||
//Allow to view the progress page and health check endpoint
|
||||
if (preg_match('#^/[a-z]{2}(?:_[A-Z]{2})?/system/update-manager/(progress|health)#', $event->getRequest()->getPathInfo())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
87
src/Form/InfoProviderSystem/FromURLFormType.php
Normal file
87
src/Form/InfoProviderSystem/FromURLFormType.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Form\InfoProviderSystem;
|
||||
|
||||
use App\Services\InfoProviderSystem\ProviderRegistry;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\UrlType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class FromURLFormType extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly ProviderRegistry $providerRegistry)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->add('url', UrlType::class, [
|
||||
'label' => 'info_providers.from_url.url.label',
|
||||
'required' => true,
|
||||
]);
|
||||
|
||||
|
||||
$builder->add('method', ChoiceType::class, [
|
||||
'expanded' => true,
|
||||
'data' => 'generic_web', //Default value
|
||||
'label' => 'info_providers.from_url.method',
|
||||
'choices' => [
|
||||
'info_providers.from_url.method.generic_web' => 'generic_web',
|
||||
'info_providers.from_url.method.ai_web' => 'ai_web',
|
||||
],
|
||||
'choice_attr' => function ($choice, $key, $value) {
|
||||
//Disable all providers that are not active
|
||||
$provider = $this->providerRegistry->getProviderByKey($value);
|
||||
if (!$provider->isActive()) {
|
||||
return ['disabled' => 'disabled'];
|
||||
}
|
||||
|
||||
return [];
|
||||
},
|
||||
|
||||
//Render the choices as inline radio buttons
|
||||
'label_attr' => [
|
||||
'class' => 'radio-inline',
|
||||
],
|
||||
]);
|
||||
|
||||
$builder->add('no_cache', CheckboxType::class, [
|
||||
'label' => 'info_providers.from_url.no_cache',
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->add('skip_delegation', CheckboxType::class, [
|
||||
'label' => 'info_providers.from_url.skip_delegation',
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->add('submit', SubmitType::class, [
|
||||
'label' => 'info_providers.search.submit',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||
namespace App\Form\InfoProviderSystem;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SearchType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
|
@ -40,6 +41,15 @@ class PartSearchType extends AbstractType
|
|||
'help' => 'info_providers.search.providers.help',
|
||||
]);
|
||||
|
||||
$builder->add('no_cache_search', CheckboxType::class, [
|
||||
'label' => 'info_providers.no_cache_search',
|
||||
'required' => false,
|
||||
]);
|
||||
$builder->add('no_cache_details', CheckboxType::class, [
|
||||
'label' => 'info_providers.no_cache_details',
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->add('submit', SubmitType::class, [
|
||||
'label' => 'info_providers.search.submit'
|
||||
]);
|
||||
|
|
|
|||
72
src/Form/Settings/AiModelsType.php
Normal file
72
src/Form/Settings/AiModelsType.php
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Form\Settings;
|
||||
|
||||
use Symfony\AI\Platform\Capability;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
/**
|
||||
* An text input with autocomplete for AI models from the given platform.
|
||||
* The platform is determined by the value of another form field, which is specified by the "platform_selector" option. This allows to filter the available models based on the selected platform.
|
||||
*/
|
||||
final class AiModelsType extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly UrlGeneratorInterface $urlGenerator)
|
||||
{
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
{
|
||||
return TextType::class;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
//The target label of the platform select, which is used to filter the models for the selected platform.
|
||||
$resolver->setRequired('platform_selector');
|
||||
$resolver->setAllowedTypes('platform_selector', 'string');
|
||||
|
||||
//Only show models, that have the given capability. This is used to only show models that support structured output for the AI extractor settings.
|
||||
$resolver->setDefault('filter_capability', null);
|
||||
$resolver->setAllowedTypes('filter_capability', ['null', Capability::class]);
|
||||
}
|
||||
|
||||
public function finishView(FormView $view, FormInterface $form, array $options): void
|
||||
{
|
||||
$urlOptions = ['platform' => '__PLATFORM__'];
|
||||
if ($options['filter_capability'] !== null) {
|
||||
$urlOptions['capability'] = $options['filter_capability']->value;
|
||||
}
|
||||
|
||||
$view->vars['attr']['data-url-template'] = $this->urlGenerator->generate('typeahead_ai_models', $urlOptions);
|
||||
$view->vars['attr']['data-controller'] = 'elements--ai-model-autocomplete';
|
||||
|
||||
$view->vars['attr']['data-platform-selector'] = $options['platform_selector'];
|
||||
}
|
||||
}
|
||||
65
src/Form/Settings/AiPlatformChoiceType.php
Normal file
65
src/Form/Settings/AiPlatformChoiceType.php
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Form\Settings;
|
||||
|
||||
use App\Services\AI\AIPlatformRegistry;
|
||||
use App\Services\AI\AIPlatforms;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EnumType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Allow to choose an AI platform from the enabled platforms in the system. This is used in the settings to choose the default platform for AI features.
|
||||
*/
|
||||
final class AiPlatformChoiceType extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly AIPlatformRegistry $platformRegistry)
|
||||
{
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
{
|
||||
return EnumType::class;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$choices = array_map(static fn(string $val) => AIPlatforms::from($val), array_keys($this->platformRegistry->getEnabledPlatforms()));
|
||||
|
||||
$resolver->setDefaults([
|
||||
'class' => AIPlatforms::class,
|
||||
'choices' => $choices,
|
||||
'required' => false,
|
||||
'platform_selector_label' => null
|
||||
]);
|
||||
}
|
||||
|
||||
public function finishView(FormView $view, FormInterface $form, array $options): void
|
||||
{
|
||||
$view->vars['attr']['data-platform-selector-label'] = $options['platform_selector_label'] ?? $view->vars['id'].'_label';
|
||||
}
|
||||
}
|
||||
|
|
@ -29,60 +29,137 @@ use Symfony\Contracts\HttpClient\ResponseStreamInterface;
|
|||
|
||||
/**
|
||||
* HttpClient wrapper that randomizes the user agent for each request, to make it harder for servers to detect and block us.
|
||||
* It also sets some other headers to make the requests look more like real browser requests.
|
||||
* When we get a 503, 403 or 429, we assume that the server is blocking us and try again with a different user agent, until we run out of retries.
|
||||
*/
|
||||
final class RandomizeUseragentHttpClient implements HttpClientInterface
|
||||
{
|
||||
public const USER_AGENTS = [
|
||||
"Mozilla/5.0 (Windows; U; Windows NT 10.0; Win64; x64) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/52.0.1359.302 Safari/600.6 Edge/15.25690",
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299",
|
||||
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 8_8_3) Gecko/20100101 Firefox/51.6",
|
||||
"Mozilla/5.0 (Android; Android 4.4.4; E:number:20-23:00 Build/24.0.B.1.34) AppleWebKit/603.18 (KHTML, like Gecko) Chrome/47.0.1559.384 Mobile Safari/600.5",
|
||||
"Mozilla/5.0 (compatible; MSIE 9.0; Windows; Windows NT 6.3; WOW64 Trident/5.0)",
|
||||
"Mozilla/5.0 (Windows; Windows NT 6.0; Win64; x64) AppleWebKit/602.21 (KHTML, like Gecko) Chrome/51.0.3187.154 Safari/536",
|
||||
"Mozilla/5.0 (iPhone; CPU iPhone OS 9_4_2; like Mac OS X) AppleWebKit/537.24 (KHTML, like Gecko) Chrome/51.0.2432.275 Mobile Safari/535.6",
|
||||
"Mozilla/5.0 (U; Linux i680 ) Gecko/20100101 Firefox/57.5",
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 8_8_6; en-US) Gecko/20100101 Firefox/53.9",
|
||||
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 8_6_7) AppleWebKit/534.46 (KHTML, like Gecko) Chrome/55.0.3276.345 Safari/535",
|
||||
"Mozilla/5.0 (Windows; Windows NT 10.5;) AppleWebKit/535.42 (KHTML, like Gecko) Chrome/53.0.1176.353 Safari/534.0 Edge/11.95743",
|
||||
"Mozilla/5.0 (Linux; Android 5.1.1; MOTO G Build/LPH223) AppleWebKit/600.27 (KHTML, like Gecko) Chrome/47.0.1604.204 Mobile Safari/535.1",
|
||||
"Mozilla/5.0 (iPod; CPU iPod OS 7_4_8; like Mac OS X) AppleWebKit/534.17 (KHTML, like Gecko) Chrome/50.0.1632.146 Mobile Safari/600.4",
|
||||
"Mozilla/5.0 (Linux; U; Linux i570 ; en-US) Gecko/20100101 Firefox/49.9",
|
||||
"Mozilla/5.0 (Windows NT 10.2; WOW64; en-US) AppleWebKit/603.2 (KHTML, like Gecko) Chrome/55.0.1299.311 Safari/535",
|
||||
"Mozilla/5.0 (Windows; Windows NT 10.5; x64; en-US) AppleWebKit/603.39 (KHTML, like Gecko) Chrome/52.0.1443.139 Safari/536.6 Edge/13.79436",
|
||||
"Mozilla/5.0 (Linux; U; Android 5.1; SM-G9350T Build/MMB29M) AppleWebKit/537.15 (KHTML, like Gecko) Chrome/55.0.2552.307 Mobile Safari/600.8",
|
||||
"Mozilla/5.0 (Android; Android 6.0; SAMSUNG SM-D9350V Build/MDB08L) AppleWebKit/535.30 (KHTML, like Gecko) Chrome/53.0.1345.278 Mobile Safari/537.4",
|
||||
"Mozilla/5.0 (Windows; Windows NT 10.0;) AppleWebKit/534.44 (KHTML, like Gecko) Chrome/47.0.3503.387 Safari/601",
|
||||
private const PROFILES = [
|
||||
// --- CHROME ON WINDOWS ---
|
||||
'chrome_windows' => [
|
||||
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36',
|
||||
'Sec-Ch-Ua' => '"Google Chrome";v="142", "Chromium";v="142", "Not=A?Brand";v="99"',
|
||||
'Sec-Ch-Ua-Mobile' => '?0',
|
||||
'Sec-Ch-Ua-Platform' => '"Windows"',
|
||||
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
||||
],
|
||||
|
||||
// --- CHROME ON MACOS ---
|
||||
'chrome_mac' => [
|
||||
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
|
||||
'Sec-Ch-Ua' => '"Google Chrome";v="141", "Chromium";v="141", "Not=A?Brand";v="99"',
|
||||
'Sec-Ch-Ua-Mobile' => '?0',
|
||||
'Sec-Ch-Ua-Platform' => '"macOS"',
|
||||
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
||||
],
|
||||
|
||||
// --- EDGE ON WINDOWS ---
|
||||
'edge_windows' => [
|
||||
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0',
|
||||
'Sec-Ch-Ua' => '"Microsoft Edge";v="142", "Chromium";v="142", "Not=A?Brand";v="99"',
|
||||
'Sec-Ch-Ua-Mobile' => '?0',
|
||||
'Sec-Ch-Ua-Platform' => '"Windows"',
|
||||
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
||||
],
|
||||
|
||||
// --- FIREFOX ON WINDOWS ---
|
||||
'firefox_windows' => [
|
||||
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0',
|
||||
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8',
|
||||
'Accept-Language' => 'en-US,en;q=0.5',
|
||||
// Firefox does not send Sec-Ch-Ua headers by default
|
||||
],
|
||||
|
||||
// --- FIREFOX ON LINUX ---
|
||||
'firefox_linux' => [
|
||||
'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:137.0) Gecko/20100101 Firefox/137.0',
|
||||
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8',
|
||||
'Accept-Language' => 'en-US,en;q=0.5',
|
||||
],
|
||||
|
||||
// --- SAFARI ON MACOS ---
|
||||
'safari_mac' => [
|
||||
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15',
|
||||
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||
'Accept-Language' => 'en-US,en;q=0.9',
|
||||
],
|
||||
|
||||
// --- CHROME ON ANDROID (Mobile) ---
|
||||
'chrome_android' => [
|
||||
'User-Agent' => 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Mobile Safari/537.36',
|
||||
'Sec-Ch-Ua' => '"Google Chrome";v="142", "Chromium";v="142", "Not=A?Brand";v="99"',
|
||||
'Sec-Ch-Ua-Mobile' => '?1',
|
||||
'Sec-Ch-Ua-Platform' => '"Android"',
|
||||
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
||||
],
|
||||
|
||||
// --- SAFARI ON IPHONE (Mobile) ---
|
||||
'safari_iphone' => [
|
||||
'User-Agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1',
|
||||
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||
'Accept-Language' => 'en-US,en;q=0.9',
|
||||
],
|
||||
];
|
||||
|
||||
private const COMMON_HEADERS = [
|
||||
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
||||
'Accept-Language' => 'en-US,en;q=0.9',
|
||||
'Sec-Fetch-Dest' => 'document',
|
||||
'Sec-Fetch-Mode' => 'navigate',
|
||||
'Sec-Fetch-Site' => 'none',
|
||||
'Sec-Fetch-User' => '?1',
|
||||
'Upgrade-Insecure-Requests' => '1',
|
||||
];
|
||||
|
||||
private const ENTRY_REFERERS = [
|
||||
'https://www.google.com/',
|
||||
'https://www.bing.com/',
|
||||
'https://duckduckgo.com/',
|
||||
'https://t.co/', // Twitter/X shortener
|
||||
'https://www.reddit.com/',
|
||||
];
|
||||
|
||||
private ?string $lastUrl = null;
|
||||
|
||||
public function __construct(
|
||||
private readonly HttpClientInterface $client,
|
||||
private readonly array $userAgents = self::USER_AGENTS,
|
||||
private readonly int $repeatOnFailure = 1,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getRandomUserAgent(): string
|
||||
{
|
||||
return $this->userAgents[array_rand($this->userAgents)];
|
||||
}
|
||||
|
||||
public function request(string $method, string $url, array $options = []): ResponseInterface
|
||||
{
|
||||
$repeatsLeft = $this->repeatOnFailure;
|
||||
do {
|
||||
$modifiedOptions = $options;
|
||||
if (!isset($modifiedOptions['headers']['User-Agent'])) {
|
||||
$modifiedOptions['headers']['User-Agent'] = $this->getRandomUserAgent();
|
||||
$profile = self::PROFILES[array_rand(self::PROFILES)];
|
||||
|
||||
// Merge common headers with the specific browser profile
|
||||
$headers = array_merge(self::COMMON_HEADERS, $profile);
|
||||
|
||||
//Add a Referer header if not already set, to make it look more like a real browser request. We use the last URL we visited as the referer, to simulate internal navigation. If we don't have a last URL (first request), we pick a random entry point from common referers.
|
||||
if (!isset($options['headers']['Referer'])) {
|
||||
if ($this->lastUrl !== null) {
|
||||
// If we have a previous URL, use it (Internal Navigation)
|
||||
$headers['Referer'] = $this->lastUrl;
|
||||
} else {
|
||||
// First request? Pick an entry point (External Entry)
|
||||
$headers['Referer'] = self::ENTRY_REFERERS[array_rand(self::ENTRY_REFERERS)];
|
||||
}
|
||||
}
|
||||
$response = $this->client->request($method, $url, $modifiedOptions);
|
||||
|
||||
// Allow manual overrides from $options
|
||||
$options['headers'] = array_merge($headers, $options['headers'] ?? []);
|
||||
|
||||
$response = $this->client->request($method, $url, $options);
|
||||
|
||||
//When we get a 503, 403 or 429, we assume that the server is blocking us and try again with a different user agent
|
||||
if (!in_array($response->getStatusCode(), [403, 429, 503], true)) {
|
||||
$this->lastUrl = $url; // Update last visited URL for referer in the next request
|
||||
return $response;
|
||||
}
|
||||
|
||||
//Otherwise we try again with a different user agent, until we run out of retries
|
||||
usleep(5000); // Sleep for 5ms to avoid hammering the server too hard in case of multiple retries
|
||||
} while ($repeatsLeft-- > 0);
|
||||
|
||||
return $response;
|
||||
|
|
@ -95,6 +172,6 @@ final class RandomizeUseragentHttpClient implements HttpClientInterface
|
|||
|
||||
public function withOptions(array $options): static
|
||||
{
|
||||
return new self($this->client->withOptions($options), $this->userAgents, $this->repeatOnFailure);
|
||||
return new self($this->client->withOptions($options), $this->repeatOnFailure);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
94
src/Services/AI/AIPlatformRegistry.php
Normal file
94
src/Services/AI/AIPlatformRegistry.php
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Services\AI;
|
||||
|
||||
use Jbtronics\SettingsBundle\Manager\SettingsManagerInterface;
|
||||
use Symfony\AI\Platform\PlatformInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
|
||||
|
||||
final readonly class AIPlatformRegistry
|
||||
{
|
||||
/**
|
||||
* All registered platforms, indexed by their service tag name (e.g. "openrouter", "lmstudio")
|
||||
* @var array<string, PlatformInterface> $allPlatforms
|
||||
*/
|
||||
private array $allPlatforms;
|
||||
|
||||
/**
|
||||
* All registered platforms, indexed by their AIPlatforms enum value (e.g. AIPlatforms::OPENROUTER->value)
|
||||
* @var array<string, PlatformInterface> $enabledPlatforms
|
||||
*/
|
||||
private array $enabledPlatforms;
|
||||
|
||||
public function __construct(
|
||||
SettingsManagerInterface $settingsManager,
|
||||
#[AutowireIterator(tag: 'ai.platform', indexAttribute: 'name')]
|
||||
iterable $platforms,
|
||||
) {
|
||||
$this->allPlatforms = iterator_to_array($platforms);
|
||||
|
||||
//Check which platforms are active based on the settings and store them in $activePlatforms
|
||||
$tmp = [];
|
||||
foreach (AIPlatforms::cases() as $platform) {
|
||||
if (isset($this->allPlatforms[$platform->toServiceTagName()])) {
|
||||
//Check if the platform is active by calling its isActive() on the settings class
|
||||
$settings = $settingsManager->get($platform->toSettingsClass());
|
||||
if (!$settings->isAIPlatformEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tmp[$platform->value] = $this->allPlatforms[$platform->toServiceTagName()];
|
||||
}
|
||||
}
|
||||
$this->enabledPlatforms = $tmp;
|
||||
}
|
||||
|
||||
public function getPlatform(AIPlatforms $platform): PlatformInterface
|
||||
{
|
||||
if (!isset($this->enabledPlatforms[$platform->value])) {
|
||||
throw new \InvalidArgumentException(sprintf('AI platform "%s" is not active or does not exist.', $platform->name));
|
||||
}
|
||||
|
||||
return $this->enabledPlatforms[$platform->value];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given platform is active (i.e. it is registered and its settings are properly configured)
|
||||
* @param AIPlatforms $platform
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled(AIPlatforms $platform): bool
|
||||
{
|
||||
return isset($this->enabledPlatforms[$platform->value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all active platforms, indexed by their AIPlatforms enum value (e.g. AIPlatforms::OPENROUTER->value)
|
||||
* @return PlatformInterface[]
|
||||
*/
|
||||
public function getEnabledPlatforms(): array
|
||||
{
|
||||
return $this->enabledPlatforms;
|
||||
}
|
||||
}
|
||||
33
src/Services/AI/AIPlatformSettingsInterface.php
Normal file
33
src/Services/AI/AIPlatformSettingsInterface.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Services\AI;
|
||||
|
||||
interface AIPlatformSettingsInterface
|
||||
{
|
||||
/**
|
||||
* Returns true, if the AI platform is enabled in the settings and can be used, false otherwise.
|
||||
* @return bool
|
||||
*/
|
||||
public function isAIPlatformEnabled(): bool;
|
||||
}
|
||||
64
src/Services/AI/AIPlatforms.php
Normal file
64
src/Services/AI/AIPlatforms.php
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Services\AI;
|
||||
|
||||
use App\Settings\AISettings\LMStudioSettings;
|
||||
use App\Settings\AISettings\OpenRouterSettings;
|
||||
use Symfony\Contracts\Translation\TranslatableInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
enum AIPlatforms: string implements TranslatableInterface
|
||||
{
|
||||
case OPENROUTER = 'openrouter';
|
||||
case LMSTUDIO = 'lmstudio';
|
||||
|
||||
/**
|
||||
* Returns the name attribute of the service tag for this platform, which is used to register the platform in the AIPlatformRegistry
|
||||
* @return string
|
||||
*/
|
||||
public function toServiceTagName(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class name of the settings class for this platform, which implements AIPlatformSettingsInterface
|
||||
* @return string
|
||||
* @phpstan-return class-string<AIPlatformSettingsInterface>
|
||||
*/
|
||||
public function toSettingsClass(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::LMSTUDIO => LMStudioSettings::class,
|
||||
self::OPENROUTER => OpenRouterSettings::class,
|
||||
};
|
||||
}
|
||||
|
||||
public function trans(TranslatorInterface $translator, ?string $locale = null): string
|
||||
{
|
||||
$key = 'settings.ai.' . $this->value;
|
||||
|
||||
return $translator->trans($key, locale: $locale);
|
||||
}
|
||||
}
|
||||
61
src/Services/AI/AcceptAllModelsCatalog.php
Normal file
61
src/Services/AI/AcceptAllModelsCatalog.php
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Services\AI;
|
||||
|
||||
use Symfony\AI\Platform\Bridge\Generic\CompletionsModel;
|
||||
use Symfony\AI\Platform\Exception\ModelNotFoundException;
|
||||
use Symfony\AI\Platform\Model;
|
||||
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
|
||||
|
||||
/**
|
||||
* This is a wrapper, to allow accepting all models, even if they are not contained in the decorated ModelCatalogInterface.
|
||||
* This is a workaround for outdated/incomplete model catalogs provided by AI platforms, which do not contain all available models, or do not update their catalogs frequently enough.
|
||||
*/
|
||||
#[AsDecorator('ai.platform.model_catalog.lmstudio')]
|
||||
#[AsDecorator('ai.platform.model_catalog.openrouter')]
|
||||
final readonly class AcceptAllModelsCatalog implements ModelCatalogInterface
|
||||
{
|
||||
|
||||
public function __construct(private ModelCatalogInterface $decorated)
|
||||
{
|
||||
}
|
||||
|
||||
public function getModel(string $modelName): Model
|
||||
{
|
||||
//Use the actual values when its available.
|
||||
try {
|
||||
return $this->decorated->getModel($modelName);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
//If the model is not found, return a generic model with the given name and no capabilities.
|
||||
return new CompletionsModel($modelName, []);
|
||||
}
|
||||
}
|
||||
|
||||
public function getModels(): array
|
||||
{
|
||||
//Return the actual models catalog here for correct autocompletition
|
||||
return $this->decorated->getModels();
|
||||
}
|
||||
}
|
||||
|
|
@ -156,8 +156,8 @@ class AttachmentManager
|
|||
//Taken from: https://www.php.net/manual/de/function.filesize.php#106569 and slightly modified
|
||||
|
||||
$sz = 'BKMGTP';
|
||||
$factor = (int) floor((strlen((string) $bytes) - 1) / 3);
|
||||
$factor = min((int) floor((strlen((string) $bytes) - 1) / 3), strlen($sz) - 1);
|
||||
//Use real (10 based) SI prefixes
|
||||
return sprintf("%.{$decimals}f", $bytes / 1000 ** $factor).@$sz[$factor];
|
||||
return sprintf("%.{$decimals}f", $bytes / 1000 ** $factor).$sz[$factor];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,10 +59,10 @@ class SIFormatter
|
|||
$prefixes_neg = ['', 'm', 'μ', 'n', 'p', 'f', 'a', 'z', 'y'];
|
||||
|
||||
if ($magnitude >= 0) {
|
||||
$nearest = (int) floor(abs($magnitude) / 3);
|
||||
$nearest = min((int) floor(abs($magnitude) / 3), count($prefixes_pos) - 1);
|
||||
$symbol = $prefixes_pos[$nearest];
|
||||
} else {
|
||||
$nearest = (int) round(abs($magnitude) / 3);
|
||||
$nearest = min((int) round(abs($magnitude) / 3), count($prefixes_neg) - 1);
|
||||
$symbol = $prefixes_neg[$nearest];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ trait PKImportHelperTrait
|
|||
//Use mime type to determine the extension like PartKeepr does in legacy implementation (just use the second part of the mime type)
|
||||
//See UploadedFile.php:291 in PartKeepr (https://github.com/partkeepr/PartKeepr/blob/f6176c3354b24fa39ac8bc4328ee0df91de3d5b6/src/PartKeepr/UploadedFileBundle/Entity/UploadedFile.php#L291)
|
||||
if (!empty ($attachment_row['mimetype'])) {
|
||||
$attachment_row['extension'] = explode('/', (string) $attachment_row['mimetype'])[1];
|
||||
$attachment_row['extension'] = explode('/', (string) $attachment_row['mimetype'])[1] ?? '';
|
||||
} else {
|
||||
//If the mime type is empty, we use the original extension
|
||||
$attachment_row['extension'] = pathinfo((string) $attachment_row['originalname'], PATHINFO_EXTENSION);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ final class BulkInfoProviderService
|
|||
}
|
||||
|
||||
$partResults = [];
|
||||
$hasAnyResults = false;
|
||||
|
||||
// Group providers by batch capability
|
||||
$batchProviders = [];
|
||||
|
|
@ -88,7 +87,6 @@ final class BulkInfoProviderService
|
|||
);
|
||||
|
||||
if (!empty($allResults)) {
|
||||
$hasAnyResults = true;
|
||||
$searchResults = $this->formatSearchResults($allResults);
|
||||
}
|
||||
|
||||
|
|
@ -99,10 +97,6 @@ final class BulkInfoProviderService
|
|||
);
|
||||
}
|
||||
|
||||
if (!$hasAnyResults) {
|
||||
throw new \RuntimeException('No search results found for any of the selected parts');
|
||||
}
|
||||
|
||||
$response = new BulkSearchResponseDTO($partResults);
|
||||
|
||||
// Prefetch details if requested
|
||||
|
|
|
|||
109
src/Services/InfoProviderSystem/CreateFromUrlHelper.php
Normal file
109
src/Services/InfoProviderSystem/CreateFromUrlHelper.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Services\InfoProviderSystem;
|
||||
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Exceptions\ProviderIDNotSupportedException;
|
||||
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
|
||||
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
final readonly class CreateFromUrlHelper
|
||||
{
|
||||
public function __construct(private Security $security,
|
||||
private ProviderRegistry $providerRegistry,
|
||||
private PartInfoRetriever $infoRetriever,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if at least one provider can create parts from an URL and the current user is allowed to use it.
|
||||
* This is used to determine if the "From URL" feature should be shown to the user.
|
||||
* @return bool
|
||||
*/
|
||||
public function canCreateFromUrl(): bool
|
||||
{
|
||||
if (!$this->security->isGranted('@info_providers.create_parts')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Check if either the generic web provider or the ai web provider is active
|
||||
$genericWebProvider = $this->providerRegistry->getProviderByKey('generic_web');
|
||||
$aiWebProvider = $this->providerRegistry->getProviderByKey('ai_web');
|
||||
|
||||
return $genericWebProvider->isActive() || $aiWebProvider->isActive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates the URL to another provider if possible, otherwise return null
|
||||
* @param string $url
|
||||
* @return SearchResultDTO|null
|
||||
*/
|
||||
public function delegateToOtherProvider(string $url, InfoProviderInterface $callingInfoProvider): ?SearchResultDTO
|
||||
{
|
||||
//Extract domain from url:
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
if ($host === false || $host === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$provider = $this->providerRegistry->getProviderHandlingDomain($host);
|
||||
|
||||
if ($provider !== null && $provider->isActive() && $provider->getProviderKey() !== $callingInfoProvider->getProviderKey()) {
|
||||
try {
|
||||
$id = $provider->getIDFromURL($url);
|
||||
if ($id !== null) {
|
||||
$results = $this->infoRetriever->searchByKeyword($id, [$provider]);
|
||||
if (count($results) > 0) {
|
||||
return $results[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (ProviderIDNotSupportedException $e) {
|
||||
//Ignore and continue
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates the URL to another provider if possible and returns the details, otherwise return null
|
||||
* @param string $url
|
||||
* @param InfoProviderInterface $callingInfoProvider
|
||||
* @return PartDetailDTO|null
|
||||
*/
|
||||
public function delegateToOtherProviderDetails(string $url, InfoProviderInterface $callingInfoProvider): ?PartDetailDTO
|
||||
{
|
||||
$delegatedResult = $this->delegateToOtherProvider($url, $callingInfoProvider);
|
||||
if ($delegatedResult !== null) {
|
||||
return $this->infoRetriever->getDetailsForSearchResult($delegatedResult);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
252
src/Services/InfoProviderSystem/DTOJsonSchemaConverter.php
Normal file
252
src/Services/InfoProviderSystem/DTOJsonSchemaConverter.php
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Services\InfoProviderSystem;
|
||||
|
||||
use App\Entity\Parts\ManufacturingStatus;
|
||||
use App\Services\InfoProviderSystem\DTOs\FileDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
|
||||
|
||||
/**
|
||||
* This class allows to convert the JSON data returned by an LLM into the DTOs used by the info provider system later.
|
||||
*/
|
||||
final class DTOJsonSchemaConverter
|
||||
{
|
||||
/**
|
||||
* Returns the JSON schema, that defines the expected structure of the JSON data returned by the LLM.
|
||||
* @return array
|
||||
*/
|
||||
public function getJSONSchema(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'clock',
|
||||
'strict' => true,
|
||||
'schema' => [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'name' => ['type' => 'string', 'description' => 'Product name'],
|
||||
'description' => ['type' => 'string', 'description' => 'A short description of the product, maybe containing the most important things. Onnly One line.'],
|
||||
'manufacturer' => ['type' => ['string', 'null'], 'description' => 'Manufacturer name'],
|
||||
'mpn' => ['type' => ['string', 'null'], 'description' => 'Manufacturer Part Number'],
|
||||
'category' => ['type' => ['string', 'null'], 'description' => 'Product category, e.g. "Passive components -> Resistors"'],
|
||||
'manufacturing_status' => ['type' => ['string', 'null'], 'enum' => ['active', 'obsolete', 'nrfnd', 'discontinued', null], 'description' => 'Manufacturing status'],
|
||||
'footprint' => ['type' => ['string', 'null'], 'description' => 'Package/footprint type, like "SOT-23", "DIP-8", "QFN-32" etc.'],
|
||||
'mass' => ['type' => ['number', 'null'], 'description' => 'Mass of the product in grams'],
|
||||
'gtin' => ['type' => ['string', 'null'], 'description' => 'Global Trade Item Number (GTIN) / EAN / UPC code for barcodes'],
|
||||
'notes' => ['type' => ['string', 'null'], 'description' => 'Optional long description of the part with more details than description. Can be markdown formatted.'],
|
||||
'parameters' => [
|
||||
'type' => 'array',
|
||||
'items' => [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'name' => ['type' => 'string'],
|
||||
'symbol' => ['type' => ['string', 'null'], 'description' => 'An optional quantity symbol for the parameter in latex code, like R_1'],
|
||||
'value_typical' => ['type' => ['number', 'null'], 'description' => 'The typical value of the parameter. For example, for a resistor this could be 100 for a 100 Ohm resistor. Also used if only one numeric value is given. If used an unit should be given'],
|
||||
'value_min' => ['type' => ['number', 'null'], 'description' => 'If a range is given for the parameter, this is the minimum value. Null if no range is given.'],
|
||||
'value_max' => ['type' => ['number', 'null'], 'description' => 'If a range is given for the parameter, this is the maximum value. Null if not a range.'],
|
||||
'value_text' => ['type' => ['string', 'null'], 'description' => 'When a value is not numeric it can be put here as text. Only use if it does not fit in value_min, value_typical or value_max. E.g. "Yes", "Red", etc.'],
|
||||
'group' => ['type' => ['string', 'null'], 'description' => 'An optional group name for the parameter, e.g. "Electrical parameters", "Mechanical parameters" etc.'],
|
||||
'unit' => ['type' => ['string', 'null'], 'description' => 'The unit of the parameter values, e.g. kg, Ohm, V, etc.'],
|
||||
],
|
||||
'required' => ['name', 'value_typical', 'value_min', 'value_max', 'value_text']
|
||||
],
|
||||
],
|
||||
'datasheets' => [
|
||||
'description' => 'A list of datasheets, manuals, or other technical documents related to the product. Not images, but actual documents, preferably PDFs.',
|
||||
'type' => 'array',
|
||||
'items' => [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'url' => ['type' => 'string'],
|
||||
'description' => ['type' => 'string'],
|
||||
],
|
||||
'required' => ['url'],
|
||||
],
|
||||
],
|
||||
'images' => [
|
||||
'type' => 'array',
|
||||
'items' => [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'url' => ['type' => 'string'],
|
||||
'description' => ['type' => 'string'],
|
||||
],
|
||||
'required' => ['url'],
|
||||
],
|
||||
],
|
||||
'vendor_infos' => [
|
||||
'type' => 'array',
|
||||
'items' => [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'distributor_name' => ['type' => 'string', 'description' => 'Name of the distributor or vendor. Typically the shop name'],
|
||||
'order_number' => ['type' => ['string', 'null'], 'description' => 'The order number or SKU used by the distributor. Optional, but can help to find the product on the distributor website.'],
|
||||
'product_url' => ['type' => 'string'],
|
||||
'prices_include_vat' => ['type' => ['boolean', 'null'], 'description' => 'Whether the prices include VAT or not. Null if unknown.'],
|
||||
'prices' => [
|
||||
'type' => 'array',
|
||||
'items' => [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'minimum_quantity' => ['type' => 'integer', 'description' => 'Minimum quantity for this price tier. 1 when no tiered pricing is available.'],
|
||||
'price' => ['type' => 'number', 'description' => 'Price for the given minimum quantity.'],
|
||||
'currency' => ['type' => 'string', 'description' => 'Currency ISO code, e.g. USD'],
|
||||
],
|
||||
'required' => ['minimum_quantity', 'price', 'currency'],
|
||||
],
|
||||
],
|
||||
],
|
||||
'required' => ['distributor_name', 'product_url'],
|
||||
],
|
||||
],
|
||||
'manufacturer_product_url' => ['type' => ['string', 'null'], 'description' => 'Manufacturer product page URL'],
|
||||
],
|
||||
'required' => ['name', 'description'],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function jsonToDTO(array $data, string $providerKey, string $providerId, ?string $productUrl = null, string $distributorNameFallback = '???'): PartDetailDTO
|
||||
{
|
||||
// Map manufacturing status
|
||||
$manufacturingStatus = null;
|
||||
if (!empty($data['manufacturing_status'])) {
|
||||
$status = strtolower((string) $data['manufacturing_status']);
|
||||
$manufacturingStatus = match ($status) {
|
||||
'active' => ManufacturingStatus::ACTIVE,
|
||||
'obsolete', 'discontinued' => ManufacturingStatus::DISCONTINUED,
|
||||
'nrfnd', 'not recommended for new designs' => ManufacturingStatus::NRFND,
|
||||
'eol' => ManufacturingStatus::EOL,
|
||||
'announced' => ManufacturingStatus::ANNOUNCED,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
// Build parameters
|
||||
$parameters = null;
|
||||
if (!empty($data['parameters']) && is_array($data['parameters'])) {
|
||||
$parameters = [];
|
||||
foreach ($data['parameters'] as $p) {
|
||||
if (!empty($p['name'])) {
|
||||
$parameters[] = new ParameterDTO(
|
||||
name: $p['name'],
|
||||
value_text: $p['value_text'] ?? null,
|
||||
value_typ: isset($p['value_typical']) && is_numeric($p['value_typical']) ? (float) $p['value_typical'] : null,
|
||||
value_min: isset($p['value_min']) && is_numeric($p['value_min']) ? (float) $p['value_min'] : null,
|
||||
value_max: isset($p['value_max']) && is_numeric($p['value_max']) ? (float) $p['value_max'] : null,
|
||||
unit: $p['unit'] ?? null,
|
||||
symbol: $p['symbol'] ?? null,
|
||||
group: $p['group'] ?? null,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build datasheets
|
||||
$datasheets = null;
|
||||
if (!empty($data['datasheets']) && is_array($data['datasheets'])) {
|
||||
$datasheets = [];
|
||||
foreach ($data['datasheets'] as $d) {
|
||||
if (!empty($d['url'])) {
|
||||
$datasheets[] = new FileDTO(
|
||||
url: $d['url'],
|
||||
name: $d['description'] ?? 'Datasheet'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build images
|
||||
$images = null;
|
||||
if (!empty($data['images']) && is_array($data['images'])) {
|
||||
$images = [];
|
||||
foreach ($data['images'] as $i) {
|
||||
if (!empty($i['url'])) {
|
||||
$images[] = new FileDTO(
|
||||
url: $i['url'],
|
||||
name: $i['description'] ?? 'Image'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build vendor infos
|
||||
$vendorInfos = null;
|
||||
if (!empty($data['vendor_infos']) && is_array($data['vendor_infos'])) {
|
||||
$vendorInfos = [];
|
||||
foreach ($data['vendor_infos'] as $v) {
|
||||
$prices = [];
|
||||
if (!empty($v['prices']) && is_array($v['prices'])) {
|
||||
foreach ($v['prices'] as $p) {
|
||||
$prices[] = new PriceDTO(
|
||||
minimum_discount_amount: (int) ($p['minimum_quantity'] ?? 1),
|
||||
price: (string) ($p['price'] ?? 0),
|
||||
currency_iso_code: $p['currency'] ?? null,
|
||||
price_related_quantity: 1,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$vendorInfos[] = new PurchaseInfoDTO(
|
||||
distributor_name: $v['distributor_name'] ?? $distributorNameFallback,
|
||||
order_number: $v['order_number'] ?? 'Unknown',
|
||||
prices: $prices,
|
||||
product_url: $v['product_url'] ?? $productUrl,
|
||||
prices_include_vat: $v['prices_include_vat'] ?? null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Get preview image URL
|
||||
$previewImageUrl = null;
|
||||
if (!empty($data['images']) && is_array($data['images']) && !empty($data['images'][0]['url'])) {
|
||||
$previewImageUrl = $data['images'][0]['url'];
|
||||
}
|
||||
|
||||
return new PartDetailDTO(
|
||||
provider_key: $providerKey,
|
||||
provider_id: $providerId,
|
||||
name: $data['name'] ?? 'Unknown',
|
||||
description: $data['description'] ?? '',
|
||||
category: $data['category'] ?? null,
|
||||
manufacturer: $data['manufacturer'] ?? null,
|
||||
mpn: $data['mpn'] ?? null,
|
||||
preview_image_url: $previewImageUrl,
|
||||
manufacturing_status: $manufacturingStatus,
|
||||
provider_url: $productUrl,
|
||||
footprint: $data['footprint'] ?? null,
|
||||
gtin: $data['gtin'] ?? null,
|
||||
notes: $data['notes'] ?? null,
|
||||
datasheets: $datasheets,
|
||||
images: $images,
|
||||
parameters: $parameters,
|
||||
vendor_infos: $vendorInfos,
|
||||
mass: isset($data['mass']) && is_numeric($data['mass']) ? (float) $data['mass'] : null,
|
||||
manufacturer_product_url: $data['manufacturer_product_url'] ?? null,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -53,6 +53,7 @@ final class PartInfoRetriever
|
|||
* Search for a keyword in the given providers. The results can be cached
|
||||
* @param string[]|InfoProviderInterface[] $providers A list of providers to search in, either as provider keys or as provider instances
|
||||
* @param string $keyword The keyword to search for
|
||||
* @param array<string, mixed> $options An associative array of options which can be used to modify the search behavior. The supported options depend on the provider and should be documented in the provider's documentation.
|
||||
* @return SearchResultDTO[] The search results
|
||||
* @throws InfoProviderNotActiveException if any of the given providers is not active
|
||||
* @throws ClientException if any of the providers throws an exception during the search
|
||||
|
|
@ -60,7 +61,7 @@ final class PartInfoRetriever
|
|||
* @throws TransportException if any of the providers throws an exception during the search
|
||||
* @throws OAuthReconnectRequiredException if any of the providers throws an exception during the search that indicates that the OAuth token needs to be refreshed
|
||||
*/
|
||||
public function searchByKeyword(string $keyword, array $providers): array
|
||||
public function searchByKeyword(string $keyword, array $providers, array $options = []): array
|
||||
{
|
||||
$results = [];
|
||||
|
||||
|
|
@ -79,7 +80,7 @@ final class PartInfoRetriever
|
|||
}
|
||||
|
||||
/** @noinspection SlowArrayOperationsInLoopInspection */
|
||||
$results = array_merge($results, $this->searchInProvider($provider, $keyword));
|
||||
$results = array_merge($results, $this->searchInProvider($provider, $keyword, $options));
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
|
@ -89,15 +90,31 @@ final class PartInfoRetriever
|
|||
* Search for a keyword in the given provider. The result is cached for 7 days.
|
||||
* @return SearchResultDTO[]
|
||||
*/
|
||||
protected function searchInProvider(InfoProviderInterface $provider, string $keyword): array
|
||||
protected function searchInProvider(InfoProviderInterface $provider, string $keyword, array $options = []): array
|
||||
{
|
||||
//Generate key and escape reserved characters from the provider id
|
||||
$escaped_keyword = hash('xxh3', $keyword);
|
||||
return $this->partInfoCache->get("search_{$provider->getProviderKey()}_{$escaped_keyword}", function (ItemInterface $item) use ($provider, $keyword) {
|
||||
|
||||
$no_cache = $options[InfoProviderInterface::OPTION_NO_CACHE] ?? false;
|
||||
|
||||
//Exclude the no_cache option from the options hash, since it should not affect the cache key, as it only determines whether to bypass the cache or not, but does not change the actual search results
|
||||
$options_without_cache = $options;
|
||||
unset($options_without_cache[InfoProviderInterface::OPTION_NO_CACHE]);
|
||||
//Generate a hash for the options, to ensure that different options result in different cache entries
|
||||
$options_hash = hash('xxh3', json_encode($options_without_cache, JSON_THROW_ON_ERROR));
|
||||
|
||||
$cache_key = "search_{$provider->getProviderKey()}_{$escaped_keyword}_{$options_hash}";
|
||||
|
||||
//If no_cache is set, bypass the cache and get fresh results from the provider
|
||||
if ($no_cache) {
|
||||
$this->partInfoCache->delete($cache_key);
|
||||
}
|
||||
|
||||
return $this->partInfoCache->get($cache_key, function (ItemInterface $item) use ($provider, $keyword, $options) {
|
||||
//Set the expiration time
|
||||
$item->expiresAfter(!$this->debugMode ? self::CACHE_RESULT_EXPIRATION : 10);
|
||||
|
||||
return $provider->searchByKeyword($keyword);
|
||||
return $provider->searchByKeyword($keyword, $options);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -106,10 +123,11 @@ final class PartInfoRetriever
|
|||
* The result is cached for 4 days.
|
||||
* @param string $provider_key
|
||||
* @param string $part_id
|
||||
* @param array<string, mixed> $options An associative array of options which can be used to modify the search behavior. The supported options depend on the provider and should be documented in the provider's documentation.
|
||||
* @return PartDetailDTO
|
||||
* @throws InfoProviderNotActiveException if the the given providers is not active
|
||||
*/
|
||||
public function getDetails(string $provider_key, string $part_id): PartDetailDTO
|
||||
public function getDetails(string $provider_key, string $part_id, array $options = []): PartDetailDTO
|
||||
{
|
||||
$provider = $this->provider_registry->getProviderByKey($provider_key);
|
||||
|
||||
|
|
@ -118,13 +136,26 @@ final class PartInfoRetriever
|
|||
throw InfoProviderNotActiveException::fromProvider($provider);
|
||||
}
|
||||
|
||||
//Exclude the no_cache option from the options hash, since it should not affect the cache key, as it only determines whether to bypass the cache or not, but does not change the actual search results
|
||||
$options_without_cache = $options;
|
||||
unset($options_without_cache[InfoProviderInterface::OPTION_NO_CACHE]);
|
||||
//Generate a hash for the options, to ensure that different options result in different cache entries
|
||||
$options_hash = hash('xxh3', json_encode($options_without_cache, JSON_THROW_ON_ERROR));
|
||||
|
||||
//Generate key and escape reserved characters from the provider id
|
||||
$escaped_part_id = hash('xxh3', $part_id);
|
||||
return $this->partInfoCache->get("details_{$provider_key}_{$escaped_part_id}", function (ItemInterface $item) use ($provider, $part_id) {
|
||||
$cache_key = "details_{$provider_key}_{$escaped_part_id}_{$options_hash}";
|
||||
|
||||
//Delete the cache entry if no_cache is set, to ensure that the next get call will fetch fresh data from the provider, instead of returning stale data from the cache.
|
||||
if ($options[InfoProviderInterface::OPTION_NO_CACHE] ?? false) {
|
||||
$this->partInfoCache->delete($cache_key);
|
||||
}
|
||||
|
||||
return $this->partInfoCache->get($cache_key, function (ItemInterface $item) use ($provider, $part_id, $options) {
|
||||
//Set the expiration time
|
||||
$item->expiresAfter(!$this->debugMode ? self::CACHE_DETAIL_EXPIRATION : 10);
|
||||
|
||||
return $provider->getDetails($part_id);
|
||||
return $provider->getDetails($part_id, $options);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
312
src/Services/InfoProviderSystem/Providers/AIWebProvider.php
Normal file
312
src/Services/InfoProviderSystem/Providers/AIWebProvider.php
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
* Copyright (C) 2026 Rahul Singh (https://github.com/rahools)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Services\InfoProviderSystem\Providers;
|
||||
|
||||
use App\Exceptions\ProviderIDNotSupportedException;
|
||||
use App\Helpers\RandomizeUseragentHttpClient;
|
||||
use App\Services\AI\AIPlatformRegistry;
|
||||
use App\Services\InfoProviderSystem\CreateFromUrlHelper;
|
||||
use App\Services\InfoProviderSystem\DTOJsonSchemaConverter;
|
||||
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
||||
use App\Settings\InfoProviderSystem\AIExtractorSettings;
|
||||
use Brick\Schema\SchemaReader;
|
||||
use Imagine\Image\Format;
|
||||
use Jkphl\Micrometa;
|
||||
use League\HTMLToMarkdown\HtmlConverter;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\AI\Platform\Message\Message;
|
||||
use Symfony\AI\Platform\Message\MessageBag;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
use Symfony\Component\DomCrawler\UriResolver;
|
||||
use Symfony\Component\HttpClient\NoPrivateNetworkHttpClient;
|
||||
use Symfony\Component\Intl\Languages;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
use function Symfony\Component\String\u;
|
||||
|
||||
|
||||
final class AIWebProvider implements InfoProviderInterface
|
||||
{
|
||||
use FixAndValidateUrlTrait;
|
||||
|
||||
private const DISTRIBUTOR_NAME = 'Website';
|
||||
|
||||
private readonly HttpClientInterface $httpClient;
|
||||
|
||||
public function __construct(
|
||||
HttpClientInterface $httpClient,
|
||||
private readonly AIExtractorSettings $settings,
|
||||
private readonly AIPlatformRegistry $AIPlatformRegistry,
|
||||
private readonly DTOJsonSchemaConverter $jsonSchemaConverter,
|
||||
private readonly CacheItemPoolInterface $partInfoCache,
|
||||
private readonly CreateFromUrlHelper $createFromUrlHelper,
|
||||
) {
|
||||
//Use NoPrivateNetworkHttpClient to prevent SSRF vulnerabilities, and RandomizeUseragentHttpClient to make it harder for servers to block us
|
||||
$this->httpClient = (new RandomizeUseragentHttpClient(new NoPrivateNetworkHttpClient($httpClient)))->withOptions(
|
||||
[
|
||||
'timeout' => 15,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function getProviderInfo(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'AI Web Extractor',
|
||||
'description' => 'Extract part info from any URL using LLM',
|
||||
//'url' => 'https://openrouter.ai',
|
||||
'disabled_help' => 'Configure AI settings',
|
||||
'settings_class' => AIExtractorSettings::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function getProviderKey(): string
|
||||
{
|
||||
return 'ai_web';
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->settings->platform !== null && $this->settings->model !== null && $this->settings->model !== '';
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
$url = $this->fixAndValidateURL($keyword);
|
||||
|
||||
if (!($options[self::OPTION_SKIP_DELEGATION] ?? false)) {
|
||||
//Before loading the page, try to delegate to another provider
|
||||
$delegatedPart = $this->createFromUrlHelper->delegateToOtherProvider($url, $this);
|
||||
if ($delegatedPart !== null) {
|
||||
return [$delegatedPart];
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$new_options = $options;
|
||||
$new_options[self::OPTION_SKIP_DELEGATION] = true; //Skip delegation for the getDetails call to prevent infinite loops
|
||||
|
||||
return [
|
||||
$this->getDetails($keyword, $new_options)
|
||||
]; } catch (ProviderIDNotSupportedException $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
$url = $this->fixAndValidateURL($id);
|
||||
|
||||
if (!($options[self::OPTION_SKIP_DELEGATION] ?? false)) {
|
||||
//Before loading the page, try to delegate to another provider
|
||||
$delegatedPart = $this->createFromUrlHelper->delegateToOtherProviderDetails($url, $this);
|
||||
if ($delegatedPart !== null) {
|
||||
return $delegatedPart;
|
||||
}
|
||||
}
|
||||
|
||||
//Check if we have a cached result for this URL, to avoid unnecessary LLM calls, which can be slow and costly.
|
||||
$cacheKey = 'ai_web_'.hash('xxh3', $url);
|
||||
|
||||
//If ignore cache option is set, skip cache and fetch fresh data
|
||||
if ($options[self::OPTION_NO_CACHE] ?? false) {
|
||||
$this->partInfoCache->deleteItem($cacheKey);
|
||||
}
|
||||
|
||||
//Return cached result if available
|
||||
$cacheItem = $this->partInfoCache->getItem($cacheKey);
|
||||
if ($cacheItem->isHit()) {
|
||||
return $cacheItem->get();
|
||||
}
|
||||
|
||||
// Fetch HTML content
|
||||
$response = $this->httpClient->request('GET', $url);
|
||||
$html = $response->getContent();
|
||||
|
||||
//Convert html to markdown, to provide a cleaner input to the LLM.
|
||||
$markdown = $this->htmlToMarkdown($html, $url);
|
||||
//Truncate markdown to max content length, if needed
|
||||
$markdown = u($markdown)->truncate($this->settings->maxContentLength, '... [truncated]')->toString();
|
||||
|
||||
//Extract structured data using traditional methods, to provide additional context to the LLM. This can help improve accuracy, especially for technical specifications that might be in tables or specific formats.
|
||||
$structuredData = $this->extractStructuredData($html, $url);
|
||||
|
||||
// Call LLM
|
||||
$llmResponse = $this->callLLM($markdown, $url, $structuredData);
|
||||
|
||||
// Build and return PartDetailDTO
|
||||
$result = $this->jsonSchemaConverter->jsonToDTO($llmResponse, $this->getProviderKey(), $url, $url, self::DISTRIBUTOR_NAME);
|
||||
|
||||
// Cache the result for future use, to improve performance and reduce costs.
|
||||
$cacheItem->set($result);
|
||||
$cacheItem->expiresAfter(3600 * 2); //Cache for 2 hours, as web content can change frequently, but we still want to benefit from caching for repeated accesses.
|
||||
$this->partInfoCache->save($cacheItem);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts structured data from the HTML using microformats.
|
||||
* @param string $html
|
||||
* @param string $url
|
||||
* @return string JSON encoded structured data
|
||||
*/
|
||||
private function extractStructuredData(string $html, string $url): string
|
||||
{
|
||||
//Only parse microdata, json-ld and rdfa, as they are the most common formats for structured data on product pages. Links and microformat only create clutter for the LLM
|
||||
$micrometa = new Micrometa\Ports\Parser(Micrometa\Ports\Format::JSON_LD | Micrometa\Ports\Format::MICRODATA | Micrometa\Ports\Format::RDFA_LITE);
|
||||
$items = $micrometa($url, $html);
|
||||
|
||||
return json_encode($items->toObject(), JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
private function htmlToMarkdown(string $html, string $url): string
|
||||
{
|
||||
|
||||
$crawler = new Crawler($html);
|
||||
|
||||
//Replace relative URLs with absolute URLs, to ensure that the LLM has full context and can access the links if needed.
|
||||
$baseUrl = $crawler->getBaseHref() ?? $url;
|
||||
|
||||
//Replace all relative links with their absolute counnterparts, to provide more context to the LLM and to ensure that any links included in the markdown are valid and can be accessed if needed.
|
||||
$crawler->filter('a')->each(function (Crawler $node) use ($baseUrl) {
|
||||
$href = $node->attr('href');
|
||||
if ($href) {
|
||||
$absoluteUrl = UriResolver::resolve($href, $baseUrl);
|
||||
//@phpstan-ignore-next-line we know that getNode(0) will always return a DOMElement, because the crawler is initialized with valid HTML and we are filtering for 'a' tags, which are always DOMElements.
|
||||
$node->getNode(0)->setAttribute('href', $absoluteUrl);
|
||||
}
|
||||
});
|
||||
|
||||
$crawler->filter('img')->each(function (Crawler $node) use ($baseUrl) {
|
||||
$src = $node->attr('src');
|
||||
if ($src) {
|
||||
$absoluteUrl = UriResolver::resolve($src, $baseUrl);
|
||||
//@phpstan-ignore-next-line we know that getNode(0) will always return a DOMElement, because the crawler is initialized with valid HTML and we are filtering for 'a' tags, which are always DOMElements.
|
||||
$node->getNode(0)->setAttribute('src', $absoluteUrl);
|
||||
}
|
||||
});
|
||||
|
||||
//Extract only the main content of the page to avoid overwhelming the LLM with irrelevant information.
|
||||
$mainContent = $crawler->filter('main, article, #content');
|
||||
|
||||
// If we found a specific content area, get its HTML; otherwise, use the whole body.
|
||||
//Concat the html of all matched nodes, to provide more context to the LLM, especially for pages that use multiple sections for product info.
|
||||
if ($mainContent->count() > 0) {
|
||||
$htmlToConvert = '';
|
||||
foreach ($mainContent as $node) {
|
||||
$htmlToConvert .= $node->ownerDocument->saveHTML($node);
|
||||
$htmlToConvert .= "\n\n"; // Add some spacing between sections
|
||||
}
|
||||
} else {
|
||||
//Use the whole body content, as it might contain relevant information, especially for simpler pages that don't have a clear main/content section.
|
||||
$htmlToConvert = $crawler->outerHtml();
|
||||
}
|
||||
|
||||
|
||||
//Concert to markdown
|
||||
$converter = new HtmlConverter([
|
||||
'strip_tags' => true, // Removes tags that aren't Markdown-compatible (like <div>)
|
||||
'hard_break' => true, // Preserves line breaks
|
||||
'remove_nodes' => 'nav footer script style' // Extra safety layer
|
||||
]);
|
||||
|
||||
return $converter->convert($htmlToConvert);
|
||||
}
|
||||
|
||||
public function getCapabilities(): array
|
||||
{
|
||||
return [
|
||||
ProviderCapabilities::BASIC,
|
||||
ProviderCapabilities::PICTURE,
|
||||
ProviderCapabilities::DATASHEET,
|
||||
ProviderCapabilities::PRICE,
|
||||
ProviderCapabilities::PARAMETERS,
|
||||
];
|
||||
}
|
||||
|
||||
private function callLLM(string $htmlContent, string $url, ?string $structuredData = null): array
|
||||
{
|
||||
$input = new MessageBag(
|
||||
Message::forSystem($this->buildSystemPrompt()),
|
||||
Message::ofUser("Extract part information from this webpage content:\n\nURL: $url\n\n$htmlContent")
|
||||
);
|
||||
|
||||
if ($structuredData) {
|
||||
$input->add(Message::ofUser("Following data was extracted using traditional methods, but might be incomplete or inaccurate.
|
||||
Enrich it with the actual website data:\n\n".$structuredData));
|
||||
}
|
||||
|
||||
try {
|
||||
$aiPlatform = $this->AIPlatformRegistry->getPlatform($this->settings->platform ?? throw new \RuntimeException('No AI platform selected') );
|
||||
|
||||
//'openai/gpt-5-mini'
|
||||
$result = $aiPlatform->invoke($this->settings->model ?? throw new \RuntimeException('No model selected'), $input, [
|
||||
'response_format' => [
|
||||
'type' => 'json_schema',
|
||||
'json_schema' => $this->jsonSchemaConverter->getJSONSchema(),
|
||||
]
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
throw new \RuntimeException('LLM invocation failed: '.$e->getMessage(), previous: $e);
|
||||
}
|
||||
|
||||
return $result->getResult()->getContent();
|
||||
}
|
||||
|
||||
private function buildSystemPrompt(): string
|
||||
{
|
||||
$tmp = <<<'PROMPT'
|
||||
You are an expert at extracting electronic component information from web pages. Extract structured data in JSON format, from markdown extracted from a product page.
|
||||
Focus on the main content of the page, such as product descriptions, specifications, and tables. Ignore navigation menus, footers, and sidebars.
|
||||
|
||||
Rules:
|
||||
- manufacturing_status: Use "active", "obsolete", "nrfnd" (not recommended for new designs), "discontinued", or null
|
||||
- parameters: Extract technical specs like voltage, current, temperature, etc. and put them into the fields according to the JSON schema. Include units if available.
|
||||
- prices: Extract pricing tiers with minimum_quantity, price, and currency code
|
||||
- URLs must be absolute (include https://...)
|
||||
- If information is not found, use null
|
||||
- Try to avoid duplicating parameters, if the same parameter is mentioned multiple times, or if it is already used in another field.
|
||||
- Include only the 1 to 3 most relevant images, such as the main product image or important diagrams. Ignore decorative images, logos, or icons.
|
||||
- Extract GTIN / EAN if available, as it can be useful for matching parts across different sources, even if the part number is different.
|
||||
- Include detailed product description into notes field, as it can contain important information that doesn't fit into other fields, such as features, applications, or unique selling points.
|
||||
|
||||
PROMPT;
|
||||
|
||||
if ($this->settings->outputLanguage === null) {
|
||||
$tmp .= "\n\nProvide the response in the same language of the webpage.";
|
||||
} else {
|
||||
$tmp .= "\n\nThe response must be in ". Languages::getName($this->settings->outputLanguage, 'en') ." language. Translate texts if needed.";
|
||||
}
|
||||
|
||||
if ($this->settings->additionalInstructions) {
|
||||
$tmp .= "\n\nAdditional instructions:\n" . $this->settings->additionalInstructions;
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -34,7 +34,8 @@ interface BatchInfoProviderInterface extends InfoProviderInterface
|
|||
* Search for multiple keywords in a single batch operation and return the results, ordered by the keywords.
|
||||
* This allows for a more efficient search compared to running multiple single searches.
|
||||
* @param string[] $keywords
|
||||
* @param array<string, mixed> $options An associative array of options which can be used to modify the search behavior. The supported options depend on the provider and should be documented in the provider's documentation.
|
||||
* @return array<string, SearchResultDTO[]> An associative array where the key is the keyword and the value is the search results for that keyword
|
||||
*/
|
||||
public function searchByKeywordsBatch(array $keywords): array;
|
||||
public function searchByKeywordsBatch(array $keywords, array $options = []): array;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ class BuerklinProvider implements BatchInfoProviderInterface, URLHandlerInfoProv
|
|||
];
|
||||
}
|
||||
|
||||
private function getProduct(string $code): array
|
||||
private function getProduct(string $code, bool $use_cache = true): array
|
||||
{
|
||||
$code = strtoupper(trim($code));
|
||||
if ($code === '') {
|
||||
|
|
@ -132,6 +132,11 @@ class BuerklinProvider implements BatchInfoProviderInterface, URLHandlerInfoProv
|
|||
md5($code . '|' . $this->settings->language . '|' . $this->settings->currency)
|
||||
);
|
||||
|
||||
if (!$use_cache) {
|
||||
$this->partInfoCache->deleteItem($cacheKey);
|
||||
unset($this->productCache[$cacheKey]);
|
||||
}
|
||||
|
||||
if (isset($this->productCache[$cacheKey])) {
|
||||
return $this->productCache[$cacheKey];
|
||||
}
|
||||
|
|
@ -461,9 +466,11 @@ class BuerklinProvider implements BatchInfoProviderInterface, URLHandlerInfoProv
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $keyword
|
||||
* @param array $options
|
||||
* @return PartDetailDTO[]
|
||||
*/
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
$keyword = strtoupper(trim($keyword));
|
||||
if ($keyword === '') {
|
||||
|
|
@ -486,17 +493,18 @@ class BuerklinProvider implements BatchInfoProviderInterface, URLHandlerInfoProv
|
|||
|
||||
// Fallback: try direct lookup by code
|
||||
try {
|
||||
$product = $this->getProduct($keyword);
|
||||
$product = $this->getProduct($keyword, use_cache: !($options[self::OPTION_NO_CACHE] ?? false));
|
||||
return [$this->getPartDetail($product)];
|
||||
} catch (\Throwable $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getDetails(string $id): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
// Detail endpoint is /products/{code}/
|
||||
$response = $this->getProduct($id);
|
||||
//By default use cache for details, but allow bypassing cache with option (e.g. for refresh)
|
||||
$response = $this->getProduct($id, use_cache: !($options[self::OPTION_NO_CACHE] ?? false));
|
||||
|
||||
return $this->getPartDetail($response);
|
||||
}
|
||||
|
|
@ -588,10 +596,11 @@ class BuerklinProvider implements BatchInfoProviderInterface, URLHandlerInfoProv
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string[] $keywords
|
||||
* @param array $keywords
|
||||
* @param array $options
|
||||
* @return array<string, SearchResultDTO[]>
|
||||
*/
|
||||
public function searchByKeywordsBatch(array $keywords): array
|
||||
public function searchByKeywordsBatch(array $keywords, array $options = []): array
|
||||
{
|
||||
/** @var array<string, SearchResultDTO[]> $results */
|
||||
$results = [];
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ class CanopyProvider implements InfoProviderInterface
|
|||
return null;
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
$response = $this->httpClient->request('GET', self::SEARCH_API_URL, [
|
||||
'query' => [
|
||||
|
|
@ -177,15 +177,17 @@ class CanopyProvider implements InfoProviderInterface
|
|||
return new PurchaseInfoDTO(self::DISTRIBUTOR_NAME, order_number: $asin, prices: $priceDtos, product_url: $this->productPageFromASIN($asin));
|
||||
}
|
||||
|
||||
public function getDetails(string $id): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
//Check that the id is a valid ASIN (10 characters, letters and numbers)
|
||||
if (!preg_match('/^[A-Z0-9]{10}$/', $id)) {
|
||||
throw new \InvalidArgumentException("The id must be a valid ASIN (10 characters, letters and numbers)");
|
||||
}
|
||||
|
||||
$do_not_cache = ($options[self::OPTION_NO_CACHE] ?? false) || $this->settings->alwaysGetDetails;
|
||||
|
||||
//Use cached details if available and the settings allow it, to avoid unnecessary API requests, since the search results already contain most of the details
|
||||
if(!$this->settings->alwaysGetDetails && ($cached = $this->getFromCache($id)) !== null) {
|
||||
if(!$do_not_cache && ($cached = $this->getFromCache($id)) !== null) {
|
||||
return $cached;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ readonly class ConradProvider implements InfoProviderInterface, URLHandlerInfoPr
|
|||
return null;
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
$url = $this->settings->shopID->getAPIRoot() . self::SEARCH_ENDPOINT . '/'
|
||||
. $this->settings->shopID->getDomainEnd() . '/' . $this->settings->shopID->getLanguage()
|
||||
|
|
@ -279,7 +279,7 @@ readonly class ConradProvider implements InfoProviderInterface, URLHandlerInfoPr
|
|||
);
|
||||
}
|
||||
|
||||
public function getDetails(string $id): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
$productInfoURL = $this->settings->shopID->getAPIRoot() . '/product/1/service/' . $this->settings->shopID->getShopID()
|
||||
. '/product/' . $id;
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ class DigikeyProvider implements InfoProviderInterface
|
|||
return $this->settings->clientId !== null && $this->settings->clientId !== '' && $this->authTokenManager->hasToken(self::OAUTH_APP_NAME);
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
$request = [
|
||||
'Keywords' => $keyword,
|
||||
|
|
@ -159,7 +159,7 @@ class DigikeyProvider implements InfoProviderInterface
|
|||
return $result;
|
||||
}
|
||||
|
||||
public function getDetails(string $id): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
try {
|
||||
$response = $this->digikeyClient->request('GET', '/products/v4/search/' . urlencode($id) . '/productdetails', [
|
||||
|
|
|
|||
|
|
@ -282,12 +282,12 @@ class Element14Provider implements InfoProviderInterface, URLHandlerInfoProvider
|
|||
};
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
return $this->queryByTerm('any:' . $keyword);
|
||||
}
|
||||
|
||||
public function getDetails(string $id): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
$tmp = $this->queryByTerm('id:' . $id);
|
||||
if (count($tmp) === 0) {
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class EmptyProvider implements InfoProviderInterface
|
|||
return true;
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
return [
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ class EmptyProvider implements InfoProviderInterface
|
|||
];
|
||||
}
|
||||
|
||||
public function getDetails(string $id): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
throw new \RuntimeException('No part details available');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Services\InfoProviderSystem\Providers;
|
||||
|
||||
use App\Exceptions\ProviderIDNotSupportedException;
|
||||
|
||||
trait FixAndValidateUrlTrait
|
||||
{
|
||||
private function fixAndValidateURL(string $url): string
|
||||
{
|
||||
$originalUrl = $url;
|
||||
|
||||
//Add scheme if missing
|
||||
if (!preg_match('/^https?:\/\//', $url)) {
|
||||
//Remove any leading slashes
|
||||
$url = ltrim($url, '/');
|
||||
|
||||
//If the URL starts with https:/ or http:/, add the missing slash
|
||||
//Traefik removes the double slash as secruity measure, so we want to be forgiving and add it back if needed
|
||||
//See https://github.com/Part-DB/Part-DB-server/issues/1296
|
||||
if (preg_match('/^https?:\/[^\/]/', $url)) {
|
||||
$url = preg_replace('/^(https?:)\/([^\/])/', '$1//$2', $url);
|
||||
} else {
|
||||
$url = 'https://'.$url;
|
||||
}
|
||||
}
|
||||
|
||||
//If this is not a valid URL with host, domain and path, throw an exception
|
||||
if (filter_var($url, FILTER_VALIDATE_URL) === false ||
|
||||
parse_url($url, PHP_URL_HOST) === null ||
|
||||
parse_url($url, PHP_URL_PATH) === null) {
|
||||
throw new ProviderIDNotSupportedException("The given ID is not a valid URL: ".$originalUrl);
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
|
|
@ -25,6 +25,7 @@ namespace App\Services\InfoProviderSystem\Providers;
|
|||
|
||||
use App\Exceptions\ProviderIDNotSupportedException;
|
||||
use App\Helpers\RandomizeUseragentHttpClient;
|
||||
use App\Services\InfoProviderSystem\CreateFromUrlHelper;
|
||||
use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
|
||||
|
|
@ -48,12 +49,14 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|||
class GenericWebProvider implements InfoProviderInterface
|
||||
{
|
||||
|
||||
use FixAndValidateUrlTrait;
|
||||
|
||||
public const DISTRIBUTOR_NAME = 'Website';
|
||||
|
||||
private readonly HttpClientInterface $httpClient;
|
||||
|
||||
public function __construct(HttpClientInterface $httpClient, private readonly GenericWebProviderSettings $settings,
|
||||
private readonly ProviderRegistry $providerRegistry, private readonly PartInfoRetriever $infoRetriever,
|
||||
private readonly CreateFromUrlHelper $createFromUrlHelper,
|
||||
)
|
||||
{
|
||||
//Use NoPrivateNetworkHttpClient to prevent SSRF vulnerabilities, and RandomizeUseragentHttpClient to make it harder for servers to block us
|
||||
|
|
@ -85,19 +88,23 @@ class GenericWebProvider implements InfoProviderInterface
|
|||
return $this->settings->enabled;
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
$url = $this->fixAndValidateURL($keyword);
|
||||
|
||||
//Before loading the page, try to delegate to another provider
|
||||
$delegatedPart = $this->delegateToOtherProvider($url);
|
||||
if ($delegatedPart !== null) {
|
||||
return [$delegatedPart];
|
||||
if (!($options[self::OPTION_SKIP_DELEGATION] ?? false)) {
|
||||
//Before loading the page, try to delegate to another provider
|
||||
$delegatedPart = $this->createFromUrlHelper->delegateToOtherProvider($url, $this);
|
||||
if ($delegatedPart !== null) {
|
||||
return [$delegatedPart];
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$new_options = $options;
|
||||
$new_options[self::OPTION_SKIP_DELEGATION] = true; //Skip delegation for the getDetails call to prevent infinite loops
|
||||
return [
|
||||
$this->getDetails($keyword, false) //We already tried delegation
|
||||
$this->getDetails($keyword, $new_options)
|
||||
]; } catch (ProviderIDNotSupportedException $e) {
|
||||
return [];
|
||||
}
|
||||
|
|
@ -274,78 +281,16 @@ class GenericWebProvider implements InfoProviderInterface
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates the URL to another provider if possible, otherwise return null
|
||||
* @param string $url
|
||||
* @return SearchResultDTO|null
|
||||
*/
|
||||
private function delegateToOtherProvider(string $url): ?SearchResultDTO
|
||||
{
|
||||
//Extract domain from url:
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
if ($host === false || $host === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$provider = $this->providerRegistry->getProviderHandlingDomain($host);
|
||||
|
||||
if ($provider !== null && $provider->isActive() && $provider->getProviderKey() !== $this->getProviderKey()) {
|
||||
try {
|
||||
$id = $provider->getIDFromURL($url);
|
||||
if ($id !== null) {
|
||||
$results = $this->infoRetriever->searchByKeyword($id, [$provider]);
|
||||
if (count($results) > 0) {
|
||||
return $results[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (ProviderIDNotSupportedException $e) {
|
||||
//Ignore and continue
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function fixAndValidateURL(string $url): string
|
||||
{
|
||||
$originalUrl = $url;
|
||||
|
||||
//Add scheme if missing
|
||||
if (!preg_match('/^https?:\/\//', $url)) {
|
||||
//Remove any leading slashes
|
||||
$url = ltrim($url, '/');
|
||||
|
||||
//If the URL starts with https:/ or http:/, add the missing slash
|
||||
//Traefik removes the double slash as secruity measure, so we want to be forgiving and add it back if needed
|
||||
//See https://github.com/Part-DB/Part-DB-server/issues/1296
|
||||
if (preg_match('/^https?:\/[^\/]/', $url)) {
|
||||
$url = preg_replace('/^(https?:)\/([^\/])/', '$1//$2', $url);
|
||||
} else {
|
||||
$url = 'https://'.$url;
|
||||
}
|
||||
}
|
||||
|
||||
//If this is not a valid URL with host, domain and path, throw an exception
|
||||
if (filter_var($url, FILTER_VALIDATE_URL) === false ||
|
||||
parse_url($url, PHP_URL_HOST) === null ||
|
||||
parse_url($url, PHP_URL_PATH) === null) {
|
||||
throw new ProviderIDNotSupportedException("The given ID is not a valid URL: ".$originalUrl);
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function getDetails(string $id, bool $check_for_delegation = true): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
$url = $this->fixAndValidateURL($id);
|
||||
|
||||
if ($check_for_delegation) {
|
||||
if (!($options[self::OPTION_SKIP_DELEGATION] ?? false)) {
|
||||
//Before loading the page, try to delegate to another provider
|
||||
$delegatedPart = $this->delegateToOtherProvider($url);
|
||||
$delegatedPart = $this->createFromUrlHelper->delegateToOtherProviderDetails($url, $this);
|
||||
if ($delegatedPart !== null) {
|
||||
return $this->infoRetriever->getDetailsForSearchResult($delegatedPart);
|
||||
return $delegatedPart;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
|
|||
|
||||
interface InfoProviderInterface
|
||||
{
|
||||
public const OPTION_NO_CACHE = 'no_cache'; // if set to true, the provider should not use any cache and retrieve fresh data from the source
|
||||
public const OPTION_SKIP_DELEGATION = 'skip_delegation'; // if set to true, the provider should not delegate the request to other providers, even if it supports delegation.
|
||||
|
||||
/**
|
||||
* Get information about this provider
|
||||
|
|
@ -61,16 +63,18 @@ interface InfoProviderInterface
|
|||
/**
|
||||
* Searches for a keyword and returns a list of search results
|
||||
* @param string $keyword The keyword to search for
|
||||
* @param array $options An associative array of options for the search, which can be used to pass additional parameters to the provider (e.g. filters, pagination, etc.). The content of this array is provider specific and not defined by the interface
|
||||
* @return SearchResultDTO[] A list of search results
|
||||
*/
|
||||
public function searchByKeyword(string $keyword): array;
|
||||
public function searchByKeyword(string $keyword, array $options = []): array;
|
||||
|
||||
/**
|
||||
* Returns detailed information about the part with the given id
|
||||
* @param string $id
|
||||
* @param array $options An associative array of options for the search, which can be used to pass additional parameters to the provider (e.g. filters, pagination, etc.). The content of this array is provider specific and not defined by the interface
|
||||
* @return PartDetailDTO
|
||||
*/
|
||||
public function getDetails(string $id): PartDetailDTO;
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO;
|
||||
|
||||
/**
|
||||
* A list of capabilities this provider supports (which kind of data it can provide).
|
||||
|
|
|
|||
|
|
@ -349,17 +349,18 @@ class LCSCProvider implements BatchInfoProviderInterface, URLHandlerInfoProvider
|
|||
return $result;
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
return $this->queryByTerm($keyword, true); // Use lightweight mode for search
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch search multiple keywords asynchronously (like JavaScript Promise.all)
|
||||
* @param array $keywords Array of keywords to search
|
||||
* @param array $keywords
|
||||
* @param array $options
|
||||
* @return array Results indexed by keyword
|
||||
*/
|
||||
public function searchByKeywordsBatch(array $keywords): array
|
||||
public function searchByKeywordsBatch(array $keywords, array $options = []): array
|
||||
{
|
||||
if (empty($keywords)) {
|
||||
return [];
|
||||
|
|
@ -396,6 +397,7 @@ class LCSCProvider implements BatchInfoProviderInterface, URLHandlerInfoProvider
|
|||
// Now collect all results (like .then() in JavaScript)
|
||||
foreach ($responses as $keyword => $response) {
|
||||
try {
|
||||
$keyword = (string) $keyword;
|
||||
$arr = $response->toArray(); // This waits for the response
|
||||
$results[$keyword] = $this->processSearchResponse($arr, $keyword);
|
||||
} catch (\Exception $e) {
|
||||
|
|
@ -428,7 +430,7 @@ class LCSCProvider implements BatchInfoProviderInterface, URLHandlerInfoProvider
|
|||
return $result;
|
||||
}
|
||||
|
||||
public function getDetails(string $id): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
$tmp = $this->queryByTerm($id, false);
|
||||
if (count($tmp) === 0) {
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ class MouserProvider implements InfoProviderInterface
|
|||
return $this->settings->apiKey !== '' && $this->settings->apiKey !== null;
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
/*
|
||||
SearchByKeywordRequest description:
|
||||
|
|
@ -144,7 +144,7 @@ class MouserProvider implements InfoProviderInterface
|
|||
return $this->responseToDTOArray($response);
|
||||
}
|
||||
|
||||
public function getDetails(string $id): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
/*
|
||||
SearchByPartRequest description:
|
||||
|
|
|
|||
|
|
@ -278,12 +278,13 @@ class OEMSecretsProvider implements InfoProviderInterface
|
|||
* and debugging with local JSON files. The results are processed, cached, and then sorted based
|
||||
* on the keyword and specified criteria.
|
||||
*
|
||||
* @param string $keyword The part number to search for
|
||||
* @param string $keyword
|
||||
* @param array $options
|
||||
* @return array An array of processed product details, sorted by relevance and additional criteria.
|
||||
*
|
||||
* @throws \Exception If the JSON file used for debugging is not found or contains errors.
|
||||
*/
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
/*
|
||||
oemsecrets Part Search API 3.0.1
|
||||
|
|
@ -414,14 +415,20 @@ class OEMSecretsProvider implements InfoProviderInterface
|
|||
* found in the cache, they are returned. If not, an exception is thrown indicating that
|
||||
* the details could not be found.
|
||||
*
|
||||
* @param string $id The unique identifier of the provider or part.
|
||||
* @param string $id
|
||||
* @param array $options
|
||||
* @return PartDetailDTO The detailed information about the part.
|
||||
*
|
||||
* @throws \Exception If no details are found for the given provider ID.
|
||||
*/
|
||||
public function getDetails(string $id): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
$cacheKey = $this->getCacheKey($id);
|
||||
|
||||
if ($options[self::OPTION_NO_CACHE] ?? false) {
|
||||
$this->partInfoCache->deleteItem($cacheKey);
|
||||
}
|
||||
|
||||
$cacheItem = $this->partInfoCache->getItem($cacheKey);
|
||||
|
||||
if ($cacheItem->isHit()) {
|
||||
|
|
|
|||
|
|
@ -326,7 +326,7 @@ class OctopartProvider implements InfoProviderInterface
|
|||
);
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
$graphQL = sprintf(<<<'GRAPHQL'
|
||||
query partSearch($keyword: String, $limit: Int, $currency: String!, $country: String!, $authorizedOnly: Boolean!) {
|
||||
|
|
@ -367,11 +367,13 @@ class OctopartProvider implements InfoProviderInterface
|
|||
return $tmp;
|
||||
}
|
||||
|
||||
public function getDetails(string $id): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
$no_cache = $options[self::OPTION_NO_CACHE] ?? false;
|
||||
|
||||
//Check if we have the part cached
|
||||
$cached = $this->getFromCache($id);
|
||||
if ($cached !== null) {
|
||||
if (!$no_cache && $cached !== null) {
|
||||
return $cached;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class PollinProvider implements InfoProviderInterface, URLHandlerInfoProviderInt
|
|||
return $this->settings->enabled;
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
$response = $this->client->request('GET', 'https://www.pollin.de/search', [
|
||||
'query' => [
|
||||
|
|
@ -110,7 +110,7 @@ class PollinProvider implements InfoProviderInterface, URLHandlerInfoProviderInt
|
|||
};
|
||||
}
|
||||
|
||||
public function getDetails(string $id): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
//Ensure that $id is numeric
|
||||
if (!is_numeric($id)) {
|
||||
|
|
|
|||
|
|
@ -46,6 +46,9 @@ enum ProviderCapabilities
|
|||
/** Provider can provide GTIN for a part */
|
||||
case GTIN;
|
||||
|
||||
/** Provider can provide parameters/specifications for a part */
|
||||
case PARAMETERS;
|
||||
|
||||
/**
|
||||
* Get the order index for displaying capabilities in a stable order.
|
||||
* @return int
|
||||
|
|
@ -59,6 +62,7 @@ enum ProviderCapabilities
|
|||
self::PRICE => 4,
|
||||
self::FOOTPRINT => 5,
|
||||
self::GTIN => 6,
|
||||
self::PARAMETERS => 7,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -71,6 +75,7 @@ enum ProviderCapabilities
|
|||
self::DATASHEET => 'datasheet',
|
||||
self::PRICE => 'price',
|
||||
self::GTIN => 'gtin',
|
||||
self::PARAMETERS => 'parameters',
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -83,6 +88,7 @@ enum ProviderCapabilities
|
|||
self::DATASHEET => 'fa-file-alt',
|
||||
self::PRICE => 'fa-money-bill-wave',
|
||||
self::GTIN => 'fa-barcode',
|
||||
self::PARAMETERS => 'fa-list-ul',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class ReicheltProvider implements InfoProviderInterface
|
|||
return $this->settings->enabled;
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
$response = $this->client->request('GET', sprintf($this->getBaseURL() . '/shop/search/%s', $keyword));
|
||||
$html = $response->getContent();
|
||||
|
|
@ -108,7 +108,7 @@ class ReicheltProvider implements InfoProviderInterface
|
|||
return $results;
|
||||
}
|
||||
|
||||
public function getDetails(string $id): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
//Check that the ID is a number
|
||||
if (!is_numeric($id)) {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class TMEProvider implements InfoProviderInterface, URLHandlerInfoProviderInterf
|
|||
return $this->tmeClient->isUsable();
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
$response = $this->tmeClient->makeRequest('Products/Search', [
|
||||
'Country' => $this->settings->country,
|
||||
|
|
@ -99,7 +99,7 @@ class TMEProvider implements InfoProviderInterface, URLHandlerInfoProviderInterf
|
|||
return $result;
|
||||
}
|
||||
|
||||
public function getDetails(string $id): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
$response = $this->tmeClient->makeRequest('Products/GetProducts', [
|
||||
'Country' => $this->settings->country,
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class TestProvider implements InfoProviderInterface
|
|||
return true;
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
public function searchByKeyword(string $keyword, array $options = []): array
|
||||
{
|
||||
return [
|
||||
new SearchResultDTO(provider_key: $this->getProviderKey(), provider_id: 'element1', name: 'Element 1', description: 'fd'),
|
||||
|
|
@ -72,7 +72,7 @@ class TestProvider implements InfoProviderInterface
|
|||
];
|
||||
}
|
||||
|
||||
public function getDetails(string $id): PartDetailDTO
|
||||
public function getDetails(string $id, array $options = []): PartDetailDTO
|
||||
{
|
||||
return new PartDetailDTO(
|
||||
provider_key: $this->getProviderKey(),
|
||||
|
|
|
|||
|
|
@ -62,6 +62,9 @@ final readonly class GitVersionInfoProvider
|
|||
{
|
||||
if (is_file($this->getGitDirectory() . '/HEAD')) {
|
||||
$git = file($this->getGitDirectory() . '/HEAD');
|
||||
if ($git === false) {
|
||||
return null;
|
||||
}
|
||||
$head = explode('/', $git[0], 3);
|
||||
|
||||
if (!isset($head[2])) {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ enum InstallationType: string
|
|||
{
|
||||
return match ($this) {
|
||||
self::GIT => true,
|
||||
self::DOCKER => false,
|
||||
self::DOCKER => true,
|
||||
// ZIP_RELEASE auto-update not yet implemented
|
||||
self::ZIP_RELEASE => false,
|
||||
self::UNKNOWN => false,
|
||||
|
|
@ -57,7 +57,7 @@ enum InstallationType: string
|
|||
{
|
||||
return match ($this) {
|
||||
self::GIT => 'Run: php bin/console partdb:update',
|
||||
self::DOCKER => 'Pull the new Docker image and recreate the container: docker-compose pull && docker-compose up -d',
|
||||
self::DOCKER => 'Configure Watchtower for one-click updates, or manually: docker-compose pull && docker-compose up -d',
|
||||
self::ZIP_RELEASE => 'Download the new release ZIP from GitHub, extract it over your installation, and run: php bin/console doctrine:migrations:migrate && php bin/console cache:clear',
|
||||
self::UNKNOWN => 'Unable to determine installation type. Please update manually.',
|
||||
};
|
||||
|
|
|
|||
|
|
@ -105,6 +105,6 @@ class UpdateAvailableFacade
|
|||
return $this->updateCache->get(self::CACHE_KEY, function (ItemInterface $item) {
|
||||
$item->expiresAfter(self::CACHE_TTL);
|
||||
return $this->updateChecker->getLatestVersion();
|
||||
});
|
||||
}) ?? ['version' => '0.0.1', 'url' => 'update-checking-failed'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@ class UpdateChecker
|
|||
private readonly InstallationTypeDetector $installationTypeDetector,
|
||||
private readonly GitVersionInfoProvider $gitVersionInfoProvider,
|
||||
#[Autowire(param: 'kernel.debug')] private readonly bool $is_dev_mode,
|
||||
#[Autowire(param: 'kernel.project_dir')] private readonly string $project_dir)
|
||||
#[Autowire(param: 'kernel.project_dir')] private readonly string $project_dir,
|
||||
private readonly ?WatchtowerClient $watchtowerClient = null)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -284,8 +285,16 @@ class UpdateChecker
|
|||
$updateBlockers[] = 'local_changes';
|
||||
}
|
||||
|
||||
if ($installInfo['type'] === InstallationType::DOCKER) {
|
||||
$updateBlockers[] = 'docker_installation';
|
||||
// Docker installations require Watchtower for auto-update
|
||||
$watchtowerConfigured = $this->watchtowerClient !== null && $this->watchtowerClient->isConfigured();
|
||||
$watchtowerAvailable = $watchtowerConfigured && $this->watchtowerClient->isAvailable();
|
||||
|
||||
if ($installInfo['type'] === InstallationType::DOCKER && !$watchtowerConfigured) {
|
||||
$canAutoUpdate = false;
|
||||
$updateBlockers[] = 'docker_no_watchtower';
|
||||
} elseif ($installInfo['type'] === InstallationType::DOCKER && !$watchtowerAvailable) {
|
||||
$canAutoUpdate = false;
|
||||
$updateBlockers[] = 'docker_watchtower_unreachable';
|
||||
}
|
||||
|
||||
return [
|
||||
|
|
@ -301,6 +310,8 @@ class UpdateChecker
|
|||
'can_auto_update' => $canAutoUpdate,
|
||||
'update_blockers' => $updateBlockers,
|
||||
'check_enabled' => $this->privacySettings->checkForUpdates,
|
||||
'watchtower_configured' => $watchtowerConfigured,
|
||||
'watchtower_available' => $watchtowerAvailable,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -299,6 +299,23 @@ class UpdateExecutor
|
|||
);
|
||||
}
|
||||
|
||||
// Docker installations are updated via Watchtower - skip Git/Composer/Yarn checks
|
||||
if ($installType === InstallationType::DOCKER) {
|
||||
// Only check if already locked
|
||||
if ($this->isLocked()) {
|
||||
$lockInfo = $this->getLockInfo();
|
||||
$errors[] = sprintf(
|
||||
'An update is already in progress (started at %s).',
|
||||
$lockInfo['started_at'] ?? 'unknown time'
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
'valid' => empty($errors),
|
||||
'errors' => $errors,
|
||||
];
|
||||
}
|
||||
|
||||
// Check for Git installation
|
||||
if ($installType === InstallationType::GIT) {
|
||||
// Check if git is available
|
||||
|
|
|
|||
125
src/Services/System/WatchtowerClient.php
Normal file
125
src/Services/System/WatchtowerClient.php
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\System;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
/**
|
||||
* HTTP client for communicating with the Watchtower container updater API.
|
||||
* Used to trigger Docker container updates from the Part-DB UI.
|
||||
*
|
||||
* @see https://containrrr.dev/watchtower/
|
||||
*/
|
||||
readonly class WatchtowerClient
|
||||
{
|
||||
public function __construct(
|
||||
private HttpClientInterface $httpClient,
|
||||
private LoggerInterface $logger,
|
||||
#[Autowire(env: 'WATCHTOWER_API_URL')] private string $apiUrl,
|
||||
#[Autowire(env: 'WATCHTOWER_API_TOKEN')] private string $apiToken,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether Watchtower integration is configured (URL and token are set).
|
||||
*/
|
||||
public function isConfigured(): bool
|
||||
{
|
||||
return $this->apiUrl !== '' && $this->apiToken !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Watchtower API is reachable.
|
||||
* Makes a lightweight HTTP request with a short timeout.
|
||||
*/
|
||||
public function isAvailable(): bool
|
||||
{
|
||||
if (!$this->isConfigured()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request('GET', $this->getUpdateEndpoint(), [
|
||||
'headers' => $this->getAuthHeaders(),
|
||||
'timeout' => 3,
|
||||
]);
|
||||
|
||||
// Any response means Watchtower is reachable
|
||||
$statusCode = $response->getStatusCode();
|
||||
return $statusCode < 500;
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->debug('Watchtower availability check failed: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a container update via the Watchtower HTTP API.
|
||||
* This is fire-and-forget: Watchtower will pull the new image and restart the container.
|
||||
*
|
||||
* @return bool True if Watchtower accepted the update request
|
||||
*/
|
||||
public function triggerUpdate(): bool
|
||||
{
|
||||
if (!$this->isConfigured()) {
|
||||
throw new \RuntimeException('Watchtower is not configured. Set WATCHTOWER_API_URL and WATCHTOWER_API_TOKEN.');
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request('POST', $this->getUpdateEndpoint(), [
|
||||
'headers' => $this->getAuthHeaders(),
|
||||
'timeout' => 10,
|
||||
]);
|
||||
|
||||
$statusCode = $response->getStatusCode();
|
||||
|
||||
if ($statusCode >= 200 && $statusCode < 300) {
|
||||
$this->logger->info('Watchtower update triggered successfully.');
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->logger->error('Watchtower update request returned HTTP ' . $statusCode);
|
||||
return false;
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->error('Failed to trigger Watchtower update: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function getUpdateEndpoint(): string
|
||||
{
|
||||
return rtrim($this->apiUrl, '/') . '/v1/update';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function getAuthHeaders(): array
|
||||
{
|
||||
return [
|
||||
'Authorization' => 'Bearer ' . $this->apiToken,
|
||||
];
|
||||
}
|
||||
}
|
||||
43
src/Settings/AISettings/AISettings.php
Normal file
43
src/Settings/AISettings/AISettings.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Settings\AISettings;
|
||||
|
||||
use App\Settings\SettingsIcon;
|
||||
use Jbtronics\SettingsBundle\Settings\EmbeddedSettings;
|
||||
use Jbtronics\SettingsBundle\Settings\Settings;
|
||||
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
|
||||
use Symfony\Component\Translation\TranslatableMessage as TM;
|
||||
|
||||
#[Settings(label: new TM("settings.ai"))]
|
||||
#[SettingsIcon("fa-brain")]
|
||||
class AISettings
|
||||
{
|
||||
use SettingsTrait;
|
||||
|
||||
#[EmbeddedSettings]
|
||||
public ?OpenRouterSettings $openRouter = null;
|
||||
|
||||
#[EmbeddedSettings]
|
||||
public ?LMStudioSettings $lmstudio = null;
|
||||
}
|
||||
53
src/Settings/AISettings/LMStudioSettings.php
Normal file
53
src/Settings/AISettings/LMStudioSettings.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Settings\AISettings;
|
||||
|
||||
use App\Form\Type\APIKeyType;
|
||||
use App\Services\AI\AIPlatformSettingsInterface;
|
||||
use App\Settings\SettingsIcon;
|
||||
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
|
||||
use Jbtronics\SettingsBundle\Settings\Settings;
|
||||
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
|
||||
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
|
||||
use Symfony\Component\Form\Extension\Core\Type\UrlType;
|
||||
use Symfony\Component\Translation\StaticMessage;
|
||||
use Symfony\Component\Translation\TranslatableMessage as TM;
|
||||
|
||||
#[Settings(name: 'ai_lmstudio', label: new TM("settings.ai.lmstudio"))]
|
||||
#[SettingsIcon("fa-robot")]
|
||||
class LMStudioSettings implements AIPlatformSettingsInterface
|
||||
{
|
||||
use SettingsTrait;
|
||||
|
||||
#[SettingsParameter(label: new TM("settings.ai.lmstudio.hosturl"),
|
||||
formType: UrlType::class,
|
||||
formOptions: ["attr" => ["placeholder" => new StaticMessage("http://localhost:1234")]],
|
||||
envVar: "AI_LMSTUDIO_HOSTURL", envVarMode: EnvVarMode::OVERWRITE)]
|
||||
public ?string $hostURL = null;
|
||||
|
||||
public function isAIPlatformEnabled(): bool
|
||||
{
|
||||
return $this->hostURL !== null && $this->hostURL !== "";
|
||||
}
|
||||
}
|
||||
50
src/Settings/AISettings/OpenRouterSettings.php
Normal file
50
src/Settings/AISettings/OpenRouterSettings.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Settings\AISettings;
|
||||
|
||||
use App\Form\Type\APIKeyType;
|
||||
use App\Services\AI\AIPlatformSettingsInterface;
|
||||
use App\Settings\SettingsIcon;
|
||||
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
|
||||
use Jbtronics\SettingsBundle\Settings\Settings;
|
||||
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
|
||||
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
|
||||
use Symfony\Component\Translation\TranslatableMessage as TM;
|
||||
|
||||
#[Settings(name: 'ai_openrouter', label: new TM("settings.ai.openrouter"), description: "settings.ai.openrouter.help")]
|
||||
#[SettingsIcon("fa-robot")]
|
||||
class OpenRouterSettings implements AIPlatformSettingsInterface
|
||||
{
|
||||
use SettingsTrait;
|
||||
|
||||
#[SettingsParameter(label: new TM("settings.ips.element14.apiKey"),
|
||||
formType: APIKeyType::class,
|
||||
formOptions: ["help_html" => true], envVar: "AI_OPENROUTER_KEY", envVarMode: EnvVarMode::OVERWRITE)]
|
||||
public ?string $apiKey = null;
|
||||
|
||||
public function isAIPlatformEnabled(): bool
|
||||
{
|
||||
return $this->apiKey !== null && $this->apiKey !== "";
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Settings;
|
||||
|
||||
use App\Settings\AISettings\AISettings;
|
||||
use App\Settings\BehaviorSettings\BehaviorSettings;
|
||||
use App\Settings\InfoProviderSystem\InfoProviderSettings;
|
||||
use App\Settings\MiscSettings\MiscSettings;
|
||||
|
|
@ -50,6 +51,9 @@ class AppSettings
|
|||
#[EmbeddedSettings]
|
||||
public ?SynonymSettings $synonyms = null;
|
||||
|
||||
#[EmbeddedSettings]
|
||||
public ?AISettings $ai = null;
|
||||
|
||||
#[EmbeddedSettings()]
|
||||
public ?MiscSettings $miscSettings = null;
|
||||
|
||||
|
|
|
|||
78
src/Settings/InfoProviderSystem/AIExtractorSettings.php
Normal file
78
src/Settings/InfoProviderSystem/AIExtractorSettings.php
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Settings\InfoProviderSystem;
|
||||
|
||||
use App\Form\Settings\AiModelsType;
|
||||
use App\Form\Settings\AiPlatformChoiceType;
|
||||
use App\Services\AI\AIPlatforms;
|
||||
use App\Settings\SettingsIcon;
|
||||
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
|
||||
use Jbtronics\SettingsBundle\Settings\Settings;
|
||||
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
|
||||
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
|
||||
use Symfony\AI\Platform\Capability;
|
||||
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Translation\StaticMessage;
|
||||
use Symfony\Component\Translation\TranslatableMessage as TM;
|
||||
use Symfony\Component\Validator\Constraints\Language;
|
||||
|
||||
#[Settings(name: "ai_extractor", label: new TM("settings.ips.ai_extractor"), description: new TM("settings.ips.ai_extractor.description"))]
|
||||
#[SettingsIcon("fa-plug")]
|
||||
class AIExtractorSettings
|
||||
{
|
||||
private const MODEL_SELECTOR_LABEL = 'ai_extractor';
|
||||
|
||||
use SettingsTrait;
|
||||
|
||||
#[SettingsParameter(label: new TM("settings.ips.ai_extractor.ai_platform"),
|
||||
formType: AiPlatformChoiceType::class, formOptions: ['platform_selector_label' => self::MODEL_SELECTOR_LABEL],
|
||||
)]
|
||||
public ?AIPlatforms $platform = null;
|
||||
|
||||
#[SettingsParameter(label: new TM("settings.ips.ai_extractor.model"), description: new TM("settings.ips.ai_extractor.model.help"),
|
||||
formType: AiModelsType::class, formOptions: [
|
||||
'platform_selector' => self::MODEL_SELECTOR_LABEL, 'filter_capability' => Capability::OUTPUT_STRUCTURED,
|
||||
'attr' => ['placeholder' => new StaticMessage('google/gemini-2.5-flash-lite')]
|
||||
],
|
||||
|
||||
)]
|
||||
public ?string $model = null;
|
||||
|
||||
#[SettingsParameter(label: new TM("settings.ips.ai_extractor.max_content_length"),
|
||||
description: new TM("settings.ips.ai_extractor.max_content_length.description"),
|
||||
)]
|
||||
public int $maxContentLength = 50000;
|
||||
|
||||
#[Language]
|
||||
#[SettingsParameter(label: new TM("settings.ips.ai_extractor.output_language"), description: new TM("settings.ips.ai_extractor.output_language.description"),
|
||||
formType: LanguageType::class,
|
||||
)]
|
||||
public ?string $outputLanguage = null;
|
||||
|
||||
#[SettingsParameter(label: new TM("settings.ips.ai_extractor.additional_instructions"), description: new TM("settings.ips.ai_extractor.additional_instructions.description"),
|
||||
formType: TextareaType::class,
|
||||
)]
|
||||
public ?string $additionalInstructions = null;
|
||||
}
|
||||
|
|
@ -72,7 +72,7 @@ class CanopySettings
|
|||
/**
|
||||
* @var string The domain used internally for the API requests. This is not necessarily the same as the domain shown to the user, which is determined by the keys of the ALLOWED_DOMAINS constant
|
||||
*/
|
||||
#[SettingsParameter(label: new TM("settings.ips.tme.country"), formType: ChoiceType::class, formOptions: ["choices" => self::ALLOWED_DOMAINS])]
|
||||
#[SettingsParameter(label: new TM("settings.ips.tme.country"), formType: ChoiceType::class, formOptions: ["choices" => self::ALLOWED_DOMAINS, 'translation_domain' => false])]
|
||||
public string $domain = "DE";
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ class InfoProviderSettings
|
|||
#[EmbeddedSettings]
|
||||
public ?GenericWebProviderSettings $genericWebProvider = null;
|
||||
|
||||
#[EmbeddedSettings]
|
||||
public ?AIExtractorSettings $aiExtractor = null;
|
||||
|
||||
#[EmbeddedSettings]
|
||||
public ?DigikeySettings $digikey = null;
|
||||
|
||||
|
|
@ -75,4 +78,5 @@ class InfoProviderSettings
|
|||
|
||||
#[EmbeddedSettings]
|
||||
public ?CanopySettings $canopy = null;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
*/
|
||||
namespace App\Twig;
|
||||
|
||||
use App\Services\InfoProviderSystem\CreateFromUrlHelper;
|
||||
use Twig\Attribute\AsTwigFunction;
|
||||
use App\Settings\SettingsIcon;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
|
@ -34,7 +35,7 @@ use Twig\Extension\AbstractExtension;
|
|||
|
||||
final readonly class MiscExtension
|
||||
{
|
||||
public function __construct(private EventCommentNeededHelper $eventCommentNeededHelper)
|
||||
public function __construct(private EventCommentNeededHelper $eventCommentNeededHelper, private CreateFromUrlHelper $fromUrlHelper)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -84,4 +85,14 @@ final readonly class MiscExtension
|
|||
|
||||
return $request->getBaseUrl().$request->getPathInfo().$qs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the from url provider is active, false otherwise.
|
||||
* @return bool
|
||||
*/
|
||||
#[AsTwigFunction(name: 'create_from_url_active')]
|
||||
public function create_from_url_active(): bool
|
||||
{
|
||||
return $this->fromUrlHelper->canCreateFromUrl();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
54
symfony.lock
54
symfony.lock
|
|
@ -375,6 +375,54 @@
|
|||
"shivas/versioning-bundle": {
|
||||
"version": "4.0.3"
|
||||
},
|
||||
"symfony/ai-bundle": {
|
||||
"version": "0.8",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "0.1",
|
||||
"ref": "2be6ccd77335c2631fdf12d1680649b072efb8ad"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/ai.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/ai-generic-platform": {
|
||||
"version": "0.8",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "0.1",
|
||||
"ref": "f38913b87380322d4c40c302b41626e811516bc4"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/ai_generic_platform.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/ai-lm-studio-platform": {
|
||||
"version": "0.8",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "0.1",
|
||||
"ref": "e35cced28f6559fc5effccb8f22597f309fedfdf"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/ai_lm_studio_platform.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/ai-open-router-platform": {
|
||||
"version": "0.8",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "0.1",
|
||||
"ref": "c39a146c6ec3df8b874accf6ce1cccbda431a688"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/ai_open_router_platform.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/apache-pack": {
|
||||
"version": "1.0",
|
||||
"recipe": {
|
||||
|
|
@ -393,12 +441,6 @@
|
|||
"symfony/browser-kit": {
|
||||
"version": "v4.2.3"
|
||||
},
|
||||
"symfony/cache": {
|
||||
"version": "v4.2.3"
|
||||
},
|
||||
"symfony/cache-contracts": {
|
||||
"version": "v1.1.5"
|
||||
},
|
||||
"symfony/config": {
|
||||
"version": "v4.2.3"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@
|
|||
{% trans %}info_providers.search.title{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
{% if settings_instance('generic_web_provider').enabled %}
|
||||
{% if create_from_url_active() %}
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ path('info_providers_from_url') }}">
|
||||
<i class="fa-fw fa-solid fa-book-atlas"></i>
|
||||
|
|
|
|||
235
templates/admin/update_manager/docker_progress.html.twig
Normal file
235
templates/admin/update_manager/docker_progress.html.twig
Normal file
|
|
@ -0,0 +1,235 @@
|
|||
{% extends "main_card.html.twig" %}
|
||||
|
||||
{% block title %}{% trans %}update_manager.docker.progress_title{% endtrans %}{% endblock %}
|
||||
|
||||
{% block card_title %}
|
||||
<i class="fab fa-docker" data-docker-update-progress-target="titleIcon"></i>
|
||||
{% trans %}update_manager.docker.progress_title{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block card_content %}
|
||||
<style nonce="{{ csp_nonce('style') }}">
|
||||
.docker-whale {
|
||||
display: inline-block;
|
||||
animation: whale-bob 2s ease-in-out infinite;
|
||||
}
|
||||
.docker-whale svg {
|
||||
fill: #2496ED;
|
||||
}
|
||||
.docker-whale.success {
|
||||
animation: whale-arrive 0.6s ease-out forwards;
|
||||
}
|
||||
.docker-whale.success svg { fill: #198754; }
|
||||
.docker-whale.timeout { animation: none; }
|
||||
.docker-whale.timeout svg { fill: #ffc107; }
|
||||
.docker-whale.failed { animation: none; }
|
||||
.docker-whale.failed svg { fill: #dc3545; }
|
||||
@keyframes whale-bob {
|
||||
0%, 100% { transform: translateY(0) rotate(0deg); }
|
||||
25% { transform: translateY(-8px) rotate(-2deg); }
|
||||
75% { transform: translateY(4px) rotate(1deg); }
|
||||
}
|
||||
@keyframes whale-arrive {
|
||||
0% { transform: scale(1); }
|
||||
50% { transform: scale(1.2); }
|
||||
100% { transform: scale(1); }
|
||||
}
|
||||
.whale-waves {
|
||||
text-align: center;
|
||||
font-size: 0.5rem;
|
||||
color: #2496ED66;
|
||||
animation: wave-flow 3s linear infinite;
|
||||
letter-spacing: -1px;
|
||||
margin-top: -4px;
|
||||
}
|
||||
.docker-whale.success + .whale-waves,
|
||||
.docker-whale.timeout + .whale-waves,
|
||||
.docker-whale.failed + .whale-waves { animation: none; }
|
||||
@keyframes wave-flow {
|
||||
0% { opacity: 0.3; }
|
||||
50% { opacity: 0.7; }
|
||||
100% { opacity: 0.3; }
|
||||
}
|
||||
.step-timestamp { min-width: 60px; text-align: right; }
|
||||
/* Progress bar widths - CSS classes to avoid CSP inline style violations */
|
||||
.docker-progress { height: 25px; }
|
||||
.progress-w-0 { width: 0%; }
|
||||
.progress-w-15 { width: 15%; }
|
||||
.progress-w-30 { width: 30%; }
|
||||
.progress-w-50 { width: 50%; }
|
||||
.progress-w-65 { width: 65%; }
|
||||
.progress-w-80 { width: 80%; }
|
||||
.progress-w-100 { width: 100%; }
|
||||
</style>
|
||||
<div data-controller="docker-update-progress"
|
||||
data-docker-update-progress-health-url-value="{{ path('admin_update_manager_health') }}"
|
||||
data-docker-update-progress-previous-version-value="{{ previous_version }}"
|
||||
data-docker-update-progress-text-pulling-value="{% trans %}update_manager.docker.waiting_for_watchtower{% endtrans %}"
|
||||
data-docker-update-progress-text-pulling-detail-value="{% trans %}update_manager.docker.step_pull_desc{% endtrans %}"
|
||||
data-docker-update-progress-text-restarting-value="{% trans %}update_manager.docker.restarting_title{% endtrans %}"
|
||||
data-docker-update-progress-text-restarting-detail-value="{% trans %}update_manager.docker.step_restart_desc{% endtrans %}"
|
||||
data-docker-update-progress-text-success-value="{% trans %}update_manager.docker.success_title{% endtrans %}"
|
||||
data-docker-update-progress-text-success-detail-value="{% trans %}update_manager.docker.success_message{% endtrans %}"
|
||||
data-docker-update-progress-text-timeout-value="{% trans %}update_manager.docker.timeout_title{% endtrans %}"
|
||||
data-docker-update-progress-text-timeout-detail-value="{% trans %}update_manager.docker.timeout_message{% endtrans %}"
|
||||
data-docker-update-progress-text-step-pull-value="{% trans %}update_manager.docker.step_pull{% endtrans %}"
|
||||
data-docker-update-progress-text-step-restart-value="{% trans %}update_manager.docker.step_restart{% endtrans %}">
|
||||
|
||||
{# Progress Header #}
|
||||
<div class="text-center mb-4">
|
||||
<div class="mb-3">
|
||||
<div class="docker-whale-container">
|
||||
<div class="docker-whale" data-docker-update-progress-target="headerWhale">
|
||||
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="80" height="64">
|
||||
<path d="M13.983 11.078h2.119a.186.186 0 00.186-.185V9.006a.186.186 0 00-.186-.186h-2.119a.185.185 0 00-.185.185v1.888c0 .102.083.185.185.185m-2.954-5.43h2.118a.186.186 0 00.186-.186V3.574a.186.186 0 00-.186-.185h-2.118a.185.185 0 00-.185.185v1.888c0 .102.082.185.185.185m0 2.716h2.118a.187.187 0 00.186-.186V6.29a.186.186 0 00-.186-.185h-2.118a.185.185 0 00-.185.185v1.887c0 .102.082.185.185.186m-2.93 0h2.12a.186.186 0 00.184-.186V6.29a.185.185 0 00-.185-.185H8.1a.185.185 0 00-.185.185v1.887c0 .102.083.185.185.186m-2.964 0h2.119a.186.186 0 00.185-.186V6.29a.185.185 0 00-.185-.185H5.136a.186.186 0 00-.186.185v1.887c0 .102.084.185.186.186m5.893 2.715h2.118a.186.186 0 00.186-.185V9.006a.186.186 0 00-.186-.186h-2.118a.185.185 0 00-.185.185v1.888c0 .102.082.185.185.185m-2.93 0h2.12a.185.185 0 00.184-.185V9.006a.185.185 0 00-.184-.186h-2.12a.185.185 0 00-.184.185v1.888c0 .102.083.185.185.185m-2.964 0h2.119a.185.185 0 00.185-.185V9.006a.185.185 0 00-.184-.186h-2.12a.186.186 0 00-.186.186v1.887c0 .102.084.185.186.185m-2.92 0h2.12a.185.185 0 00.184-.185V9.006a.185.185 0 00-.184-.186h-2.12a.185.185 0 00-.184.185v1.888c0 .102.082.185.185.185M23.763 9.89c-.065-.051-.672-.51-1.954-.51-.338.001-.676.03-1.01.087-.248-1.7-1.653-2.53-1.716-2.566l-.344-.199-.226.327c-.284.438-.49.922-.612 1.43-.23.97-.09 1.882.403 2.661-.595.332-1.55.413-1.744.42H.751a.751.751 0 00-.75.748 11.376 11.376 0 00.692 4.062c.545 1.428 1.355 2.48 2.41 3.124 1.18.723 3.1 1.137 5.275 1.137.983.003 1.963-.086 2.93-.266a12.248 12.248 0 003.823-1.389c.98-.567 1.86-1.288 2.61-2.136 1.252-1.418 1.998-2.997 2.553-4.4h.221c1.372 0 2.215-.549 2.68-1.009.309-.293.55-.65.707-1.046l.098-.288Z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="whale-waves">~ ~ ~ ~ ~</div>
|
||||
</div>
|
||||
</div>
|
||||
<h4 data-docker-update-progress-target="statusText">
|
||||
{% trans %}update_manager.docker.updating{% endtrans %}
|
||||
</h4>
|
||||
<p class="text-muted" data-docker-update-progress-target="statusSubtext">
|
||||
{% trans %}update_manager.docker.updating_via_watchtower{% endtrans %}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{# Progress Bar #}
|
||||
<div class="progress mb-4 docker-progress">
|
||||
<div class="progress-bar progress-bar-striped progress-bar-animated progress-w-15"
|
||||
role="progressbar"
|
||||
aria-valuenow="15"
|
||||
aria-valuemin="0"
|
||||
aria-valuemax="100"
|
||||
data-docker-update-progress-target="progressBar">
|
||||
15%
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Current Step Info #}
|
||||
<div class="alert alert-info mb-4" data-docker-update-progress-target="stepAlert">
|
||||
<strong data-docker-update-progress-target="stepName">{% trans %}update_manager.docker.step_trigger{% endtrans %}</strong>:
|
||||
<span data-docker-update-progress-target="stepMessage">{% trans %}update_manager.docker.step_trigger_desc{% endtrans %}</span>
|
||||
</div>
|
||||
|
||||
{# Success Message #}
|
||||
<div class="alert alert-success mb-4 d-none" data-docker-update-progress-target="successAlert">
|
||||
<i class="fas fa-check-circle me-2"></i>
|
||||
{% trans %}update_manager.docker.success_message{% endtrans %}
|
||||
<br>
|
||||
<strong>{% trans %}update_manager.docker.previous_version{% endtrans %}:</strong>
|
||||
<span data-docker-update-progress-target="previousVersion">{{ previous_version }}</span>
|
||||
→
|
||||
<strong>{% trans %}update_manager.docker.new_version{% endtrans %}:</strong>
|
||||
<span class="badge bg-success" data-docker-update-progress-target="newVersion">...</span>
|
||||
</div>
|
||||
|
||||
{# Timeout Message #}
|
||||
<div class="alert alert-warning mb-4 d-none" data-docker-update-progress-target="timeoutAlert">
|
||||
<i class="fas fa-exclamation-triangle me-2"></i>
|
||||
{% trans %}update_manager.docker.timeout_message{% endtrans %}
|
||||
</div>
|
||||
|
||||
{# Error Message #}
|
||||
<div class="alert alert-danger mb-4 d-none" data-docker-update-progress-target="errorAlert">
|
||||
<i class="fas fa-times-circle me-2"></i>
|
||||
<strong>{% trans %}update_manager.progress.error{% endtrans %}:</strong>
|
||||
<span data-docker-update-progress-target="errorMessage"></span>
|
||||
</div>
|
||||
|
||||
{# Steps Timeline - matches git progress style #}
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
<i class="fas fa-list-ol me-2"></i>{% trans %}update_manager.docker.steps{% endtrans %}
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<ul class="list-group list-group-flush">
|
||||
{# Step 1: Trigger Watchtower #}
|
||||
<li class="list-group-item d-flex align-items-center" data-docker-update-progress-target="stepRow" data-step="trigger">
|
||||
<i class="fas fa-check-circle text-success me-3" data-docker-update-progress-target="stepIcon"></i>
|
||||
<div class="flex-grow-1">
|
||||
<strong>{% trans %}update_manager.docker.step_trigger{% endtrans %}</strong>
|
||||
<br><small class="text-muted" data-docker-update-progress-target="stepDetail">{% trans %}update_manager.docker.step_trigger_desc{% endtrans %}</small>
|
||||
</div>
|
||||
<small class="text-muted step-timestamp" data-docker-update-progress-target="stepTime"></small>
|
||||
</li>
|
||||
|
||||
{# Step 2: Pull Image #}
|
||||
<li class="list-group-item d-flex align-items-center" data-docker-update-progress-target="stepRow" data-step="pull">
|
||||
<i class="fas fa-spinner fa-spin text-primary me-3" data-docker-update-progress-target="stepIcon"></i>
|
||||
<div class="flex-grow-1">
|
||||
<strong>{% trans %}update_manager.docker.step_pull{% endtrans %}</strong>
|
||||
<br><small class="text-muted" data-docker-update-progress-target="stepDetail">{% trans %}update_manager.docker.step_pull_desc{% endtrans %}</small>
|
||||
</div>
|
||||
<small class="text-muted step-timestamp" data-docker-update-progress-target="stepTime"></small>
|
||||
</li>
|
||||
|
||||
{# Step 3: Stop Container #}
|
||||
<li class="list-group-item d-flex align-items-center text-muted" data-docker-update-progress-target="stepRow" data-step="stop">
|
||||
<i class="fas fa-circle me-3" data-docker-update-progress-target="stepIcon"></i>
|
||||
<div class="flex-grow-1">
|
||||
<strong>{% trans %}update_manager.docker.step_stop{% endtrans %}</strong>
|
||||
<br><small class="text-muted" data-docker-update-progress-target="stepDetail">{% trans %}update_manager.docker.step_stop_desc{% endtrans %}</small>
|
||||
</div>
|
||||
<small class="text-muted step-timestamp" data-docker-update-progress-target="stepTime"></small>
|
||||
</li>
|
||||
|
||||
{# Step 4: Restart Container #}
|
||||
<li class="list-group-item d-flex align-items-center text-muted" data-docker-update-progress-target="stepRow" data-step="restart">
|
||||
<i class="fas fa-circle me-3" data-docker-update-progress-target="stepIcon"></i>
|
||||
<div class="flex-grow-1">
|
||||
<strong>{% trans %}update_manager.docker.step_restart{% endtrans %}</strong>
|
||||
<br><small class="text-muted" data-docker-update-progress-target="stepDetail">{% trans %}update_manager.docker.step_restart_desc{% endtrans %}</small>
|
||||
</div>
|
||||
<small class="text-muted step-timestamp" data-docker-update-progress-target="stepTime"></small>
|
||||
</li>
|
||||
|
||||
{# Step 5: Health Check #}
|
||||
<li class="list-group-item d-flex align-items-center text-muted" data-docker-update-progress-target="stepRow" data-step="health">
|
||||
<i class="fas fa-circle me-3" data-docker-update-progress-target="stepIcon"></i>
|
||||
<div class="flex-grow-1">
|
||||
<strong>{% trans %}update_manager.docker.step_health{% endtrans %}</strong>
|
||||
<br><small class="text-muted" data-docker-update-progress-target="stepDetail">{% trans %}update_manager.docker.step_health_desc{% endtrans %}</small>
|
||||
</div>
|
||||
<small class="text-muted step-timestamp" data-docker-update-progress-target="stepTime"></small>
|
||||
</li>
|
||||
|
||||
{# Step 6: Verify Version #}
|
||||
<li class="list-group-item d-flex align-items-center text-muted" data-docker-update-progress-target="stepRow" data-step="verify">
|
||||
<i class="fas fa-circle me-3" data-docker-update-progress-target="stepIcon"></i>
|
||||
<div class="flex-grow-1">
|
||||
<strong>{% trans %}update_manager.docker.step_verify{% endtrans %}</strong>
|
||||
<br><small class="text-muted" data-docker-update-progress-target="stepDetail">{% trans %}update_manager.docker.step_verify_desc{% endtrans %}</small>
|
||||
</div>
|
||||
<small class="text-muted step-timestamp" data-docker-update-progress-target="stepTime"></small>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Elapsed Time #}
|
||||
<div class="text-center text-muted small mb-3">
|
||||
<i class="fas fa-clock me-1"></i>
|
||||
{% trans %}update_manager.docker.elapsed{% endtrans %}:
|
||||
<span data-docker-update-progress-target="elapsedTime">0s</span>
|
||||
</div>
|
||||
|
||||
{# Actions - shown after completion or timeout #}
|
||||
<div class="text-center d-none" data-docker-update-progress-target="actions">
|
||||
<a href="{{ path('admin_update_manager') }}" class="btn btn-secondary me-2">
|
||||
<i class="fas fa-arrow-left me-1"></i> {% trans %}update_manager.progress.back{% endtrans %}
|
||||
</a>
|
||||
<a href="/" class="btn btn-primary">
|
||||
<i class="fas fa-home me-1"></i> {% trans %}update_manager.docker.go_to_homepage{% endtrans %}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{# Warning Notice #}
|
||||
<div class="alert alert-warning mt-4" data-docker-update-progress-target="warningAlert">
|
||||
<i class="fas fa-exclamation-triangle me-2"></i>
|
||||
<strong>{% trans %}update_manager.docker.warning{% endtrans %}:</strong>
|
||||
{% trans %}update_manager.docker.do_not_close{% endtrans %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -75,6 +75,20 @@
|
|||
<span class="badge bg-secondary">{{ status.installation.type_name }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row">{% trans %}update_manager.web_updates_allowed{% endtrans %}</th>
|
||||
<td>{{ helper.boolean_badge(not web_updates_disabled) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans %}update_manager.backup_restore_allowed{% endtrans %}</th>
|
||||
<td>{{ helper.boolean_badge(not backup_restore_disabled) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans %}update_manager.backup_download_allowed{% endtrans %}</th>
|
||||
<td>{{ helper.boolean_badge(not backup_download_disabled) }}</td>
|
||||
</tr>
|
||||
|
||||
{% if status.git.is_git_install %}
|
||||
<tr>
|
||||
<th scope="row">{% trans %}update_manager.git_branch{% endtrans %}</th>
|
||||
|
|
@ -99,25 +113,35 @@
|
|||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th scope="row">{% trans %}update_manager.auto_update_supported{% endtrans %}</th>
|
||||
<td>
|
||||
{{ helper.boolean_badge(status.can_auto_update) }}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row">{% trans %}update_manager.web_updates_allowed{% endtrans %}</th>
|
||||
<td>{{ helper.boolean_badge(not web_updates_disabled) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans %}update_manager.backup_restore_allowed{% endtrans %}</th>
|
||||
<td>{{ helper.boolean_badge(not backup_restore_disabled) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans %}update_manager.backup_download_allowed{% endtrans %}</th>
|
||||
<td>{{ helper.boolean_badge(not backup_download_disabled) }}</td>
|
||||
</tr>
|
||||
{% if is_docker %}
|
||||
{# Docker: show Watchtower status #}
|
||||
<tr>
|
||||
<th scope="row">{% trans %}update_manager.docker.watchtower_status{% endtrans %}</th>
|
||||
<td>
|
||||
{% if status.watchtower_configured|default(false) and status.watchtower_available|default(false) %}
|
||||
<span class="badge bg-success">
|
||||
<i class="fas fa-check me-1"></i>{% trans %}update_manager.docker.watchtower_connected{% endtrans %}
|
||||
</span>
|
||||
{% elseif status.watchtower_configured|default(false) %}
|
||||
<span class="badge bg-warning text-dark">
|
||||
<i class="fas fa-exclamation-triangle me-1"></i>{% trans %}update_manager.docker.watchtower_unreachable_short{% endtrans %}
|
||||
</span>
|
||||
{% else %}
|
||||
<span class="badge bg-secondary">
|
||||
<i class="fas fa-times me-1"></i>{% trans %}update_manager.docker.watchtower_not_configured{% endtrans %}
|
||||
</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
{# Git/other: show update readiness #}
|
||||
<tr>
|
||||
<th scope="row">{% trans %}update_manager.auto_update_supported{% endtrans %}</th>
|
||||
<td>
|
||||
{{ helper.boolean_badge(status.can_auto_update) }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -158,30 +182,63 @@
|
|||
</div>
|
||||
|
||||
{% if status.update_available and status.can_auto_update and validation.valid and not web_updates_disabled %}
|
||||
<form action="{{ path('admin_update_manager_start') }}" method="post"
|
||||
data-controller="update-confirm"
|
||||
data-update-confirm-is-downgrade-value="false"
|
||||
data-update-confirm-target-version-value="{{ status.latest_tag }}"
|
||||
data-update-confirm-confirm-update-value="{{ 'update_manager.confirm_update'|trans }}"
|
||||
data-update-confirm-confirm-downgrade-value="{{ 'update_manager.confirm_downgrade'|trans }}"
|
||||
data-update-confirm-downgrade-warning-value="{{ 'update_manager.downgrade_removes_update_manager'|trans }}">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('update_manager_start') }}">
|
||||
<input type="hidden" name="version" value="{{ status.latest_tag }}">
|
||||
{% if is_docker %}
|
||||
{# Docker update via Watchtower #}
|
||||
<form action="{{ path('admin_update_manager_start_docker') }}" method="post"
|
||||
data-controller="update-confirm"
|
||||
data-update-confirm-is-downgrade-value="false"
|
||||
data-update-confirm-target-version-value="{{ status.latest_tag }}"
|
||||
data-update-confirm-confirm-update-value="{{ 'update_manager.docker.confirm_update'|trans }}"
|
||||
data-update-confirm-confirm-downgrade-value="{{ 'update_manager.confirm_downgrade'|trans }}"
|
||||
data-update-confirm-downgrade-warning-value="{{ 'update_manager.downgrade_removes_update_manager'|trans }}">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('update_manager_start_docker') }}">
|
||||
|
||||
<div class="d-grid gap-2">
|
||||
<button type="submit" class="btn btn-success btn-lg">
|
||||
<i class="fas fa-download me-2"></i>
|
||||
{% trans %}update_manager.update_to{% endtrans %} {{ status.latest_tag }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="d-grid gap-2">
|
||||
<button type="submit" class="btn btn-success btn-lg">
|
||||
<i class="fab fa-docker me-2"></i>
|
||||
{% trans %}update_manager.docker.update_via_watchtower{% endtrans %} {{ status.latest_tag }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="form-check mt-3">
|
||||
<input class="form-check-input" type="checkbox" name="backup" value="1" id="create-backup" checked>
|
||||
<label class="form-check-label" for="create-backup">
|
||||
<i class="fas fa-database me-1"></i> {% trans %}update_manager.create_backup{% endtrans %}
|
||||
</label>
|
||||
</div>
|
||||
</form>
|
||||
<div class="form-check mt-3">
|
||||
<input class="form-check-input" type="checkbox" name="backup" value="1" id="create-backup-docker" checked>
|
||||
<label class="form-check-label" for="create-backup-docker">
|
||||
<i class="fas fa-database me-1"></i> {% trans %}update_manager.create_backup{% endtrans %}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-info mt-3 mb-0 small">
|
||||
<i class="fas fa-info-circle me-1"></i>
|
||||
{% trans %}update_manager.docker.no_rollback_warning{% endtrans %}
|
||||
</div>
|
||||
</form>
|
||||
{% else %}
|
||||
{# Git update #}
|
||||
<form action="{{ path('admin_update_manager_start') }}" method="post"
|
||||
data-controller="update-confirm"
|
||||
data-update-confirm-is-downgrade-value="false"
|
||||
data-update-confirm-target-version-value="{{ status.latest_tag }}"
|
||||
data-update-confirm-confirm-update-value="{{ 'update_manager.confirm_update'|trans }}"
|
||||
data-update-confirm-confirm-downgrade-value="{{ 'update_manager.confirm_downgrade'|trans }}"
|
||||
data-update-confirm-downgrade-warning-value="{{ 'update_manager.downgrade_removes_update_manager'|trans }}">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('update_manager_start') }}">
|
||||
<input type="hidden" name="version" value="{{ status.latest_tag }}">
|
||||
|
||||
<div class="d-grid gap-2">
|
||||
<button type="submit" class="btn btn-success btn-lg">
|
||||
<i class="fas fa-download me-2"></i>
|
||||
{% trans %}update_manager.update_to{% endtrans %} {{ status.latest_tag }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="form-check mt-3">
|
||||
<input class="form-check-input" type="checkbox" name="backup" value="1" id="create-backup" checked>
|
||||
<label class="form-check-label" for="create-backup">
|
||||
<i class="fas fa-database me-1"></i> {% trans %}update_manager.create_backup{% endtrans %}
|
||||
</label>
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if status.published_at %}
|
||||
|
|
@ -229,12 +286,59 @@
|
|||
|
||||
{# Non-auto-update installations info #}
|
||||
{% if not status.can_auto_update %}
|
||||
<div class="alert alert-secondary">
|
||||
<h6 class="alert-heading">
|
||||
<i class="fas fa-info-circle me-2"></i>{% trans%}update_manager.cant_auto_update{% endtrans%}: {{ status.installation.type_name }}
|
||||
</h6>
|
||||
<p class="mb-0">{{ status.installation.update_instructions }}</p>
|
||||
</div>
|
||||
{% if is_docker and not status.watchtower_configured|default(false) %}
|
||||
{# Docker without Watchtower - show setup instructions #}
|
||||
<div class="card border-info mb-4">
|
||||
<div class="card-header bg-info text-white">
|
||||
<i class="fab fa-docker me-2"></i>{% trans %}update_manager.docker.setup_title{% endtrans %}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p>{% trans %}update_manager.docker.setup_description{% endtrans %}</p>
|
||||
|
||||
<h6>{% trans %}update_manager.docker.setup_step1{% endtrans %}</h6>
|
||||
<pre class="bg-dark text-light p-3 rounded"><code>
|
||||
# See documentation for full example: https://docs.part-db.de/installation/installation_docker.html
|
||||
services:
|
||||
watchtower:
|
||||
image: ghcr.io/nicholas-fedor/watchtower:latest
|
||||
container_name: watchtower
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
environment:
|
||||
- WATCHTOWER_HTTP_API_UPDATE=true
|
||||
- WATCHTOWER_HTTP_API_TOKEN=your-secret-token
|
||||
- WATCHTOWER_LABEL_ENABLE=true
|
||||
- WATCHTOWER_CLEANUP=true
|
||||
</code></pre>
|
||||
|
||||
<h6>{% trans %}update_manager.docker.setup_step2{% endtrans %}</h6>
|
||||
<pre class="bg-dark text-light p-3 rounded"><code>WATCHTOWER_API_URL=http://watchtower:8080
|
||||
WATCHTOWER_API_TOKEN=your-secret-token</code></pre>
|
||||
|
||||
<div class="alert alert-warning mb-0 mt-3">
|
||||
<i class="fas fa-exclamation-triangle me-2"></i>
|
||||
{% trans %}update_manager.docker.setup_network_hint{% endtrans %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% elseif is_docker and status.watchtower_configured|default(false) and not status.watchtower_available|default(false) %}
|
||||
{# Docker with Watchtower configured but not reachable #}
|
||||
<div class="alert alert-warning">
|
||||
<h6 class="alert-heading">
|
||||
<i class="fas fa-exclamation-triangle me-2"></i>{% trans %}update_manager.docker.watchtower_unreachable_title{% endtrans %}
|
||||
</h6>
|
||||
<p class="mb-0">{% trans %}update_manager.docker.watchtower_unreachable_description{% endtrans %}</p>
|
||||
</div>
|
||||
{% else %}
|
||||
{# Other non-auto-update installations (ZIP, unknown) #}
|
||||
<div class="alert alert-secondary">
|
||||
<h6 class="alert-heading">
|
||||
<i class="fas fa-info-circle me-2"></i>{% trans%}update_manager.cant_auto_update{% endtrans%}: {{ status.installation.type_name }}
|
||||
</h6>
|
||||
<p class="mb-0">{{ status.installation.update_instructions }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<div class="row">
|
||||
|
|
@ -277,6 +381,9 @@
|
|||
<i class="fas fa-file-alt"></i>
|
||||
</a>
|
||||
{% if release.version != status.current_version and status.can_auto_update and validation.valid and not web_updates_disabled %}
|
||||
{% if is_docker %}
|
||||
{# Docker: version switching not supported, only update to latest via Watchtower #}
|
||||
{% else %}
|
||||
<form action="{{ path('admin_update_manager_start') }}" method="post" class="d-inline"
|
||||
data-controller="update-confirm"
|
||||
data-update-confirm-is-downgrade-value="{{ release.version < status.current_version ? 'true' : 'false' }}"
|
||||
|
|
@ -297,6 +404,7 @@
|
|||
{% endif %}
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
Consider yourself lucky. You found some rare error code. <br> You should maybe inform your administrator about it...
|
||||
{% endblock %}
|
||||
</h3>
|
||||
{% block further_actions %}<p class="help_text">You can try to <a href="javascript:history.back()">Go Back</a> or <a href="{{ path('homepage') }}">Visit the homepage</a>.</p>{% endblock %}
|
||||
{% block further_actions %}<p class="help_text">You can try to <a href="#" onclick="history.back();return false;">Go Back</a> or <a href="{{ path('homepage') }}">Visit the homepage</a>.</p>{% endblock %}
|
||||
{% block admin_contact %}<p class="help_text">If this error persists, please contact your
|
||||
{% if error_page_admin_email is not empty %}
|
||||
<a href="mailto:{{ error_page_admin_email }}">administrator.</a>
|
||||
|
|
|
|||
|
|
@ -22,103 +22,130 @@
|
|||
</p>
|
||||
</div>
|
||||
|
||||
{% if jobs is not empty %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans %}info_providers.bulk_import.job_name{% endtrans %}</th>
|
||||
<th>{% trans %}info_providers.bulk_import.parts_count{% endtrans %}</th>
|
||||
<th>{% trans %}info_providers.bulk_import.results_count{% endtrans %}</th>
|
||||
<th>{% trans %}info_providers.bulk_import.progress{% endtrans %}</th>
|
||||
<th>{% trans %}info_providers.bulk_import.status{% endtrans %}</th>
|
||||
<th>{% trans %}info_providers.bulk_import.created_by{% endtrans %}</th>
|
||||
<th>{% trans %}info_providers.bulk_import.created_at{% endtrans %}</th>
|
||||
<th>{% trans %}info_providers.bulk_import.completed_at{% endtrans %}</th>
|
||||
<th>{% trans %}info_providers.bulk_import.action.label{% endtrans %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for job in jobs %}
|
||||
<tr>
|
||||
<td>
|
||||
<strong>{{ job.displayNameKey|trans(job.displayNameParams) }} - {{ job.formattedTimestamp }}</strong>
|
||||
{% if job.isInProgress %}
|
||||
<span class="badge bg-info ms-2">Active</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ job.partCount }}</td>
|
||||
<td>{{ job.resultCount }}</td>
|
||||
<td>
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="progress me-2" style="width: 80px; height: 12px;">
|
||||
<div class="progress-bar {% if job.isCompleted %}bg-success{% elseif job.isFailed %}bg-danger{% else %}bg-info{% endif %}"
|
||||
role="progressbar"
|
||||
style="width: {{ job.progressPercentage }}%"
|
||||
aria-valuenow="{{ job.progressPercentage }}"
|
||||
aria-valuemin="0" aria-valuemax="100">
|
||||
</div>
|
||||
</div>
|
||||
<small class="text-muted">{{ job.progressPercentage }}%</small>
|
||||
</div>
|
||||
<small class="text-muted">
|
||||
{% trans with {'%current%': job.completedPartsCount + job.skippedPartsCount, '%total%': job.partCount} %}info_providers.bulk_import.progress_label{% endtrans %}
|
||||
</small>
|
||||
</td>
|
||||
<td>
|
||||
{% if job.isPending %}
|
||||
<span class="badge bg-warning">{% trans %}info_providers.bulk_import.status.pending{% endtrans %}</span>
|
||||
{% elseif job.isInProgress %}
|
||||
<span class="badge bg-info">{% trans %}info_providers.bulk_import.status.in_progress{% endtrans %}</span>
|
||||
{% elseif job.isCompleted %}
|
||||
<span class="badge bg-success">{% trans %}info_providers.bulk_import.status.completed{% endtrans %}</span>
|
||||
{% elseif job.isStopped %}
|
||||
<span class="badge bg-secondary">{% trans %}info_providers.bulk_import.status.stopped{% endtrans %}</span>
|
||||
{% elseif job.isFailed %}
|
||||
<span class="badge bg-danger">{% trans %}info_providers.bulk_import.status.failed{% endtrans %}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ job.createdBy.fullName(true) }}</td>
|
||||
<td>{{ job.createdAt|format_datetime('short') }}</td>
|
||||
<td>
|
||||
{% if job.completedAt %}
|
||||
{{ job.completedAt|format_datetime('short') }}
|
||||
{% else %}
|
||||
<span class="text-muted">-</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group btn-group-sm" role="group">
|
||||
{% if job.isInProgress or job.isCompleted or job.isStopped %}
|
||||
<a href="{{ path('bulk_info_provider_step2', {'jobId': job.id}) }}" class="btn btn-primary">
|
||||
<i class="fas fa-eye"></i> {% trans %}info_providers.bulk_import.view_results{% endtrans %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if job.canBeStopped %}
|
||||
<button type="button" class="btn btn-warning" data-action="click->bulk-job-manage#stopJob" data-job-id="{{ job.id }}">
|
||||
<i class="fas fa-stop"></i> {% trans %}info_providers.bulk_import.action.stop{% endtrans %}
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if job.isCompleted or job.isFailed or job.isStopped %}
|
||||
<button type="button" class="btn btn-danger" data-action="click->bulk-job-manage#deleteJob" data-job-id="{{ job.id }}">
|
||||
<i class="fas fa-trash"></i> {% trans %}info_providers.bulk_import.action.delete{% endtrans %}
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
{% if active_jobs is empty and finished_jobs is empty %}
|
||||
<div class="alert alert-info" role="alert">
|
||||
<i class="fas fa-info-circle"></i>
|
||||
{% trans %}info_providers.bulk_import.no_jobs_found{% endtrans %}<br>
|
||||
{% trans %}info_providers.bulk_import.create_first_job{% endtrans %}
|
||||
</div>
|
||||
{% else %}
|
||||
{# Active Jobs #}
|
||||
{% if active_jobs is not empty %}
|
||||
<h5 class="mb-3">
|
||||
<i class="fas fa-tasks me-1"></i> {% trans %}info_providers.bulk_import.active_jobs{% endtrans %}
|
||||
<span class="badge bg-primary">{{ active_jobs|length }}</span>
|
||||
</h5>
|
||||
{{ _self.job_table(active_jobs, false) }}
|
||||
{% endif %}
|
||||
|
||||
{# Finished Jobs (History) #}
|
||||
{% if finished_jobs is not empty %}
|
||||
<h5 class="mb-3">
|
||||
<i class="fas fa-history me-1"></i> {% trans %}info_providers.bulk_import.finished_jobs{% endtrans %}
|
||||
<span class="badge bg-secondary">{{ finished_jobs|length }}</span>
|
||||
</h5>
|
||||
{{ _self.job_table(finished_jobs, true) }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% macro job_table(jobs, showCompletedAt) %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans %}info_providers.bulk_import.job_name{% endtrans %}</th>
|
||||
<th>{% trans %}info_providers.bulk_import.parts_count{% endtrans %}</th>
|
||||
<th>{% trans %}info_providers.bulk_import.results_count{% endtrans %}</th>
|
||||
<th>{% trans %}info_providers.bulk_import.progress{% endtrans %}</th>
|
||||
<th>{% trans %}info_providers.bulk_import.status{% endtrans %}</th>
|
||||
<th>{% trans %}info_providers.bulk_import.created_by{% endtrans %}</th>
|
||||
<th>{% trans %}info_providers.bulk_import.created_at{% endtrans %}</th>
|
||||
{% if showCompletedAt %}
|
||||
<th>{% trans %}info_providers.bulk_import.completed_at{% endtrans %}</th>
|
||||
{% endif %}
|
||||
<th>{% trans %}info_providers.bulk_import.action.label{% endtrans %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for job in jobs %}
|
||||
{{ _self.job_row(job, showCompletedAt) }}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro job_row(job, showCompletedAt) %}
|
||||
{% set showCompletedAt = showCompletedAt|default(false) %}
|
||||
<tr>
|
||||
<td>
|
||||
<strong>#{{ job.id }} - {{ job.displayNameKey|trans(job.displayNameParams) }}</strong>
|
||||
<br><small class="text-muted">{{ job.formattedTimestamp }}</small>
|
||||
</td>
|
||||
<td>{{ job.partCount }}</td>
|
||||
<td>{{ job.resultCount }}</td>
|
||||
<td>
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="progress me-2" style="width: 80px; height: 12px;">
|
||||
<div class="progress-bar {% if job.isCompleted %}bg-success{% elseif job.isFailed %}bg-danger{% else %}bg-info{% endif %}"
|
||||
role="progressbar"
|
||||
style="width: {{ job.progressPercentage }}%"
|
||||
aria-valuenow="{{ job.progressPercentage }}"
|
||||
aria-valuemin="0" aria-valuemax="100">
|
||||
</div>
|
||||
</div>
|
||||
<small class="text-muted">{{ job.progressPercentage }}%</small>
|
||||
</div>
|
||||
<small class="text-muted">
|
||||
{% trans with {'%current%': job.completedPartsCount + job.skippedPartsCount, '%total%': job.partCount} %}info_providers.bulk_import.progress_label{% endtrans %}
|
||||
</small>
|
||||
</td>
|
||||
<td>
|
||||
{% if job.isPending %}
|
||||
<span class="badge bg-warning">{% trans %}info_providers.bulk_import.status.pending{% endtrans %}</span>
|
||||
{% elseif job.isInProgress %}
|
||||
<span class="badge bg-info">{% trans %}info_providers.bulk_import.status.in_progress{% endtrans %}</span>
|
||||
{% elseif job.isCompleted %}
|
||||
<span class="badge bg-success">{% trans %}info_providers.bulk_import.status.completed{% endtrans %}</span>
|
||||
{% elseif job.isStopped %}
|
||||
<span class="badge bg-secondary">{% trans %}info_providers.bulk_import.status.stopped{% endtrans %}</span>
|
||||
{% elseif job.isFailed %}
|
||||
<span class="badge bg-danger">{% trans %}info_providers.bulk_import.status.failed{% endtrans %}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ job.createdBy.fullName(true) }}</td>
|
||||
<td>{{ job.createdAt|format_datetime('short') }}</td>
|
||||
{% if showCompletedAt %}
|
||||
<td>
|
||||
{% if job.completedAt %}
|
||||
{{ job.completedAt|format_datetime('short') }}
|
||||
{% else %}
|
||||
<span class="text-muted">-</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
<td>
|
||||
<div class="btn-group btn-group-sm" role="group">
|
||||
{% if job.isInProgress or job.isCompleted or job.isStopped %}
|
||||
<a href="{{ path('bulk_info_provider_step2', {'jobId': job.id}) }}" class="btn btn-primary">
|
||||
<i class="fas fa-eye"></i> {% trans %}info_providers.bulk_import.view_results{% endtrans %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if job.canBeStopped %}
|
||||
<button type="button" class="btn btn-warning" data-action="click->bulk-job-manage#stopJob" data-job-id="{{ job.id }}">
|
||||
<i class="fas fa-stop"></i> {% trans %}info_providers.bulk_import.action.stop{% endtrans %}
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if job.isCompleted or job.isFailed or job.isStopped %}
|
||||
<button type="button" class="btn btn-danger" data-action="click->bulk-job-manage#deleteJob" data-job-id="{{ job.id }}">
|
||||
<i class="fas fa-trash"></i> {% trans %}info_providers.bulk_import.action.delete{% endtrans %}
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endmacro %}
|
||||
|
|
|
|||
|
|
@ -9,22 +9,42 @@
|
|||
|
||||
{% block card_title %}
|
||||
<i class="fas fa-search"></i> {% trans %}info_providers.bulk_import.step2.title{% endtrans %}
|
||||
<span class="badge bg-secondary">{{ job.displayNameKey|trans(job.displayNameParams) }} - {{ job.formattedTimestamp }}</span>
|
||||
<span class="badge bg-secondary">#{{ job.id }} - {{ job.displayNameKey|trans(job.displayNameParams) }}</span>
|
||||
{% endblock %}
|
||||
|
||||
{% block card_content %}
|
||||
|
||||
<!-- Navigation -->
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<a href="{{ path('bulk_info_provider_manage') }}" class="btn btn-outline-secondary btn-sm">
|
||||
<i class="fas fa-arrow-left"></i> {% trans %}info_providers.bulk_import.back_to_jobs{% endtrans %}
|
||||
</a>
|
||||
<a href="{{ path('parts_show_all') }}" class="btn btn-outline-primary btn-sm">
|
||||
<i class="fas fa-list"></i> {% trans %}info_providers.bulk_import.back_to_parts{% endtrans %}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% if job.isCompleted %}
|
||||
<div class="alert alert-success mb-3" role="alert">
|
||||
<i class="fas fa-check-circle"></i>
|
||||
<strong>{% trans %}info_providers.bulk_import.job_completed{% endtrans %}</strong>
|
||||
{% trans %}info_providers.bulk_import.job_completed.description{% endtrans %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div {{ stimulus_controller('bulk-import', {
|
||||
'jobId': job.id,
|
||||
'researchUrl': path('bulk_info_provider_research_part', {'jobId': job.id, 'partId': '__PART_ID__'}),
|
||||
'researchAllUrl': path('bulk_info_provider_research_all', {'jobId': job.id}),
|
||||
'markCompletedUrl': path('bulk_info_provider_mark_completed', {'jobId': job.id, 'partId': '__PART_ID__'}),
|
||||
'markSkippedUrl': path('bulk_info_provider_mark_skipped', {'jobId': job.id, 'partId': '__PART_ID__'}),
|
||||
'markPendingUrl': path('bulk_info_provider_mark_pending', {'jobId': job.id, 'partId': '__PART_ID__'})
|
||||
'markPendingUrl': path('bulk_info_provider_mark_pending', {'jobId': job.id, 'partId': '__PART_ID__'}),
|
||||
'quickApplyUrl': path('bulk_info_provider_quick_apply', {'jobId': job.id, 'partId': '__PART_ID__'}),
|
||||
'quickApplyAllUrl': path('bulk_info_provider_quick_apply_all', {'jobId': job.id})
|
||||
}) }}>
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<div>
|
||||
<h5 class="mb-1">{{ job.displayNameKey|trans(job.displayNameParams) }} - {{ job.formattedTimestamp }}</h5>
|
||||
<h5 class="mb-1">#{{ job.id }} - {{ job.displayNameKey|trans(job.displayNameParams) }}</h5>
|
||||
<small class="text-muted">
|
||||
{{ job.partCount }} {% trans %}info_providers.bulk_import.parts{% endtrans %} •
|
||||
{{ job.resultCount }} {% trans %}info_providers.bulk_import.results{% endtrans %} •
|
||||
|
|
@ -95,6 +115,13 @@
|
|||
<span class="spinner-border spinner-border-sm me-1" style="display: none;" id="research-all-spinner"></span>
|
||||
<i class="fas fa-search"></i> {% trans %}info_providers.bulk_import.research.all_pending{% endtrans %}
|
||||
</button>
|
||||
<button type="button" class="btn btn-success btn-sm"
|
||||
data-action="click->bulk-import#quickApplyAll"
|
||||
id="quick-apply-all-btn"
|
||||
title="{% trans %}info_providers.bulk_import.quick_apply_all.tooltip{% endtrans %}">
|
||||
<span class="spinner-border spinner-border-sm me-1" style="display: none;" id="quick-apply-all-spinner"></span>
|
||||
<i class="fas fa-bolt"></i> {% trans %}info_providers.bulk_import.quick_apply_all{% endtrans %}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -181,39 +208,74 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for result in part_result.searchResults %}
|
||||
{% set sortedResults = part_result.resultsSortedByPriority %}
|
||||
{% for result in sortedResults %}
|
||||
{# @var result \App\Services\InfoProviderSystem\DTOs\BulkSearchPartResultDTO #}
|
||||
{% set dto = result.searchResult %}
|
||||
{% set localPart = result.localPart %}
|
||||
<tr>
|
||||
{% set isTopResult = loop.first %}
|
||||
<tr{% if isTopResult and not isCompleted %} class="table-success"{% endif %}>
|
||||
<td>
|
||||
<img src="{{ dto.preview_image_url }}" data-thumbnail="{{ dto.preview_image_url }}"
|
||||
class="hoverpic" style="max-width: 35px;" {{ stimulus_controller('elements/hoverpic') }}>
|
||||
{% if dto.preview_image_url %}
|
||||
<img src="{{ dto.preview_image_url }}" data-thumbnail="{{ dto.preview_image_url }}"
|
||||
class="hoverpic" style="max-width: 35px;" {{ stimulus_controller('elements/hoverpic') }}
|
||||
onerror="this.style.display='none'">
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{# Check for matches against source keyword (what was searched) #}
|
||||
{% set sourceKw = result.sourceKeyword|default('')|lower %}
|
||||
{% set nameMatch = sourceKw is not empty and dto.name is not null and dto.name|lower == sourceKw %}
|
||||
{% set mpnMatch = sourceKw is not empty and dto.mpn is not null and dto.mpn|lower == sourceKw %}
|
||||
{% set spnMatch = sourceKw is not empty and dto.provider_id is not null and dto.provider_id|lower == sourceKw %}
|
||||
{% set anyMatch = nameMatch or mpnMatch or spnMatch %}
|
||||
{% if dto.provider_url is not null %}
|
||||
<a href="{{ dto.provider_url }}" target="_blank" rel="noopener">{{ dto.name }}</a>
|
||||
<a href="{{ dto.provider_url }}" target="_blank" rel="noopener"{% if nameMatch %} class="fw-bold"{% endif %}>{{ dto.name }}</a>
|
||||
{% else %}
|
||||
{{ dto.name }}
|
||||
<span{% if nameMatch %} class="fw-bold"{% endif %}>{{ dto.name }}</span>
|
||||
{% endif %}
|
||||
{% if nameMatch %}
|
||||
<span class="badge bg-success ms-1" title="{% trans %}info_providers.bulk_import.exact_match{% endtrans %}"><i class="fas fa-check-circle"></i></span>
|
||||
{% endif %}
|
||||
{% if dto.mpn is not null %}
|
||||
<br><small class="text-muted">{{ dto.mpn }}</small>
|
||||
<br><small{% if mpnMatch %} class="fw-bold text-success"{% endif %}>{{ dto.mpn }}</small>
|
||||
{% if mpnMatch %}
|
||||
<span class="badge bg-success ms-1" style="font-size: 0.65em;" title="{% trans %}info_providers.bulk_import.mpn_match{% endtrans %}">MPN <i class="fas fa-check-circle"></i></span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ dto.description }}</td>
|
||||
<td>{{ dto.manufacturer ?? '' }}</td>
|
||||
<td>
|
||||
{{ info_provider_label(dto.provider_key)|default(dto.provider_key) }}
|
||||
<br><small class="text-muted">{{ dto.provider_id }}</small>
|
||||
<br><small{% if spnMatch %} class="fw-bold text-success"{% endif %}>{{ dto.provider_id }}</small>
|
||||
{% if spnMatch %}
|
||||
<span class="badge bg-success ms-1" style="font-size: 0.65em;" title="{% trans %}info_providers.bulk_import.spn_match{% endtrans %}">SPN <i class="fas fa-check-circle"></i></span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge bg-info">{{ result.sourceField ?? 'unknown' }}</span>
|
||||
{% if anyMatch %}
|
||||
<span class="badge bg-success">{% trans %}info_providers.bulk_import.match{% endtrans %}</span>
|
||||
{% else %}
|
||||
<span class="badge bg-info">{{ result.sourceField ?? 'unknown' }}</span>
|
||||
{% endif %}
|
||||
{% if result.sourceKeyword %}
|
||||
<br><small class="text-muted">{{ result.sourceKeyword }}</small>
|
||||
{% endif %}
|
||||
<br><small{% if anyMatch %} class="fw-bold text-success"{% endif %}>{{ result.sourceKeyword }}</small>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group-vertical btn-group-sm" role="group">
|
||||
{% if not isCompleted %}
|
||||
<button type="button" class="btn {% if not isTopResult %} btn-outline-success{% else %}btn-success{% endif %}"
|
||||
data-action="click->bulk-import#quickApply"
|
||||
data-part-id="{{ part.id }}"
|
||||
data-provider-key="{{ dto.provider_key }}"
|
||||
data-provider-id="{{ dto.provider_id }}"
|
||||
title="{% trans %}info_providers.bulk_import.quick_apply.tooltip{% endtrans %}">
|
||||
<i class="fas fa-bolt"></i> {% trans %}info_providers.bulk_import.quick_apply{% endtrans %}
|
||||
{% if isTopResult %}<span class="badge bg-light text-success ms-1">{% trans %}info_providers.bulk_import.recommended{% endtrans %}</span>{% endif %}
|
||||
</button>
|
||||
{% endif %}
|
||||
{% set updateHref = path('info_providers_update_part',
|
||||
{'id': part.id, 'providerKey': dto.provider_key, 'providerId': dto.provider_id}) ~ '?jobId=' ~ job.id %}
|
||||
<a class="btn btn-primary{% if isCompleted %} disabled{% endif %}" href="{% if not isCompleted %}{{ updateHref }}{% else %}#{% endif %}"{% if isCompleted %} aria-disabled="true"{% endif %}>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,22 @@
|
|||
|
||||
{{ form_start(form) }}
|
||||
{{ form_row(form.url) }}
|
||||
|
||||
{{ form_row(form.method) }}
|
||||
|
||||
<div class="row mb-2">
|
||||
<div class="{{ col_input }} {{ offset_label }}">
|
||||
<a data-bs-toggle="collapse" href="#infoSearchAdvancedPanel">{% trans %}info_providers.search.advanced_options{% endtrans %}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="collapse" id="infoSearchAdvancedPanel">
|
||||
<div class="card card-body mb-2">
|
||||
{{ form_row(form.no_cache) }}
|
||||
{{ form_row(form.skip_delegation) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ form_row(form.submit) }}
|
||||
{{ form_end(form) }}
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,19 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-2">
|
||||
<div class="{{ col_input }} {{ offset_label }}">
|
||||
<a data-bs-toggle="collapse" href="#infoSearchAdvancedPanel">{% trans %}info_providers.search.advanced_options{% endtrans %}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="collapse" id="infoSearchAdvancedPanel">
|
||||
<div class="card card-body mb-2">
|
||||
{{ form_row(form.no_cache_search) }}
|
||||
{{ form_row(form.no_cache_details) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ form_row(form.submit) }}
|
||||
|
||||
{{ form_end(form) }}
|
||||
|
|
@ -116,16 +129,16 @@
|
|||
|
||||
{% if update_target %} {# We update an existing part #}
|
||||
{% set href = path('info_providers_update_part',
|
||||
{'providerKey': dto.provider_key, 'providerId': dto.provider_id, 'id': update_target.iD}) %}
|
||||
{'providerKey': dto.provider_key, 'providerId': dto.provider_id, 'id': update_target.iD, 'no_cache': no_cache_details ? 1 : null}) %}
|
||||
{% else %} {# Create a fresh part #}
|
||||
{% set href = path('info_providers_create_part',
|
||||
{'providerKey': dto.provider_key, 'providerId': dto.provider_id}) %}
|
||||
{'providerKey': dto.provider_key, 'providerId': dto.provider_id, 'no_cache': no_cache_details ? 1 : null}) %}
|
||||
{% endif %}
|
||||
|
||||
{# If we have no local part, then we can just show the create button #}
|
||||
{% if localPart is null %}
|
||||
<a class="btn btn-primary" href="{{ href }}"
|
||||
target="_blank" title="{% trans %}part.create.btn{% endtrans %}">
|
||||
target="_blank" title="{% trans %}part.create.btn{% endtrans %}">
|
||||
<i class="fa-solid fa-plus-square"></i>
|
||||
</a>
|
||||
{% else %} {# Otherwise add a button group with all three buttons #}
|
||||
|
|
@ -139,7 +152,7 @@
|
|||
target="_blank" title="{% trans %}info_providers.search.show_existing_part{% endtrans %}">
|
||||
<i class="fa-solid fa-search"></i>
|
||||
</a>
|
||||
<a class="btn btn-primary" href="{{ path("info_providers_update_part", {'id': localPart.id, 'providerKey': dto.provider_key, 'providerId': dto.provider_id}) }}"
|
||||
<a class="btn btn-primary" href="{{ path("info_providers_update_part", {'id': localPart.id, 'providerKey': dto.provider_key, 'providerId': dto.provider_id, 'no_cache': no_cache_details ? 1 : null }) }}"
|
||||
target="_blank" title="{% trans %}info_providers.search.update_existing_part{% endtrans %}">
|
||||
<i class="fa-solid fa-arrows-rotate"></i>
|
||||
</a>
|
||||
|
|
|
|||
46
templates/parts/info/_add_lot_modal.html.twig
Normal file
46
templates/parts/info/_add_lot_modal.html.twig
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
{% if add_lot_form is not null %}
|
||||
{% form_theme add_lot_form 'form/extended_bootstrap_layout.html.twig' %}
|
||||
|
||||
<div class="modal fade" id="add-lot-modal" tabindex="-1" aria-labelledby="add-lot-modal-title" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
{{ form_start(add_lot_form) }}
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="add-lot-modal-title">
|
||||
<i class="fas fa-plus-square fa-fw"></i>
|
||||
{% trans %}part_lot.create{% endtrans %}
|
||||
</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
{{ form_row(add_lot_form.description) }}
|
||||
{{ form_row(add_lot_form.storage_location) }}
|
||||
{{ form_row(add_lot_form.amount) }}
|
||||
{{ form_row(add_lot_form.instock_unknown) }}
|
||||
{{ form_row(add_lot_form.needs_refill) }}
|
||||
{{ form_row(add_lot_form.expiration_date) }}
|
||||
|
||||
<div>
|
||||
<a class="btn btn-link btn-sm {{ offset_label }}" data-bs-toggle="collapse" href="#add-lot-advanced" role="button" aria-expanded="false" aria-controls="add-lot-advanced">
|
||||
{% trans %}part_lot.edit.advanced{% endtrans %}
|
||||
</a>
|
||||
<div class="collapse" id="add-lot-advanced">
|
||||
{{ form_row(add_lot_form.comment) }}
|
||||
{{ form_row(add_lot_form.owner) }}
|
||||
{{ form_row(add_lot_form.user_barcode) }}
|
||||
{{ form_row(add_lot_form.last_stocktake_at) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans %}modal.close{% endtrans %}</button>
|
||||
<button type="submit" class="btn btn-success">
|
||||
<i class="fas fa-plus-square fa-fw"></i>
|
||||
{% trans %}part_lot.create{% endtrans %}
|
||||
</button>
|
||||
</div>
|
||||
{{ form_end(add_lot_form) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
{% include "parts/info/_withdraw_modal.html.twig" %}
|
||||
{% include "parts/info/_stocktake_modal.html.twig" %}
|
||||
{% include "parts/info/_add_lot_modal.html.twig" %}
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
|
|
@ -126,3 +127,10 @@
|
|||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% if add_lot_form is not null %}
|
||||
<button type="button" class="btn btn-outline-success" data-bs-toggle="modal" data-bs-target="#add-lot-modal">
|
||||
<i class="fas fa-plus-square fa-fw"></i>
|
||||
{% trans %}part_lot.create{% endtrans %}
|
||||
</button>
|
||||
{% endif %}
|
||||
|
|
|
|||
222
tests/Controller/AuthorizationTest.php
Normal file
222
tests/Controller/AuthorizationTest.php
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\UserSystem\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Verifies the HTTP access-control boundaries:
|
||||
*
|
||||
* The app has an "anonymous" fixture user with readonly permissions, so truly
|
||||
* public read routes return 200 even without a session. Write-protected routes
|
||||
* return 401 for unauthenticated requests (not a 302 redirect).
|
||||
*
|
||||
* Users: admin (all-allow), user (editor preset), noread (no group/no perms)
|
||||
*/
|
||||
#[Group('DB')]
|
||||
#[Group('slow')]
|
||||
final class AuthorizationTest extends WebTestCase
|
||||
{
|
||||
// -----------------------------------------------------------------------
|
||||
// Data providers
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Routes readable by the anonymous user — unauthenticated requests get 200.
|
||||
*/
|
||||
public static function publicReadRoutesProvider(): \Generator
|
||||
{
|
||||
yield 'homepage' => ['/en/'];
|
||||
yield 'part view' => ['/en/part/1'];
|
||||
yield 'statistics' => ['/en/statistics'];
|
||||
yield 'select category' => ['/en/select_api/category'];
|
||||
yield 'typeahead tags' => ['/en/typeahead/tags/search/test'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Write-protected routes — unauthenticated gets 401 (not 302).
|
||||
*/
|
||||
public static function writeProtectedRoutesProvider(): \Generator
|
||||
{
|
||||
yield 'part edit' => ['/en/part/1/edit'];
|
||||
yield 'part new' => ['/en/part/new'];
|
||||
yield 'user edit' => ['/en/user/1/edit'];
|
||||
yield 'log list' => ['/en/log/'];
|
||||
yield 'server info' => ['/en/tools/server_infos'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Routes the `noread` user (no group = no permissions) must be denied.
|
||||
*/
|
||||
public static function noreadDeniedRoutesProvider(): \Generator
|
||||
{
|
||||
yield 'part view' => ['/en/part/1'];
|
||||
yield 'part edit' => ['/en/part/1/edit'];
|
||||
yield 'part new' => ['/en/part/new'];
|
||||
yield 'log list' => ['/en/log/'];
|
||||
yield 'server info' => ['/en/tools/server_infos'];
|
||||
yield 'select category' => ['/en/select_api/category'];
|
||||
yield 'typeahead tags' => ['/en/typeahead/tags/search/test'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Routes the `user` (editor preset) must have access to.
|
||||
*/
|
||||
public static function editorAllowedRoutesProvider(): \Generator
|
||||
{
|
||||
yield 'homepage' => ['/en/'];
|
||||
yield 'part view' => ['/en/part/1'];
|
||||
yield 'part edit' => ['/en/part/1/edit'];
|
||||
yield 'part new' => ['/en/part/new'];
|
||||
yield 'select cat' => ['/en/select_api/category'];
|
||||
yield 'typeahead' => ['/en/typeahead/tags/search/test'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin-only routes the `user` (editor) must be denied.
|
||||
*/
|
||||
public static function editorDeniedRoutesProvider(): \Generator
|
||||
{
|
||||
yield 'user edit' => ['/en/user/1/edit'];
|
||||
yield 'log list' => ['/en/log/'];
|
||||
yield 'server info' => ['/en/tools/server_infos'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Routes the `admin` user must be able to reach.
|
||||
*/
|
||||
public static function adminAllowedRoutesProvider(): \Generator
|
||||
{
|
||||
yield 'user edit' => ['/en/user/1/edit'];
|
||||
yield 'log list' => ['/en/log/'];
|
||||
yield 'server info' => ['/en/tools/server_infos'];
|
||||
yield 'part view' => ['/en/part/1'];
|
||||
yield 'part edit' => ['/en/part/1/edit'];
|
||||
yield 'statistics' => ['/en/statistics'];
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Helpers
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
private function loginAs(string $username): KernelBrowser
|
||||
{
|
||||
$client = static::createClient();
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
$user = $em->getRepository(User::class)->findOneBy(['name' => $username]);
|
||||
if ($user === null) {
|
||||
$this->markTestSkipped("Fixture user '$username' not found.");
|
||||
}
|
||||
$client->loginUser($user);
|
||||
$client->followRedirects(false);
|
||||
return $client;
|
||||
}
|
||||
|
||||
private function assertDenied(KernelBrowser $client, string $url): void
|
||||
{
|
||||
$client->request('GET', $url);
|
||||
$code = $client->getResponse()->getStatusCode();
|
||||
$this->assertTrue(
|
||||
$code === Response::HTTP_FORBIDDEN || $code === Response::HTTP_UNAUTHORIZED || $client->getResponse()->isRedirect(),
|
||||
"Expected 401/403/redirect on $url, got $code"
|
||||
);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unauthenticated: public reads
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
#[DataProvider('publicReadRoutesProvider')]
|
||||
public function testUnauthenticatedCanReadPublicRoutes(string $url): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$client->request('GET', $url);
|
||||
// Anonymous user (readonly group) can access read-only content
|
||||
$this->assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unauthenticated: write routes → 401
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
#[DataProvider('writeProtectedRoutesProvider')]
|
||||
public function testUnauthenticatedIsUnauthorizedOnWriteRoutes(string $url): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$client->followRedirects(false);
|
||||
$client->request('GET', $url);
|
||||
|
||||
$code = $client->getResponse()->getStatusCode();
|
||||
$this->assertTrue(
|
||||
$code === Response::HTTP_UNAUTHORIZED || $client->getResponse()->isRedirect(),
|
||||
"Expected 401 or redirect on $url for unauthenticated request, got $code"
|
||||
);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// noread user: denied everywhere
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
#[DataProvider('noreadDeniedRoutesProvider')]
|
||||
public function testNoreadUserIsDenied(string $url): void
|
||||
{
|
||||
$this->assertDenied($this->loginAs('noread'), $url);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Editor user
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
#[DataProvider('editorAllowedRoutesProvider')]
|
||||
public function testEditorCanAccess(string $url): void
|
||||
{
|
||||
$client = $this->loginAs('user');
|
||||
$client->request('GET', $url);
|
||||
$this->assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
#[DataProvider('editorDeniedRoutesProvider')]
|
||||
public function testEditorIsDeniedOnAdminRoutes(string $url): void
|
||||
{
|
||||
$this->assertDenied($this->loginAs('user'), $url);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Admin user: can access everything
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
#[DataProvider('adminAllowedRoutesProvider')]
|
||||
public function testAdminCanAccessAllRoutes(string $url): void
|
||||
{
|
||||
$client = $this->loginAs('admin');
|
||||
$client->request('GET', $url);
|
||||
$this->assertResponseIsSuccessful();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
152
tests/Controller/SelectApiControllerTest.php
Normal file
152
tests/Controller/SelectApiControllerTest.php
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\UserSystem\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* Tests the SelectAPIController endpoints used by select2 widgets.
|
||||
* These JSON endpoints back every structural-entity dropdown in the UI.
|
||||
*/
|
||||
#[Group('DB')]
|
||||
#[Group('slow')]
|
||||
final class SelectApiControllerTest extends WebTestCase
|
||||
{
|
||||
public static function endpointProvider(): \Generator
|
||||
{
|
||||
yield 'category' => ['/en/select_api/category'];
|
||||
yield 'footprint' => ['/en/select_api/footprint'];
|
||||
yield 'manufacturer' => ['/en/select_api/manufacturer'];
|
||||
yield 'measurement_unit' => ['/en/select_api/measurement_unit'];
|
||||
yield 'project' => ['/en/select_api/project'];
|
||||
yield 'storage_location' => ['/en/select_api/storage_location'];
|
||||
yield 'label_profiles' => ['/en/select_api/label_profiles'];
|
||||
}
|
||||
|
||||
private function adminClient(): KernelBrowser
|
||||
{
|
||||
$client = static::createClient();
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
$admin = $em->getRepository(User::class)->findOneBy(['name' => 'admin']);
|
||||
if ($admin === null) {
|
||||
$this->markTestSkipped('Fixture user admin not found.');
|
||||
}
|
||||
$client->loginUser($admin);
|
||||
return $client;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Response format
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
#[DataProvider('endpointProvider')]
|
||||
public function testEndpointReturns200WithJsonContentType(string $url): void
|
||||
{
|
||||
$client = $this->adminClient();
|
||||
$client->request('GET', $url);
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertResponseHeaderSame('content-type', 'application/json');
|
||||
}
|
||||
|
||||
#[DataProvider('endpointProvider')]
|
||||
public function testEndpointReturnsValidJsonArray(string $url): void
|
||||
{
|
||||
$client = $this->adminClient();
|
||||
$client->request('GET', $url);
|
||||
|
||||
$body = $client->getResponse()->getContent();
|
||||
$decoded = json_decode($body, true);
|
||||
|
||||
$this->assertIsArray($decoded, "Response from $url is not a valid JSON array");
|
||||
}
|
||||
|
||||
#[DataProvider('endpointProvider')]
|
||||
public function testEachEntryHasTextAndValueKeys(string $url): void
|
||||
{
|
||||
$client = $this->adminClient();
|
||||
$client->request('GET', $url);
|
||||
|
||||
$decoded = json_decode($client->getResponse()->getContent(), true);
|
||||
// Some endpoints include an empty "select none" entry at index 0; all entries must have text + value
|
||||
foreach ($decoded as $entry) {
|
||||
$this->assertArrayHasKey('text', $entry, "Entry in $url missing 'text' key");
|
||||
$this->assertArrayHasKey('value', $entry, "Entry in $url missing 'value' key");
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Access control
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
#[DataProvider('endpointProvider')]
|
||||
public function testUnauthenticatedCanReadSelectApi(string $url): void
|
||||
{
|
||||
// The anonymous user (readonly group) has read access to structural entities,
|
||||
// so these endpoints return 200 even without a session.
|
||||
$client = static::createClient();
|
||||
$client->request('GET', $url);
|
||||
$this->assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
#[DataProvider('endpointProvider')]
|
||||
public function testNoreadUserIsDenied(string $url): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
$noread = $em->getRepository(User::class)->findOneBy(['name' => 'noread']);
|
||||
if ($noread === null) {
|
||||
$this->markTestSkipped('Fixture user noread not found.');
|
||||
}
|
||||
$client->loginUser($noread);
|
||||
$client->followRedirects(false);
|
||||
$client->request('GET', $url);
|
||||
|
||||
$response = $client->getResponse();
|
||||
$this->assertTrue(
|
||||
$response->getStatusCode() === 403 || $response->isRedirect(),
|
||||
"Expected 403 or redirect for noread user on $url, got " . $response->getStatusCode()
|
||||
);
|
||||
}
|
||||
|
||||
#[DataProvider('endpointProvider')]
|
||||
public function testEditorUserCanAccess(string $url): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
$user = $em->getRepository(User::class)->findOneBy(['name' => 'user']);
|
||||
if ($user === null) {
|
||||
$this->markTestSkipped('Fixture user user not found.');
|
||||
}
|
||||
$client->loginUser($user);
|
||||
$client->request('GET', $url);
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue