Drop legacy OPDS and keep only the new implementation (#1236)
This commit is contained in:
+6
-15
@@ -2,10 +2,10 @@ package com.adityachandel.booklore.config.security.service;
|
|||||||
|
|
||||||
import com.adityachandel.booklore.config.security.userdetails.OpdsUserDetails;
|
import com.adityachandel.booklore.config.security.userdetails.OpdsUserDetails;
|
||||||
import com.adityachandel.booklore.exception.ApiError;
|
import com.adityachandel.booklore.exception.ApiError;
|
||||||
import com.adityachandel.booklore.mapper.OpdsUserMapper;
|
|
||||||
import com.adityachandel.booklore.mapper.OpdsUserV2Mapper;
|
import com.adityachandel.booklore.mapper.OpdsUserV2Mapper;
|
||||||
|
import com.adityachandel.booklore.model.dto.OpdsUserV2;
|
||||||
|
import com.adityachandel.booklore.model.entity.OpdsUserV2Entity;
|
||||||
import com.adityachandel.booklore.repository.OpdsUserV2Repository;
|
import com.adityachandel.booklore.repository.OpdsUserV2Repository;
|
||||||
import com.adityachandel.booklore.repository.OpdsUserRepository;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
@@ -16,23 +16,14 @@ import org.springframework.stereotype.Service;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class OpdsUserDetailsService implements UserDetailsService {
|
public class OpdsUserDetailsService implements UserDetailsService {
|
||||||
|
|
||||||
private final OpdsUserRepository opdsUserRepository;
|
|
||||||
private final OpdsUserV2Repository opdsUserV2Repository;
|
private final OpdsUserV2Repository opdsUserV2Repository;
|
||||||
private final OpdsUserMapper opdsUserMapper;
|
|
||||||
private final OpdsUserV2Mapper opdsUserV2Mapper;
|
private final OpdsUserV2Mapper opdsUserV2Mapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OpdsUserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
public OpdsUserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
return opdsUserRepository.findByUsername(username)
|
OpdsUserV2Entity userV2 = opdsUserV2Repository.findByUsername(username)
|
||||||
.map(user -> {
|
.orElseThrow(() -> ApiError.USER_NOT_FOUND.createException(username));
|
||||||
var mappedUser = opdsUserMapper.toOpdsUser(user);
|
OpdsUserV2 mappedCredential = opdsUserV2Mapper.toDto(userV2);
|
||||||
return new OpdsUserDetails(null, mappedUser);
|
return new OpdsUserDetails(mappedCredential, null);
|
||||||
})
|
|
||||||
.orElseGet(() -> {
|
|
||||||
var userV2 = opdsUserV2Repository.findByUsername(username)
|
|
||||||
.orElseThrow(() -> ApiError.USER_NOT_FOUND.createException(username));
|
|
||||||
var mappedCredential = opdsUserV2Mapper.toDto(userV2);
|
|
||||||
return new OpdsUserDetails(mappedCredential, null);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-48
@@ -1,48 +0,0 @@
|
|||||||
package com.adityachandel.booklore.controller;
|
|
||||||
|
|
||||||
import com.adityachandel.booklore.model.dto.OpdsUser;
|
|
||||||
import com.adityachandel.booklore.model.dto.request.OpdsUserCreateRequest;
|
|
||||||
import com.adityachandel.booklore.model.dto.request.PasswordResetRequest;
|
|
||||||
import com.adityachandel.booklore.service.opds.OpdsUserService;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/v1/opds-users")
|
|
||||||
public class OpdsUserController {
|
|
||||||
|
|
||||||
private final OpdsUserService opdsUserService;
|
|
||||||
|
|
||||||
@PreAuthorize("@securityUtil.isAdmin()")
|
|
||||||
@PostMapping
|
|
||||||
public ResponseEntity<Void> createOpdsUser(@RequestBody OpdsUserCreateRequest request) {
|
|
||||||
opdsUserService.createOpdsUser(request.getUsername(), request.getPassword());
|
|
||||||
return ResponseEntity.noContent().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreAuthorize("@securityUtil.isAdmin()")
|
|
||||||
@GetMapping
|
|
||||||
public ResponseEntity<List<OpdsUser>> listOpdsUsers() {
|
|
||||||
List<OpdsUser> users = opdsUserService.getOpdsUsers();
|
|
||||||
return ResponseEntity.ok(users);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreAuthorize("@securityUtil.isAdmin()")
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public ResponseEntity<Void> deleteOpdsUser(@PathVariable Long id) {
|
|
||||||
opdsUserService.deleteOpdsUser(id);
|
|
||||||
return ResponseEntity.noContent().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreAuthorize("@securityUtil.isAdmin()")
|
|
||||||
@PutMapping("/{userId}/reset-password")
|
|
||||||
public ResponseEntity<Void> resetPassword(@PathVariable("userId") Long userId, @RequestBody PasswordResetRequest resetRequest) {
|
|
||||||
opdsUserService.resetPassword(userId, resetRequest.getPassword());
|
|
||||||
return ResponseEntity.ok().build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package com.adityachandel.booklore.mapper;
|
|
||||||
|
|
||||||
import com.adityachandel.booklore.model.dto.OpdsUser;
|
|
||||||
import com.adityachandel.booklore.model.entity.OpdsUserEntity;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
|
|
||||||
@Mapper(componentModel = "spring")
|
|
||||||
public interface OpdsUserMapper {
|
|
||||||
|
|
||||||
OpdsUser toOpdsUser(OpdsUserEntity opdsUserEntity);
|
|
||||||
}
|
|
||||||
-25
@@ -1,25 +0,0 @@
|
|||||||
package com.adityachandel.booklore.model.entity;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Entity
|
|
||||||
@Table(name = "opds_user")
|
|
||||||
public class OpdsUserEntity {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Column(name = "username", nullable = false)
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
@Column(name = "password", nullable = false)
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
}
|
|
||||||
-12
@@ -1,12 +0,0 @@
|
|||||||
package com.adityachandel.booklore.repository;
|
|
||||||
|
|
||||||
import com.adityachandel.booklore.model.entity.OpdsUserEntity;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface OpdsUserRepository extends JpaRepository<OpdsUserEntity, Long> {
|
|
||||||
boolean existsByUsername(String username);
|
|
||||||
|
|
||||||
Optional<OpdsUserEntity> findByUsername(String username);
|
|
||||||
}
|
|
||||||
-52
@@ -1,52 +0,0 @@
|
|||||||
package com.adityachandel.booklore.service.opds;
|
|
||||||
|
|
||||||
import com.adityachandel.booklore.exception.ApiError;
|
|
||||||
import com.adityachandel.booklore.mapper.OpdsUserMapper;
|
|
||||||
import com.adityachandel.booklore.model.dto.OpdsUser;
|
|
||||||
import com.adityachandel.booklore.model.entity.OpdsUserEntity;
|
|
||||||
import com.adityachandel.booklore.repository.OpdsUserRepository;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class OpdsUserService {
|
|
||||||
|
|
||||||
private final OpdsUserRepository opdsUserRepository;
|
|
||||||
private final OpdsUserMapper opdsUserMapper;
|
|
||||||
private final PasswordEncoder passwordEncoder;
|
|
||||||
|
|
||||||
public void createOpdsUser(String username, String password) {
|
|
||||||
if (opdsUserRepository.existsByUsername(username)) {
|
|
||||||
throw ApiError.USERNAME_ALREADY_TAKEN.createException(username);
|
|
||||||
}
|
|
||||||
OpdsUserEntity opdsUser = new OpdsUserEntity();
|
|
||||||
opdsUser.setUsername(username);
|
|
||||||
opdsUser.setPassword(passwordEncoder.encode(password));
|
|
||||||
opdsUserRepository.save(opdsUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OpdsUser> getOpdsUsers() {
|
|
||||||
return opdsUserRepository.findAll()
|
|
||||||
.stream()
|
|
||||||
.map(opdsUserMapper::toOpdsUser)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteOpdsUser(Long id) {
|
|
||||||
if (!opdsUserRepository.existsById(id)) {
|
|
||||||
throw ApiError.USER_NOT_FOUND.createException(id);
|
|
||||||
}
|
|
||||||
opdsUserRepository.deleteById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void resetPassword(Long id, String newPassword) {
|
|
||||||
OpdsUserEntity opdsUser = opdsUserRepository.findById(id).orElseThrow(() -> ApiError.USER_NOT_FOUND.createException(id));
|
|
||||||
opdsUser.setPassword(passwordEncoder.encode(newPassword));
|
|
||||||
opdsUserRepository.save(opdsUser);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-78
@@ -1,78 +0,0 @@
|
|||||||
package com.adityachandel.booklore.config.security.service;
|
|
||||||
|
|
||||||
import com.adityachandel.booklore.config.security.userdetails.OpdsUserDetails;
|
|
||||||
import com.adityachandel.booklore.mapper.OpdsUserMapper;
|
|
||||||
import com.adityachandel.booklore.mapper.OpdsUserV2Mapper;
|
|
||||||
import com.adityachandel.booklore.model.entity.OpdsUserEntity;
|
|
||||||
import com.adityachandel.booklore.model.entity.OpdsUserV2Entity;
|
|
||||||
import com.adityachandel.booklore.repository.OpdsUserRepository;
|
|
||||||
import com.adityachandel.booklore.repository.OpdsUserV2Repository;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
|
||||||
class OpdsUserDetailsServiceTest {
|
|
||||||
|
|
||||||
private OpdsUserRepository opdsUserRepository;
|
|
||||||
private OpdsUserV2Repository opdsUserV2Repository;
|
|
||||||
private OpdsUserMapper opdsUserMapper;
|
|
||||||
private OpdsUserV2Mapper opdsUserV2Mapper;
|
|
||||||
private OpdsUserDetailsService service;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void setUp() {
|
|
||||||
opdsUserRepository = mock(OpdsUserRepository.class);
|
|
||||||
opdsUserV2Repository = mock(OpdsUserV2Repository.class);
|
|
||||||
opdsUserMapper = mock(OpdsUserMapper.class);
|
|
||||||
opdsUserV2Mapper = mock(OpdsUserV2Mapper.class);
|
|
||||||
|
|
||||||
service = new OpdsUserDetailsService(opdsUserRepository, opdsUserV2Repository, opdsUserMapper, opdsUserV2Mapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void loadUserByUsername_primaryRepositoryHit_usesPrimaryMapperAndDoesNotCallV2() {
|
|
||||||
String username = "primaryUser";
|
|
||||||
|
|
||||||
Optional<OpdsUserEntity> primaryEntity = Optional.of(mock(OpdsUserEntity.class));
|
|
||||||
when(opdsUserRepository.findByUsername(username)).thenReturn(primaryEntity);
|
|
||||||
|
|
||||||
OpdsUserDetails result = service.loadUserByUsername(username);
|
|
||||||
|
|
||||||
assertNotNull(result, "Expected non-null OpdsUserDetails when primary repo returns a user");
|
|
||||||
verify(opdsUserMapper, times(1)).toOpdsUser(any(OpdsUserEntity.class));
|
|
||||||
verify(opdsUserV2Repository, never()).findByUsername(anyString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void loadUserByUsername_primaryEmpty_v2RepositoryHit_usesV2Mapper() {
|
|
||||||
String username = "v2User";
|
|
||||||
|
|
||||||
when(opdsUserRepository.findByUsername(username)).thenReturn(Optional.empty());
|
|
||||||
|
|
||||||
Optional<OpdsUserV2Entity> v2Entity = Optional.of(mock(OpdsUserV2Entity.class));
|
|
||||||
when(opdsUserV2Repository.findByUsername(username)).thenReturn(v2Entity);
|
|
||||||
|
|
||||||
OpdsUserDetails result = service.loadUserByUsername(username);
|
|
||||||
|
|
||||||
assertNotNull(result, "Expected non-null OpdsUserDetails when v2 repo returns a user");
|
|
||||||
verify(opdsUserRepository, times(1)).findByUsername(username);
|
|
||||||
verify(opdsUserV2Repository, times(1)).findByUsername(username);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void loadUserByUsername_bothRepositoriesEmpty_throwsException() {
|
|
||||||
String username = "missingUser";
|
|
||||||
|
|
||||||
when(opdsUserRepository.findByUsername(username)).thenReturn(Optional.empty());
|
|
||||||
when(opdsUserV2Repository.findByUsername(username)).thenReturn(Optional.empty());
|
|
||||||
|
|
||||||
assertThrows(Exception.class, () -> service.loadUserByUsername(username), "Expected an exception when user not found in either repository");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<div class="settings-header">
|
<div class="settings-header">
|
||||||
<h2 class="settings-title">
|
<h2 class="settings-title">
|
||||||
<i class="pi pi-server"></i>
|
<i class="pi pi-server"></i>
|
||||||
OPDS Settings v2
|
OPDS Settings (New)
|
||||||
</h2>
|
</h2>
|
||||||
<p class="settings-description">
|
<p class="settings-description">
|
||||||
Manage your OPDS credentials and control how your book collection is shared with reading apps.
|
Manage your OPDS credentials and control how your book collection is shared with reading apps.
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
<div class="section-header">
|
<div class="section-header">
|
||||||
<h3 class="section-title">
|
<h3 class="section-title">
|
||||||
<i class="pi pi-link"></i>
|
<i class="pi pi-link"></i>
|
||||||
OPDS Endpoint
|
OPDS Endpoints
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -52,28 +52,59 @@
|
|||||||
<div class="setting-item">
|
<div class="setting-item">
|
||||||
<div class="setting-info">
|
<div class="setting-info">
|
||||||
<div class="setting-label-row">
|
<div class="setting-label-row">
|
||||||
<label class="setting-label">Endpoint URL</label>
|
<label class="setting-label">OPDS v1 Catalog</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input
|
<input
|
||||||
id="endpoint-url"
|
id="endpoint-url-v1"
|
||||||
class="endpoint-input"
|
class="endpoint-input"
|
||||||
fluid
|
fluid
|
||||||
type="text"
|
type="text"
|
||||||
pInputText
|
pInputText
|
||||||
[value]="opdsEndpoint"
|
[value]="opdsV1Endpoint"
|
||||||
readonly/>
|
readonly/>
|
||||||
<p-button
|
<p-button
|
||||||
icon="pi pi-copy"
|
icon="pi pi-copy"
|
||||||
severity="info"
|
severity="info"
|
||||||
outlined
|
outlined
|
||||||
size="small"
|
size="small"
|
||||||
(onClick)="copyEndpoint()">
|
(onClick)="copyV1Endpoint()">
|
||||||
</p-button>
|
</p-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="setting-description">
|
<p class="setting-description">
|
||||||
<i class="pi pi-info-circle"></i>
|
<i class="pi pi-info-circle"></i>
|
||||||
Use this URL to connect your reading apps to your OPDS catalog.
|
OPDS v1 specification - Compatible with most reading apps and OPDS clients.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="endpoint-divider"></div>
|
||||||
|
|
||||||
|
<div class="setting-item">
|
||||||
|
<div class="setting-info">
|
||||||
|
<div class="setting-label-row">
|
||||||
|
<label class="setting-label">OPDS v2 Catalog</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input
|
||||||
|
id="endpoint-url-v2"
|
||||||
|
class="endpoint-input"
|
||||||
|
fluid
|
||||||
|
type="text"
|
||||||
|
pInputText
|
||||||
|
[value]="opdsV2Endpoint"
|
||||||
|
readonly/>
|
||||||
|
<p-button
|
||||||
|
icon="pi pi-copy"
|
||||||
|
severity="info"
|
||||||
|
outlined
|
||||||
|
size="small"
|
||||||
|
(onClick)="copyV2Endpoint()">
|
||||||
|
</p-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="setting-description">
|
||||||
|
<i class="pi pi-exclamation-triangle"></i>
|
||||||
|
OPDS v2 specification - Note: Not all clients support v2. Use v1 for better compatibility.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -132,13 +132,14 @@
|
|||||||
.setting-label {
|
.setting-label {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
min-width: 180px;
|
min-width: 150px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-group {
|
.input-group {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 0.75rem;
|
gap: 0.75rem;
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -182,6 +183,18 @@
|
|||||||
min-width: 25rem;
|
min-width: 25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.endpoint-divider {
|
||||||
|
height: 1px;
|
||||||
|
background: var(--p-content-border-color);
|
||||||
|
margin: 1.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-description {
|
||||||
|
.pi-exclamation-triangle {
|
||||||
|
color: var(--p-orange-500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.table-card {
|
.table-card {
|
||||||
border: 1px solid var(--p-content-border-color);
|
border: 1px solid var(--p-content-border-color);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ import {AppSettingKey} from '../../core/model/app-settings.model';
|
|||||||
export class OpdsSettingsV2 implements OnInit, OnDestroy {
|
export class OpdsSettingsV2 implements OnInit, OnDestroy {
|
||||||
|
|
||||||
opdsEndpoint = `${API_CONFIG.BASE_URL}/api/v2/opds/catalog`;
|
opdsEndpoint = `${API_CONFIG.BASE_URL}/api/v2/opds/catalog`;
|
||||||
|
opdsV1Endpoint = `${API_CONFIG.BASE_URL}/api/v2/opds/catalog`;
|
||||||
|
opdsV2Endpoint = `${API_CONFIG.BASE_URL}/api/v2/opds`;
|
||||||
opdsEnabled = false;
|
opdsEnabled = false;
|
||||||
|
|
||||||
private opdsService = inject(OpdsV2Service);
|
private opdsService = inject(OpdsV2Service);
|
||||||
@@ -157,6 +159,18 @@ export class OpdsSettingsV2 implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copyV1Endpoint(): void {
|
||||||
|
navigator.clipboard.writeText(this.opdsV1Endpoint).then(() => {
|
||||||
|
this.showMessage('success', 'Copied', 'OPDS v1 endpoint copied to clipboard');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
copyV2Endpoint(): void {
|
||||||
|
navigator.clipboard.writeText(this.opdsV2Endpoint).then(() => {
|
||||||
|
this.showMessage('success', 'Copied', 'OPDS v2 endpoint copied to clipboard');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
toggleOpdsServer(): void {
|
toggleOpdsServer(): void {
|
||||||
this.saveSetting(AppSettingKey.OPDS_SERVER_ENABLED, this.opdsEnabled);
|
this.saveSetting(AppSettingKey.OPDS_SERVER_ENABLED, this.opdsEnabled);
|
||||||
if (this.opdsEnabled) {
|
if (this.opdsEnabled) {
|
||||||
|
|||||||
@@ -1,288 +0,0 @@
|
|||||||
<div class="main-container enclosing-container">
|
|
||||||
<div class="settings-header">
|
|
||||||
<h2 class="settings-title">
|
|
||||||
<i class="pi pi-server"></i>
|
|
||||||
OPDS Settings v1 (Legacy)
|
|
||||||
</h2>
|
|
||||||
<p class="settings-description">
|
|
||||||
Legacy OPDS server settings for managing your book collection access.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="deprecation-notice">
|
|
||||||
<i class="pi pi-exclamation-triangle"></i>
|
|
||||||
<div>
|
|
||||||
<p class="notice-title">Deprecated:</p>
|
|
||||||
<p class="notice-text">
|
|
||||||
OPDS v1 support will be removed in a future release.
|
|
||||||
Please migrate to <strong>OPDS v2</strong> for continued support and improvements.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="settings-content">
|
|
||||||
<div class="preferences-section">
|
|
||||||
<div class="section-header">
|
|
||||||
<h3 class="section-title">
|
|
||||||
<i class="pi pi-power-off"></i>
|
|
||||||
Server Control
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="settings-card">
|
|
||||||
<div class="setting-item">
|
|
||||||
<div class="setting-info">
|
|
||||||
<div class="setting-label-row">
|
|
||||||
<label class="setting-label">OPDS Server Enabled</label>
|
|
||||||
<p-toggleswitch
|
|
||||||
[(ngModel)]="opdsEnabled"
|
|
||||||
(onChange)="toggleOpdsServer()">
|
|
||||||
</p-toggleswitch>
|
|
||||||
</div>
|
|
||||||
<p class="setting-description">
|
|
||||||
<i class="pi pi-info-circle"></i>
|
|
||||||
Enable or disable the OPDS server to control access to your book collection through reading apps.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@if (opdsEnabled) {
|
|
||||||
<div class="preferences-section">
|
|
||||||
<div class="section-header">
|
|
||||||
<h3 class="section-title">
|
|
||||||
<i class="pi pi-link"></i>
|
|
||||||
OPDS Endpoint
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="settings-card">
|
|
||||||
<div class="setting-item">
|
|
||||||
<div class="setting-info">
|
|
||||||
<div class="setting-label-row">
|
|
||||||
<label class="setting-label">Endpoint URL</label>
|
|
||||||
<div class="input-group">
|
|
||||||
<input
|
|
||||||
id="endpoint-url"
|
|
||||||
class="endpoint-input"
|
|
||||||
type="text"
|
|
||||||
pInputText
|
|
||||||
[value]="opdsEndpoint"
|
|
||||||
readonly/>
|
|
||||||
<p-button
|
|
||||||
icon="pi pi-copy"
|
|
||||||
severity="info"
|
|
||||||
outlined
|
|
||||||
size="small"
|
|
||||||
(onClick)="copyOpdsEndpoint()">
|
|
||||||
</p-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p class="setting-description">
|
|
||||||
<i class="pi pi-info-circle"></i>
|
|
||||||
Use this URL to connect your reading apps to your OPDS catalog.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="preferences-section">
|
|
||||||
<div class="section-header">
|
|
||||||
<h3 class="section-title">
|
|
||||||
<i class="pi pi-users"></i>
|
|
||||||
OPDS Users
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="table-card">
|
|
||||||
<p-table [value]="users">
|
|
||||||
<ng-template pTemplate="header">
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<div class="header-content">
|
|
||||||
<i class="pi pi-user"></i>
|
|
||||||
<span>Username</span>
|
|
||||||
</div>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<div class="header-content">
|
|
||||||
<i class="pi pi-key"></i>
|
|
||||||
<span>Password</span>
|
|
||||||
</div>
|
|
||||||
</th>
|
|
||||||
<th class="actions-header">
|
|
||||||
<div class="header-content">
|
|
||||||
<i class="pi pi-cog"></i>
|
|
||||||
<span>Actions</span>
|
|
||||||
</div>
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</ng-template>
|
|
||||||
<ng-template pTemplate="body" let-user>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<div class="user-info">
|
|
||||||
<div class="user-avatar">
|
|
||||||
{{ user.username.charAt(0).toUpperCase() }}
|
|
||||||
</div>
|
|
||||||
<span class="username">{{ user.username }}</span>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<p-password
|
|
||||||
fluid
|
|
||||||
class="w-32 md:w-56"
|
|
||||||
[(ngModel)]="dummyPassword"
|
|
||||||
[feedback]="false"
|
|
||||||
size="small"
|
|
||||||
[disabled]="true"
|
|
||||||
[toggleMask]="false">
|
|
||||||
</p-password>
|
|
||||||
<i
|
|
||||||
class="pi pi-info-circle text-gray-400"
|
|
||||||
pTooltip="The password is hidden for security reasons and is only visible once during creation. You can reset the password if needed."
|
|
||||||
tooltipPosition="right"
|
|
||||||
style="cursor: pointer;">
|
|
||||||
</i>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td class="actions-cell">
|
|
||||||
<div class="action-buttons">
|
|
||||||
<p-button
|
|
||||||
icon="pi pi-key"
|
|
||||||
severity="warn"
|
|
||||||
size="small"
|
|
||||||
[outlined]="true"
|
|
||||||
[rounded]="true"
|
|
||||||
(onClick)="openResetPasswordDialog(user)"
|
|
||||||
pTooltip="Reset password">
|
|
||||||
</p-button>
|
|
||||||
<p-button
|
|
||||||
icon="pi pi-trash"
|
|
||||||
severity="danger"
|
|
||||||
size="small"
|
|
||||||
[outlined]="true"
|
|
||||||
[rounded]="true"
|
|
||||||
(onClick)="deleteUser(user.id)"
|
|
||||||
pTooltip="Delete user">
|
|
||||||
</p-button>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</ng-template>
|
|
||||||
<ng-template pTemplate="emptymessage">
|
|
||||||
<tr>
|
|
||||||
<td colspan="3">
|
|
||||||
<div class="empty-message">
|
|
||||||
<i class="pi pi-users"></i>
|
|
||||||
<p class="empty-title">No users found</p>
|
|
||||||
<p class="empty-subtitle">Create your first OPDS user to get started</p>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</ng-template>
|
|
||||||
</p-table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p-dialog
|
|
||||||
header="Create User"
|
|
||||||
[(visible)]="createUserDialogVisible"
|
|
||||||
[modal]="true"
|
|
||||||
styleClass="user-dialog"
|
|
||||||
[style]="{width: '400px'}">
|
|
||||||
<div class="dialog-form">
|
|
||||||
<div class="form-field">
|
|
||||||
<label for="username">Username</label>
|
|
||||||
<input
|
|
||||||
id="username"
|
|
||||||
type="text"
|
|
||||||
pInputText
|
|
||||||
[(ngModel)]="newUser.username"
|
|
||||||
placeholder="Enter username"/>
|
|
||||||
</div>
|
|
||||||
<div class="form-field">
|
|
||||||
<div class="label-with-info">
|
|
||||||
<label for="password">Password</label>
|
|
||||||
<i
|
|
||||||
class="pi pi-info-circle text-yellow-500"
|
|
||||||
pTooltip="Password can only be seen now. It won't be retrievable later. Please save it securely."
|
|
||||||
tooltipPosition="right"
|
|
||||||
style="cursor: pointer;">
|
|
||||||
</i>
|
|
||||||
</div>
|
|
||||||
<input
|
|
||||||
id="password"
|
|
||||||
type="password"
|
|
||||||
pInputText
|
|
||||||
[(ngModel)]="newUser.password"
|
|
||||||
placeholder="Enter password"/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<ng-template pTemplate="footer">
|
|
||||||
<div class="dialog-actions">
|
|
||||||
<p-button
|
|
||||||
label="Cancel"
|
|
||||||
severity="secondary"
|
|
||||||
outlined="true"
|
|
||||||
(onClick)="cancelCreateUser()">
|
|
||||||
</p-button>
|
|
||||||
<p-button
|
|
||||||
label="Create"
|
|
||||||
severity="success"
|
|
||||||
[disabled]="!newUser.username || !newUser.password"
|
|
||||||
(onClick)="saveNewUser()">
|
|
||||||
</p-button>
|
|
||||||
</div>
|
|
||||||
</ng-template>
|
|
||||||
</p-dialog>
|
|
||||||
|
|
||||||
<p-dialog
|
|
||||||
header="Reset User Password"
|
|
||||||
[(visible)]="resetPasswordDialogVisible"
|
|
||||||
[modal]="true"
|
|
||||||
styleClass="user-dialog"
|
|
||||||
[style]="{width: '400px'}">
|
|
||||||
<div class="dialog-form">
|
|
||||||
<p class="reset-info">Reset password for: <strong>{{ selectedUser?.username }}</strong></p>
|
|
||||||
<div class="form-field">
|
|
||||||
<div class="label-with-info">
|
|
||||||
<label for="newPassword">New Password</label>
|
|
||||||
<i
|
|
||||||
class="pi pi-info-circle text-yellow-500"
|
|
||||||
pTooltip="Password can only be seen now. It won't be retrievable later. Please save it securely."
|
|
||||||
tooltipPosition="right"
|
|
||||||
style="cursor: pointer;">
|
|
||||||
</i>
|
|
||||||
</div>
|
|
||||||
<input
|
|
||||||
id="newPassword"
|
|
||||||
type="password"
|
|
||||||
pInputText
|
|
||||||
[(ngModel)]="newPassword"
|
|
||||||
placeholder="Enter new password"/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<ng-template pTemplate="footer">
|
|
||||||
<div class="dialog-actions">
|
|
||||||
<p-button
|
|
||||||
label="Cancel"
|
|
||||||
severity="secondary"
|
|
||||||
outlined="true"
|
|
||||||
(onClick)="cancelResetPassword()">
|
|
||||||
</p-button>
|
|
||||||
<p-button
|
|
||||||
label="Reset"
|
|
||||||
severity="success"
|
|
||||||
[disabled]="!newPassword"
|
|
||||||
(onClick)="confirmResetPassword()">
|
|
||||||
</p-button>
|
|
||||||
</div>
|
|
||||||
</ng-template>
|
|
||||||
</p-dialog>
|
|
||||||
</div>
|
|
||||||
@@ -1,377 +0,0 @@
|
|||||||
.main-container {
|
|
||||||
width: 100%;
|
|
||||||
padding: 1rem;
|
|
||||||
height: calc(100dvh - 10.5rem);
|
|
||||||
overflow-y: auto;
|
|
||||||
border-width: 1px;
|
|
||||||
border-radius: 0.5rem;
|
|
||||||
|
|
||||||
@media (min-width: 768px) {
|
|
||||||
height: calc(100dvh - 11.65rem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.enclosing-container {
|
|
||||||
border-color: var(--p-content-border-color);
|
|
||||||
background: var(--p-content-background);
|
|
||||||
}
|
|
||||||
|
|
||||||
.settings-header {
|
|
||||||
margin-top: 1rem;
|
|
||||||
margin-bottom: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.settings-title {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.75rem;
|
|
||||||
font-size: 1.25rem;
|
|
||||||
font-weight: 700;
|
|
||||||
color: var(--p-text-color);
|
|
||||||
margin: 0 0 0.75rem 0;
|
|
||||||
|
|
||||||
.pi {
|
|
||||||
color: var(--p-primary-color);
|
|
||||||
font-size: 1.25rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.settings-description {
|
|
||||||
color: var(--p-text-muted-color);
|
|
||||||
font-size: 0.875rem;
|
|
||||||
line-height: 1.5;
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.deprecation-notice {
|
|
||||||
display: flex;
|
|
||||||
align-items: flex-start;
|
|
||||||
gap: 0.75rem;
|
|
||||||
padding: 1rem;
|
|
||||||
border-radius: 8px;
|
|
||||||
border: 1px solid var(--p-red-500);
|
|
||||||
background: rgba(239, 68, 68, 0.1);
|
|
||||||
color: var(--p-red-400);
|
|
||||||
|
|
||||||
.pi {
|
|
||||||
color: var(--p-red-500);
|
|
||||||
margin-top: 0.125rem;
|
|
||||||
font-size: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notice-title {
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--p-red-500);
|
|
||||||
margin: 0 0 0.25rem 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notice-text {
|
|
||||||
font-size: 0.875rem;
|
|
||||||
margin: 0;
|
|
||||||
line-height: 1.4;
|
|
||||||
|
|
||||||
strong {
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.settings-content {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.preferences-section {
|
|
||||||
@media (min-width: 768px) {
|
|
||||||
padding: 0 1rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.section-header {
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.section-title {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.5rem;
|
|
||||||
font-size: 1.125rem;
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--p-text-color);
|
|
||||||
margin: 0;
|
|
||||||
|
|
||||||
.pi {
|
|
||||||
color: var(--p-primary-color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.settings-card {
|
|
||||||
border: 1px solid var(--p-content-border-color);
|
|
||||||
border-radius: 8px;
|
|
||||||
background: var(--p-content-background);
|
|
||||||
padding: 1.5rem;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.setting-item {
|
|
||||||
display: flex;
|
|
||||||
align-items: flex-start;
|
|
||||||
gap: 2rem;
|
|
||||||
|
|
||||||
&:last-child {
|
|
||||||
border-bottom: none;
|
|
||||||
padding-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 1rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.setting-info {
|
|
||||||
flex: 1;
|
|
||||||
min-width: 0;
|
|
||||||
|
|
||||||
.setting-label {
|
|
||||||
display: block;
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--p-text-color);
|
|
||||||
font-size: 1rem;
|
|
||||||
margin-bottom: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.setting-label-row {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 1rem;
|
|
||||||
margin-bottom: 0.5rem;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
|
|
||||||
.setting-label {
|
|
||||||
margin-bottom: 0;
|
|
||||||
flex-shrink: 0;
|
|
||||||
min-width: 180px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.input-group {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.75rem;
|
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: flex-start;
|
|
||||||
gap: 0.5rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.setting-description {
|
|
||||||
display: flex;
|
|
||||||
align-items: flex-start;
|
|
||||||
gap: 0.5rem;
|
|
||||||
color: var(--p-text-muted-color);
|
|
||||||
font-size: 0.875rem;
|
|
||||||
line-height: 1.5;
|
|
||||||
margin: 0;
|
|
||||||
|
|
||||||
.pi {
|
|
||||||
color: var(--p-primary-color);
|
|
||||||
margin-top: 0.125rem;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.input-group {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.75rem;
|
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: flex-start;
|
|
||||||
gap: 0.5rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.endpoint-input {
|
|
||||||
min-width: 9rem;
|
|
||||||
max-width: 30rem;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table-card {
|
|
||||||
border: 1px solid var(--p-content-border-color);
|
|
||||||
border-radius: 8px;
|
|
||||||
overflow: hidden;
|
|
||||||
background: var(--p-content-background);
|
|
||||||
}
|
|
||||||
|
|
||||||
.p-datatable {
|
|
||||||
.p-datatable-table {
|
|
||||||
border-collapse: separate;
|
|
||||||
border-spacing: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.p-datatable-thead > tr > th {
|
|
||||||
background: var(--p-surface-100);
|
|
||||||
border-bottom: 2px solid var(--p-content-border-color);
|
|
||||||
padding: 1rem;
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--p-text-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.p-datatable-tbody > tr {
|
|
||||||
transition: background-color 0.2s;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background: var(--p-surface-50);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:last-child {
|
|
||||||
border-bottom: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.p-datatable-tbody > tr > td {
|
|
||||||
padding: 1rem;
|
|
||||||
border: none;
|
|
||||||
text-align: left;
|
|
||||||
vertical-align: middle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.p-datatable th .header-content {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: flex-start;
|
|
||||||
gap: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.user-info {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.user-avatar {
|
|
||||||
width: 32px;
|
|
||||||
height: 32px;
|
|
||||||
border-radius: 50%;
|
|
||||||
background: var(--p-primary-color);
|
|
||||||
color: white;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
font-weight: 600;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.username {
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.actions-cell {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.action-buttons {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
gap: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.empty-message {
|
|
||||||
text-align: center;
|
|
||||||
padding: 2rem 1rem;
|
|
||||||
color: var(--p-text-muted-color);
|
|
||||||
|
|
||||||
.pi {
|
|
||||||
font-size: 2rem;
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
color: var(--p-surface-400);
|
|
||||||
}
|
|
||||||
|
|
||||||
.empty-title {
|
|
||||||
font-size: 1.125rem;
|
|
||||||
font-weight: 600;
|
|
||||||
margin-bottom: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.empty-subtitle {
|
|
||||||
font-size: 0.875rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.user-dialog {
|
|
||||||
.p-dialog-content {
|
|
||||||
padding: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.p-dialog-footer {
|
|
||||||
padding: 1rem 1.5rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.dialog-form {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-field {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 0.5rem;
|
|
||||||
|
|
||||||
label {
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--p-text-color);
|
|
||||||
font-size: 0.875rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
input {
|
|
||||||
width: 100%;
|
|
||||||
padding: 0.75rem;
|
|
||||||
transition: border-color 0.2s;
|
|
||||||
|
|
||||||
&:focus {
|
|
||||||
outline: none;
|
|
||||||
border-color: var(--p-primary-color);
|
|
||||||
box-shadow: 0 0 0 2px var(--p-primary-color-alpha-20);
|
|
||||||
}
|
|
||||||
|
|
||||||
&::placeholder {
|
|
||||||
color: var(--p-text-muted-color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.label-with-info {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dialog-actions {
|
|
||||||
display: flex;
|
|
||||||
justify-content: flex-end;
|
|
||||||
gap: 0.75rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.reset-info {
|
|
||||||
color: var(--p-text-color);
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.custom-border {
|
|
||||||
border: 1px solid var(--border-color);
|
|
||||||
border-radius: var(--card-border);
|
|
||||||
}
|
|
||||||
@@ -1,187 +0,0 @@
|
|||||||
import {Component, inject, OnInit} from '@angular/core';
|
|
||||||
import {FormsModule} from '@angular/forms';
|
|
||||||
|
|
||||||
import {TableModule} from 'primeng/table';
|
|
||||||
import {Button} from 'primeng/button';
|
|
||||||
import {InputText} from 'primeng/inputtext';
|
|
||||||
import {Dialog} from 'primeng/dialog';
|
|
||||||
import {Tooltip} from 'primeng/tooltip';
|
|
||||||
import {MessageService} from 'primeng/api';
|
|
||||||
import {filter, take} from 'rxjs/operators';
|
|
||||||
|
|
||||||
import {OpdsUser, OpdsUserService} from './opds-user.service';
|
|
||||||
import {AppSettingsService} from '../../core/service/app-settings.service';
|
|
||||||
import {AppSettingKey, AppSettings} from '../../core/model/app-settings.model';
|
|
||||||
import {Password} from 'primeng/password';
|
|
||||||
import {API_CONFIG} from '../../config/api-config';
|
|
||||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'app-opds-settings',
|
|
||||||
standalone: true,
|
|
||||||
imports: [
|
|
||||||
FormsModule,
|
|
||||||
TableModule,
|
|
||||||
Button,
|
|
||||||
InputText,
|
|
||||||
Dialog,
|
|
||||||
Tooltip,
|
|
||||||
Password,
|
|
||||||
ToggleSwitch
|
|
||||||
],
|
|
||||||
templateUrl: './opds-settings.component.html',
|
|
||||||
styleUrl: './opds-settings.component.scss'
|
|
||||||
})
|
|
||||||
export class OpdsSettingsComponent implements OnInit {
|
|
||||||
opdsEnabled = false;
|
|
||||||
users: OpdsUser[] = [];
|
|
||||||
selectedUser: OpdsUser | null = null;
|
|
||||||
createUserDialogVisible = false;
|
|
||||||
resetPasswordDialogVisible = false;
|
|
||||||
newUser = {username: '', password: ''};
|
|
||||||
newPassword = '';
|
|
||||||
opdsEndpoint: string = `${API_CONFIG.BASE_URL}/api/v1/opds/catalog`;
|
|
||||||
dummyPassword: string = '********************************';
|
|
||||||
|
|
||||||
private readonly appSettings$ = inject(AppSettingsService).appSettings$;
|
|
||||||
private readonly opdsUserService = inject(OpdsUserService);
|
|
||||||
private readonly messageService = inject(MessageService);
|
|
||||||
private readonly appSettingsService = inject(AppSettingsService);
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
|
||||||
this.appSettings$
|
|
||||||
.pipe(
|
|
||||||
filter((settings): settings is AppSettings => settings != null),
|
|
||||||
take(1)
|
|
||||||
)
|
|
||||||
.subscribe(settings => {
|
|
||||||
this.opdsEnabled = settings.opdsServerEnabled ?? false;
|
|
||||||
if (this.opdsEnabled) {
|
|
||||||
this.loadUsers();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleOpdsServer(): void {
|
|
||||||
this.saveSetting(AppSettingKey.OPDS_SERVER_ENABLED, this.opdsEnabled);
|
|
||||||
if (this.opdsEnabled) {
|
|
||||||
this.loadUsers();
|
|
||||||
} else {
|
|
||||||
this.users = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadUsers(): void {
|
|
||||||
this.opdsUserService.getUsers().subscribe({
|
|
||||||
next: (users) => this.users = users,
|
|
||||||
error: () => this.showError('Load Users Failed', 'Unable to fetch users.')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
openCreateUserDialog(): void {
|
|
||||||
this.newUser = {username: '', password: ''};
|
|
||||||
this.createUserDialogVisible = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
cancelCreateUser(): void {
|
|
||||||
this.createUserDialogVisible = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
saveNewUser(): void {
|
|
||||||
const {username, password} = this.newUser;
|
|
||||||
|
|
||||||
if (username.trim() && password.trim()) {
|
|
||||||
this.opdsUserService.createUser(this.newUser).subscribe({
|
|
||||||
next: () => {
|
|
||||||
this.createUserDialogVisible = false;
|
|
||||||
this.loadUsers();
|
|
||||||
this.showSuccess('User Created', 'New OPDS user created successfully.');
|
|
||||||
},
|
|
||||||
error: (err) => {
|
|
||||||
const errorMessage = err?.error?.message || 'Unable to create user.';
|
|
||||||
this.showError('Create User Failed', errorMessage);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.showWarning('Invalid Input', 'Username and Password are required.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
openResetPasswordDialog(user: OpdsUser): void {
|
|
||||||
this.selectedUser = user;
|
|
||||||
this.newPassword = '';
|
|
||||||
this.resetPasswordDialogVisible = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
cancelResetPassword(): void {
|
|
||||||
this.resetPasswordDialogVisible = false;
|
|
||||||
this.selectedUser = null;
|
|
||||||
this.newPassword = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
copyOpdsEndpoint() {
|
|
||||||
navigator.clipboard.writeText(this.opdsEndpoint)
|
|
||||||
.then(() => {
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
confirmResetPassword(): void {
|
|
||||||
if (this.selectedUser && this.newPassword.trim()) {
|
|
||||||
this.opdsUserService.resetPassword(this.selectedUser.id, this.newPassword).subscribe({
|
|
||||||
next: () => {
|
|
||||||
this.resetPasswordDialogVisible = false;
|
|
||||||
this.showSuccess('Password Reset', 'User password reset successfully.');
|
|
||||||
},
|
|
||||||
error: (err) => {
|
|
||||||
const errorMessage = err?.error?.message || 'Unable to reset password.';
|
|
||||||
this.showError('Reset Password Failed', errorMessage);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.showWarning('Invalid Input', 'New password is required.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteUser(userId: number): void {
|
|
||||||
this.opdsUserService.deleteUser(userId).subscribe({
|
|
||||||
next: () => {
|
|
||||||
this.loadUsers();
|
|
||||||
this.showSuccess('User Deleted', 'User deleted successfully.');
|
|
||||||
},
|
|
||||||
error: () => {
|
|
||||||
this.showError('Delete User Failed', 'Unable to delete user.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private saveSetting(key: string, value: unknown): void {
|
|
||||||
this.appSettingsService.saveSettings([{key, newValue: value}]).subscribe({
|
|
||||||
next: () => {
|
|
||||||
let successMessage = 'Settings saved successfully.';
|
|
||||||
if (key === AppSettingKey.OPDS_SERVER_ENABLED) {
|
|
||||||
successMessage = (value === true)
|
|
||||||
? 'OPDS Server Enabled.'
|
|
||||||
: 'OPDS Server Disabled.';
|
|
||||||
}
|
|
||||||
this.showSuccess('Settings Saved', successMessage);
|
|
||||||
},
|
|
||||||
error: () => {
|
|
||||||
this.showError('Error', 'There was an error saving the settings.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private showSuccess(summary: string, detail: string): void {
|
|
||||||
this.messageService.add({severity: 'success', summary, detail});
|
|
||||||
}
|
|
||||||
|
|
||||||
private showError(summary: string, detail: string): void {
|
|
||||||
this.messageService.add({severity: 'error', summary, detail});
|
|
||||||
}
|
|
||||||
|
|
||||||
private showWarning(summary: string, detail: string): void {
|
|
||||||
this.messageService.add({severity: 'warn', summary, detail});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import {inject, Injectable} from '@angular/core';
|
|
||||||
import {API_CONFIG} from '../../config/api-config';
|
|
||||||
import {HttpClient} from '@angular/common/http';
|
|
||||||
import {Observable} from 'rxjs';
|
|
||||||
|
|
||||||
export interface OpdsUser {
|
|
||||||
id: number;
|
|
||||||
username: string;
|
|
||||||
password: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class OpdsUserService {
|
|
||||||
|
|
||||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/opds-users`;
|
|
||||||
|
|
||||||
private http = inject(HttpClient);
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
}
|
|
||||||
|
|
||||||
createUser(userData: Omit<OpdsUser, 'id'>): Observable<void> {
|
|
||||||
return this.http.post<void>(this.url, userData);
|
|
||||||
}
|
|
||||||
|
|
||||||
getUsers(): Observable<OpdsUser[]> {
|
|
||||||
return this.http.get<OpdsUser[]>(this.url);
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteUser(userId: number): Observable<void> {
|
|
||||||
return this.http.delete<void>(`${this.url}/${userId}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
resetPassword(resetPasswordUserId: number, newPassword: string): Observable<void> {
|
|
||||||
const resetPayload = {
|
|
||||||
password: newPassword
|
|
||||||
};
|
|
||||||
return this.http.put<void>(`${this.url}/${resetPasswordUserId}/reset-password`, resetPayload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -28,12 +28,9 @@
|
|||||||
<p-tab [value]="SettingsTab.AuthenticationSettings">
|
<p-tab [value]="SettingsTab.AuthenticationSettings">
|
||||||
<i class="pi pi-lock"></i> Authentication
|
<i class="pi pi-lock"></i> Authentication
|
||||||
</p-tab>
|
</p-tab>
|
||||||
<p-tab [value]="SettingsTab.Opds">
|
|
||||||
<i class="pi pi-globe"></i> OPDS (Deprecated)
|
|
||||||
</p-tab>
|
|
||||||
}
|
}
|
||||||
<p-tab [value]="SettingsTab.OpdsV2">
|
<p-tab [value]="SettingsTab.OpdsV2">
|
||||||
<i class="pi pi-globe"></i> OPDS v2
|
<i class="pi pi-globe"></i> OPDS
|
||||||
</p-tab>
|
</p-tab>
|
||||||
<p-tab [value]="SettingsTab.DeviceSettings">
|
<p-tab [value]="SettingsTab.DeviceSettings">
|
||||||
<i class="pi pi-mobile"></i> Devices
|
<i class="pi pi-mobile"></i> Devices
|
||||||
@@ -65,9 +62,6 @@
|
|||||||
<p-tabpanel [value]="SettingsTab.AuthenticationSettings">
|
<p-tabpanel [value]="SettingsTab.AuthenticationSettings">
|
||||||
<app-authentication-settings></app-authentication-settings>
|
<app-authentication-settings></app-authentication-settings>
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
<p-tabpanel [value]="SettingsTab.Opds">
|
|
||||||
<app-opds-settings></app-opds-settings>
|
|
||||||
</p-tabpanel>
|
|
||||||
}
|
}
|
||||||
<p-tabpanel [value]="SettingsTab.OpdsV2">
|
<p-tabpanel [value]="SettingsTab.OpdsV2">
|
||||||
<app-opds-settings-v2></app-opds-settings-v2>
|
<app-opds-settings-v2></app-opds-settings-v2>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||||
import {UserService} from './user-management/user.service';
|
import {UserService} from './user-management/user.service';
|
||||||
import { AsyncPipe } from '@angular/common';
|
import {AsyncPipe} from '@angular/common';
|
||||||
import {EmailComponent} from './email/email.component';
|
import {EmailComponent} from './email/email.component';
|
||||||
import {GlobalPreferencesComponent} from './global-preferences/global-preferences.component';
|
import {GlobalPreferencesComponent} from './global-preferences/global-preferences.component';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
@@ -11,7 +11,6 @@ import {AuthenticationSettingsComponent} from '../core/security/oauth2-managemen
|
|||||||
import {ViewPreferencesParentComponent} from './view-preferences-parent/view-preferences-parent.component';
|
import {ViewPreferencesParentComponent} from './view-preferences-parent/view-preferences-parent.component';
|
||||||
import {ReaderPreferences} from './reader-preferences/reader-preferences.component';
|
import {ReaderPreferences} from './reader-preferences/reader-preferences.component';
|
||||||
import {MetadataSettingsComponent} from './metadata-settings-component/metadata-settings-component';
|
import {MetadataSettingsComponent} from './metadata-settings-component/metadata-settings-component';
|
||||||
import {OpdsSettingsComponent} from './opds-settings/opds-settings.component';
|
|
||||||
import {DeviceSettingsComponent} from './device-settings-component/device-settings-component';
|
import {DeviceSettingsComponent} from './device-settings-component/device-settings-component';
|
||||||
import {FileNamingPatternComponent} from './file-naming-pattern/file-naming-pattern.component';
|
import {FileNamingPatternComponent} from './file-naming-pattern/file-naming-pattern.component';
|
||||||
import {OpdsSettingsV2} from './opds-settings-v2/opds-settings-v2';
|
import {OpdsSettingsV2} from './opds-settings-v2/opds-settings-v2';
|
||||||
@@ -26,8 +25,7 @@ export enum SettingsTab {
|
|||||||
MetadataSettings = 'metadata',
|
MetadataSettings = 'metadata',
|
||||||
ApplicationSettings = 'application',
|
ApplicationSettings = 'application',
|
||||||
AuthenticationSettings = 'authentication',
|
AuthenticationSettings = 'authentication',
|
||||||
OpdsV2 = 'opds-v2',
|
OpdsV2 = 'opds'
|
||||||
Opds = 'opds'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -46,7 +44,6 @@ export enum SettingsTab {
|
|||||||
ViewPreferencesParentComponent,
|
ViewPreferencesParentComponent,
|
||||||
ReaderPreferences,
|
ReaderPreferences,
|
||||||
MetadataSettingsComponent,
|
MetadataSettingsComponent,
|
||||||
OpdsSettingsComponent,
|
|
||||||
DeviceSettingsComponent,
|
DeviceSettingsComponent,
|
||||||
FileNamingPatternComponent,
|
FileNamingPatternComponent,
|
||||||
OpdsSettingsV2
|
OpdsSettingsV2
|
||||||
@@ -75,7 +72,7 @@ export class SettingsComponent implements OnInit, OnDestroy {
|
|||||||
this._activeTab = value;
|
this._activeTab = value;
|
||||||
this.router.navigate([], {
|
this.router.navigate([], {
|
||||||
relativeTo: this.route,
|
relativeTo: this.route,
|
||||||
queryParams: { tab: value },
|
queryParams: {tab: value},
|
||||||
queryParamsHandling: 'merge'
|
queryParamsHandling: 'merge'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -89,7 +86,7 @@ export class SettingsComponent implements OnInit, OnDestroy {
|
|||||||
this._activeTab = SettingsTab.ReaderSettings;
|
this._activeTab = SettingsTab.ReaderSettings;
|
||||||
this.router.navigate([], {
|
this.router.navigate([], {
|
||||||
relativeTo: this.route,
|
relativeTo: this.route,
|
||||||
queryParams: { tab: this._activeTab },
|
queryParams: {tab: this._activeTab},
|
||||||
queryParamsHandling: 'merge',
|
queryParamsHandling: 'merge',
|
||||||
replaceUrl: true
|
replaceUrl: true
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user