mirror of
https://github.com/aleksilassila/reiverr.git
synced 2026-04-27 03:05:10 +02:00
feat: Add interface for adding and configuring plugins
This commit is contained in:
@@ -26,6 +26,6 @@ export class SourceDto extends PickAndPartial(
|
||||
|
||||
export class CreateSourceDto extends PickAndPartial(
|
||||
MediaSource,
|
||||
['pluginSettings', 'id'],
|
||||
['pluginSettings'],
|
||||
['enabled', 'adminControlled'],
|
||||
) {}
|
||||
|
||||
@@ -3,13 +3,13 @@ import { PluginSettings } from 'plugins/plugin-types';
|
||||
import { User } from 'src/users/user.entity';
|
||||
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm';
|
||||
|
||||
|
||||
@Entity()
|
||||
export class MediaSource {
|
||||
@ApiProperty({ required: true, type: 'string' })
|
||||
@PrimaryColumn()
|
||||
id: string;
|
||||
|
||||
@ApiProperty({ required: true, type: 'string' })
|
||||
@PrimaryColumn()
|
||||
userId: string;
|
||||
|
||||
@@ -18,9 +18,9 @@ export class MediaSource {
|
||||
@JoinColumn({ name: 'userId' })
|
||||
user: User;
|
||||
|
||||
@ApiProperty({ required: false, type: 'string', default: true })
|
||||
@Column({ default: true })
|
||||
enabled: boolean;
|
||||
@ApiProperty({ required: false, type: 'boolean', default: false })
|
||||
@Column({ default: false })
|
||||
enabled: boolean = false;
|
||||
|
||||
@ApiProperty({ required: false, type: 'boolean', default: false })
|
||||
@Column({ default: false })
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
@ApiTags('users')
|
||||
@Controller('users/:userId/sources')
|
||||
@UseGuards(AuthGuard)
|
||||
export class UsersSourcesController {
|
||||
export class UserSourcesController {
|
||||
constructor(
|
||||
private usersService: UsersService,
|
||||
private userSourcesService: UserSourcesService,
|
||||
@@ -68,7 +68,11 @@ export class UsersSourcesController {
|
||||
@Param('sourceId') sourceId: string,
|
||||
@Param('userId') userId: string,
|
||||
): Promise<UserDto> {
|
||||
const updatedUser = await this.userSourcesService.deleteUserSource(userId, sourceId, callerUser);
|
||||
const updatedUser = await this.userSourcesService.deleteUserSource(
|
||||
userId,
|
||||
sourceId,
|
||||
callerUser,
|
||||
);
|
||||
|
||||
return UserDto.fromEntity(updatedUser);
|
||||
}
|
||||
|
||||
@@ -82,13 +82,12 @@ export class UserSourcesService {
|
||||
source.adminControlled =
|
||||
sourceDto.adminControlled ?? source.adminControlled;
|
||||
source.enabled = sourceDto.enabled ?? source.enabled;
|
||||
console.log('Test defaults, enabled', new MediaSource().enabled);
|
||||
source.pluginSettings = sourceDto.pluginSettings ?? source.pluginSettings;
|
||||
|
||||
|
||||
await this.userSourceRepository.save(source);
|
||||
return this.userService.findOne(user.id);
|
||||
}
|
||||
|
||||
|
||||
getSourceSettings(user: User, sourceId: string) {
|
||||
return user.mediaSources?.find((source) => source.id === sourceId)
|
||||
?.pluginSettings;
|
||||
|
||||
@@ -140,6 +140,7 @@ export class User {
|
||||
// @Column('json', { default: '{}' })
|
||||
// pluginSettings: PluginSettings = {};
|
||||
|
||||
@ApiProperty({ required: false, type: MediaSource, isArray: true })
|
||||
@OneToMany(() => MediaSource, (mediaSource) => mediaSource.user)
|
||||
mediaSources: MediaSource[];
|
||||
}
|
||||
|
||||
@@ -6,11 +6,12 @@ import { DatabaseModule } from '../database/database.module';
|
||||
import { LibraryModule } from './library/library.module';
|
||||
import { PlayStateModule } from './play-state/play-state.module';
|
||||
import { UserSourcesService } from './user-sources/user-sources.service';
|
||||
import { UserSourcesController } from './user-sources/user-sources.controller';
|
||||
|
||||
@Module({
|
||||
imports: [DatabaseModule, LibraryModule, PlayStateModule],
|
||||
providers: [...userProviders, UsersService, UserSourcesService],
|
||||
controllers: [UsersController],
|
||||
controllers: [UsersController, UserSourcesController],
|
||||
exports: [UsersService, UserSourcesService],
|
||||
})
|
||||
export class UsersModule {}
|
||||
|
||||
Reference in New Issue
Block a user