Fix arr storage
This commit is contained in:
@@ -98,7 +98,7 @@ func NewStorage(cfg []common.ArrConfig) *Storage {
|
|||||||
func (as *Storage) AddOrUpdate(arr *Arr) {
|
func (as *Storage) AddOrUpdate(arr *Arr) {
|
||||||
as.mu.Lock()
|
as.mu.Lock()
|
||||||
defer as.mu.Unlock()
|
defer as.mu.Unlock()
|
||||||
as.Arrs[arr.Host] = arr
|
as.Arrs[arr.Name] = arr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (as *Storage) Get(name string) *Arr {
|
func (as *Storage) Get(name string) *Arr {
|
||||||
|
|||||||
@@ -60,6 +60,13 @@
|
|||||||
submitBtn.disabled = true;
|
submitBtn.disabled = true;
|
||||||
submitBtn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Repairing...';
|
submitBtn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Repairing...';
|
||||||
let mediaIds = document.getElementById('mediaIds').value.split(',').map(id => id.trim());
|
let mediaIds = document.getElementById('mediaIds').value.split(',').map(id => id.trim());
|
||||||
|
let arr = document.getElementById('arrSelect').value;
|
||||||
|
if (!arr) {
|
||||||
|
alert('Please select an Arr instance');
|
||||||
|
submitBtn.disabled = false;
|
||||||
|
submitBtn.innerHTML = originalText;
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/internal/repair', {
|
const response = await fetch('/internal/repair', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -74,8 +81,6 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) throw new Error(await response.text());
|
if (!response.ok) throw new Error(await response.text());
|
||||||
|
|
||||||
const result = await response.json();
|
|
||||||
alert('Repair process initiated successfully!');
|
alert('Repair process initiated successfully!');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(`Error starting repair: ${error.message}`);
|
alert(`Error starting repair: ${error.message}`);
|
||||||
|
|||||||
@@ -176,15 +176,8 @@ func (u *uiHandler) handleRepairMedia(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_arr := u.qbit.Arrs.Get(req.ArrName)
|
_arr := u.qbit.Arrs.Get(req.ArrName)
|
||||||
arrs := make([]*arr.Arr, 0)
|
if _arr == nil {
|
||||||
if _arr != nil {
|
http.Error(w, "No Arrs found to repair", http.StatusNotFound)
|
||||||
arrs = append(arrs, _arr)
|
|
||||||
} else {
|
|
||||||
arrs = u.qbit.Arrs.GetAll()
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(arrs) == 0 {
|
|
||||||
http.Error(w, "No arrays found to repair", http.StatusNotFound)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,26 +187,22 @@ func (u *uiHandler) handleRepairMedia(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if req.Async {
|
if req.Async {
|
||||||
for _, a := range arrs {
|
for _, tvId := range mediaIds {
|
||||||
for _, tvId := range mediaIds {
|
go func() {
|
||||||
go func() {
|
err := _arr.Repair(tvId)
|
||||||
err := a.Repair(tvId)
|
if err != nil {
|
||||||
if err != nil {
|
u.logger.Info().Msgf("Failed to repair: %v", err)
|
||||||
u.logger.Info().Msgf("Failed to repair: %v", err)
|
}
|
||||||
}
|
}()
|
||||||
}()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
common.JSONResponse(w, "Repair process started", http.StatusOK)
|
common.JSONResponse(w, "Repair process started", http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var errs []error
|
var errs []error
|
||||||
for _, a := range arrs {
|
for _, tvId := range mediaIds {
|
||||||
for _, tvId := range mediaIds {
|
if err := _arr.Repair(tvId); err != nil {
|
||||||
if err := a.Repair(tvId); err != nil {
|
errs = append(errs, err)
|
||||||
errs = append(errs, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user