feat: radarr/sonarr tag support (#1366)
parent
db5af6d24b
commit
a306ebc2d1
@ -0,0 +1,169 @@
|
|||||||
|
import cacheManager, { AvailableCacheIds } from '../../lib/cache';
|
||||||
|
import { DVRSettings } from '../../lib/settings';
|
||||||
|
import ExternalAPI from '../externalapi';
|
||||||
|
|
||||||
|
export interface RootFolder {
|
||||||
|
id: number;
|
||||||
|
path: string;
|
||||||
|
freeSpace: number;
|
||||||
|
totalSpace: number;
|
||||||
|
unmappedFolders: {
|
||||||
|
name: string;
|
||||||
|
path: string;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface QualityProfile {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface QueueItem {
|
||||||
|
size: number;
|
||||||
|
title: string;
|
||||||
|
sizeleft: number;
|
||||||
|
timeleft: string;
|
||||||
|
estimatedCompletionTime: string;
|
||||||
|
status: string;
|
||||||
|
trackedDownloadStatus: string;
|
||||||
|
trackedDownloadState: string;
|
||||||
|
downloadId: string;
|
||||||
|
protocol: string;
|
||||||
|
downloadClient: string;
|
||||||
|
indexer: string;
|
||||||
|
id: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Tag {
|
||||||
|
id: number;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface QueueResponse<QueueItemAppendT> {
|
||||||
|
page: number;
|
||||||
|
pageSize: number;
|
||||||
|
sortKey: string;
|
||||||
|
sortDirection: string;
|
||||||
|
totalRecords: number;
|
||||||
|
records: (QueueItem & QueueItemAppendT)[];
|
||||||
|
}
|
||||||
|
|
||||||
|
class ServarrBase<QueueItemAppendT> extends ExternalAPI {
|
||||||
|
static buildUrl(settings: DVRSettings, path?: string): string {
|
||||||
|
return `${settings.useSsl ? 'https' : 'http'}://${settings.hostname}:${
|
||||||
|
settings.port
|
||||||
|
}${settings.baseUrl ?? ''}${path}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected apiName: string;
|
||||||
|
|
||||||
|
constructor({
|
||||||
|
url,
|
||||||
|
apiKey,
|
||||||
|
cacheName,
|
||||||
|
apiName,
|
||||||
|
}: {
|
||||||
|
url: string;
|
||||||
|
apiKey: string;
|
||||||
|
cacheName: AvailableCacheIds;
|
||||||
|
apiName: string;
|
||||||
|
}) {
|
||||||
|
super(
|
||||||
|
url,
|
||||||
|
{
|
||||||
|
apikey: apiKey,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nodeCache: cacheManager.getCache(cacheName).data,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.apiName = apiName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getProfiles = async (): Promise<QualityProfile[]> => {
|
||||||
|
try {
|
||||||
|
const data = await this.getRolling<QualityProfile[]>(
|
||||||
|
`/qualityProfile`,
|
||||||
|
undefined,
|
||||||
|
3600
|
||||||
|
);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(
|
||||||
|
`[${this.apiName}] Failed to retrieve profiles: ${e.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public getRootFolders = async (): Promise<RootFolder[]> => {
|
||||||
|
try {
|
||||||
|
const data = await this.getRolling<RootFolder[]>(
|
||||||
|
`/rootfolder`,
|
||||||
|
undefined,
|
||||||
|
3600
|
||||||
|
);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(
|
||||||
|
`[${this.apiName}] Failed to retrieve root folders: ${e.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public getQueue = async (): Promise<(QueueItem & QueueItemAppendT)[]> => {
|
||||||
|
try {
|
||||||
|
const response = await this.axios.get<QueueResponse<QueueItemAppendT>>(
|
||||||
|
`/queue`
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data.records;
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(
|
||||||
|
`[${this.apiName}] Failed to retrieve queue: ${e.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public getTags = async (): Promise<Tag[]> => {
|
||||||
|
try {
|
||||||
|
const response = await this.axios.get<Tag[]>(`/tag`);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(
|
||||||
|
`[${this.apiName}] Failed to retrieve tags: ${e.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public createTag = async ({ label }: { label: string }): Promise<Tag> => {
|
||||||
|
try {
|
||||||
|
const response = await this.axios.post<Tag>(`/tag`, {
|
||||||
|
label,
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(`[${this.apiName}] Failed to create tag: ${e.message}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
protected async runCommand(
|
||||||
|
commandName: string,
|
||||||
|
options: Record<string, unknown>
|
||||||
|
): Promise<void> {
|
||||||
|
try {
|
||||||
|
await this.axios.post(`/command`, {
|
||||||
|
name: commandName,
|
||||||
|
...options,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(`[${this.apiName}] Failed to run command: ${e.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ServarrBase;
|
@ -0,0 +1,32 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class CreateTagsFieldonMediaRequest1617624225464
|
||||||
|
implements MigrationInterface {
|
||||||
|
name = 'CreateTagsFieldonMediaRequest1617624225464';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TABLE "temporary_media_request" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "status" integer NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "type" varchar NOT NULL, "mediaId" integer, "requestedById" integer, "modifiedById" integer, "is4k" boolean NOT NULL DEFAULT (0), "serverId" integer, "profileId" integer, "rootFolder" varchar, "languageProfileId" integer, "tags" text, CONSTRAINT "FK_f4fc4efa14c3ba2b29c4525fa15" FOREIGN KEY ("modifiedById") REFERENCES "user" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_6997bee94720f1ecb7f31137095" FOREIGN KEY ("requestedById") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_a1aa713f41c99e9d10c48da75a0" FOREIGN KEY ("mediaId") REFERENCES "media" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`INSERT INTO "temporary_media_request"("id", "status", "createdAt", "updatedAt", "type", "mediaId", "requestedById", "modifiedById", "is4k", "serverId", "profileId", "rootFolder", "languageProfileId") SELECT "id", "status", "createdAt", "updatedAt", "type", "mediaId", "requestedById", "modifiedById", "is4k", "serverId", "profileId", "rootFolder", "languageProfileId" FROM "media_request"`
|
||||||
|
);
|
||||||
|
await queryRunner.query(`DROP TABLE "media_request"`);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "temporary_media_request" RENAME TO "media_request"`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "media_request" RENAME TO "temporary_media_request"`
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TABLE "media_request" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "status" integer NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "type" varchar NOT NULL, "mediaId" integer, "requestedById" integer, "modifiedById" integer, "is4k" boolean NOT NULL DEFAULT (0), "serverId" integer, "profileId" integer, "rootFolder" varchar, "languageProfileId" integer, CONSTRAINT "FK_f4fc4efa14c3ba2b29c4525fa15" FOREIGN KEY ("modifiedById") REFERENCES "user" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_6997bee94720f1ecb7f31137095" FOREIGN KEY ("requestedById") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_a1aa713f41c99e9d10c48da75a0" FOREIGN KEY ("mediaId") REFERENCES "media" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`INSERT INTO "media_request"("id", "status", "createdAt", "updatedAt", "type", "mediaId", "requestedById", "modifiedById", "is4k", "serverId", "profileId", "rootFolder", "languageProfileId") SELECT "id", "status", "createdAt", "updatedAt", "type", "mediaId", "requestedById", "modifiedById", "is4k", "serverId", "profileId", "rootFolder", "languageProfileId" FROM "temporary_media_request"`
|
||||||
|
);
|
||||||
|
await queryRunner.query(`DROP TABLE "temporary_media_request"`);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue