163 lines
7.0 KiB
TypeScript
163 lines
7.0 KiB
TypeScript
import {
|
|
danmakuSchemas,
|
|
librarySchemas,
|
|
mountSchemas,
|
|
playbackSchemas,
|
|
scrapeSchemas,
|
|
} from "@app/types";
|
|
import { t } from "../context.js";
|
|
import { danmakuService } from "../services/danmaku.service.js";
|
|
import { libraryService } from "../services/library.service.js";
|
|
import { mountService } from "../services/mount.service.js";
|
|
import { playbackService } from "../services/playback.service.js";
|
|
import { protectedProcedure } from "../services/procedure.js";
|
|
import { scrapeService } from "../services/scrape.service.js";
|
|
|
|
export const mediaRouter = t.router({
|
|
mountList: protectedProcedure
|
|
.input(mountSchemas.list)
|
|
.query(({ ctx }) => mountService.list(ctx.userId)),
|
|
mountCreate: protectedProcedure
|
|
.input(mountSchemas.create)
|
|
.mutation(({ ctx, input }) => mountService.create(ctx.userId, input)),
|
|
mountUpdate: protectedProcedure
|
|
.input(mountSchemas.update)
|
|
.mutation(({ ctx, input }) => mountService.update(ctx.userId, input)),
|
|
mountDelete: protectedProcedure
|
|
.input(mountSchemas.delete)
|
|
.mutation(({ ctx, input }) => mountService.delete(ctx.userId, input.id)),
|
|
mountTest: protectedProcedure
|
|
.input(mountSchemas.test)
|
|
.mutation(({ ctx, input }) => mountService.test(input, ctx.userId)),
|
|
mountListDir: protectedProcedure
|
|
.input(mountSchemas.listDir)
|
|
.query(({ ctx, input }) => mountService.listDir(ctx.userId, input)),
|
|
|
|
libraryList: protectedProcedure
|
|
.input(librarySchemas.list)
|
|
.query(({ ctx, input }) => libraryService.list(ctx.userId, input)),
|
|
libraryGroups: protectedProcedure
|
|
.input(librarySchemas.groups)
|
|
.query(({ ctx, input }) => libraryService.groups(ctx.userId, input)),
|
|
libraryGet: protectedProcedure
|
|
.input(librarySchemas.get)
|
|
.query(({ ctx, input }) => libraryService.get(ctx.userId, input.id)),
|
|
libraryScan: protectedProcedure
|
|
.input(librarySchemas.scan)
|
|
.mutation(({ ctx, input }) => libraryService.scan(ctx.userId, input.mountId, input.path)),
|
|
libraryEnsurePath: protectedProcedure
|
|
.input(librarySchemas.ensurePath)
|
|
.mutation(({ ctx, input }) =>
|
|
libraryService.ensurePath(ctx.userId, input.mountId, input.path),
|
|
),
|
|
librarySeries: protectedProcedure
|
|
.input(librarySchemas.series)
|
|
.query(({ ctx, input }) =>
|
|
libraryService.series(ctx.userId, input.bangumiId, input.mountId),
|
|
),
|
|
libraryDeleteGroup: protectedProcedure
|
|
.input(librarySchemas.deleteGroup)
|
|
.mutation(({ ctx, input }) =>
|
|
libraryService.deleteGroup(ctx.userId, input.mountId, input.bangumiId),
|
|
),
|
|
libraryUpdateGroup: protectedProcedure
|
|
.input(librarySchemas.updateGroup)
|
|
.mutation(({ ctx, input }) =>
|
|
libraryService.updateGroup(ctx.userId, input.mountId, input.bangumiId, {
|
|
title: input.title,
|
|
posterUrl: input.posterUrl,
|
|
}),
|
|
),
|
|
|
|
scrapeSearch: protectedProcedure
|
|
.input(scrapeSchemas.search)
|
|
.query(({ input }) => scrapeService.search(input.q)),
|
|
scrapeDandanMatch: protectedProcedure
|
|
.input(danmakuSchemas.match)
|
|
.mutation(({ ctx, input }) => scrapeService.matchDandanplay(ctx.userId, input.mediaItemId)),
|
|
scrapeBind: protectedProcedure
|
|
.input(scrapeSchemas.bind)
|
|
.mutation(({ ctx, input }) =>
|
|
scrapeService.bind(ctx.userId, input.mediaItemId, input.bangumiId, input.epNumber),
|
|
),
|
|
scrapeBindPath: protectedProcedure
|
|
.input(scrapeSchemas.bindPath)
|
|
.mutation(({ ctx, input }) =>
|
|
scrapeService.bindPath(ctx.userId, input.mountId, input.path, input.bangumiId),
|
|
),
|
|
scrapeRescrape: protectedProcedure
|
|
.input(scrapeSchemas.rescrape)
|
|
.mutation(({ ctx, input }) =>
|
|
scrapeService
|
|
.autoScrape(ctx.userId, input.mediaItemId)
|
|
.then(() => ({ success: true as const })),
|
|
),
|
|
scrapeRescrapePath: protectedProcedure
|
|
.input(scrapeSchemas.rescrapePath)
|
|
.mutation(({ ctx, input }) =>
|
|
scrapeService.rescrapePath(ctx.userId, input.mountId, input.path),
|
|
),
|
|
scrapeUnbindGroup: protectedProcedure
|
|
.input(scrapeSchemas.unbindGroup)
|
|
.mutation(({ ctx, input }) =>
|
|
scrapeService.unbindGroup(ctx.userId, input.mountId, input.bangumiId),
|
|
),
|
|
scrapeBindGroup: protectedProcedure
|
|
.input(scrapeSchemas.bindGroup)
|
|
.mutation(({ ctx, input }) =>
|
|
scrapeService.bindGroup(ctx.userId, input.mountId, input.bangumiId, input.newBangumiId),
|
|
),
|
|
|
|
playbackReport: protectedProcedure
|
|
.input(playbackSchemas.report)
|
|
.mutation(({ ctx, input }) => playbackService.report(ctx.userId, input)),
|
|
playbackGet: protectedProcedure
|
|
.input(playbackSchemas.get)
|
|
.query(({ ctx, input }) => playbackService.get(ctx.userId, input.mediaItemId)),
|
|
playbackContinue: protectedProcedure
|
|
.input(playbackSchemas.continueList)
|
|
.query(({ ctx, input }) => playbackService.continueList(ctx.userId, input.limit)),
|
|
playbackDelete: protectedProcedure
|
|
.input(playbackSchemas.remove)
|
|
.mutation(({ ctx, input }) => playbackService.remove(ctx.userId, input.mediaItemId)),
|
|
playbackClear: protectedProcedure
|
|
.input(playbackSchemas.clear)
|
|
.mutation(({ ctx }) => playbackService.clearAll(ctx.userId)),
|
|
|
|
danmakuFetch: protectedProcedure
|
|
.input(danmakuSchemas.fetch)
|
|
.query(({ ctx, input }) => danmakuService.fetch(ctx.userId, input.mediaItemId)),
|
|
danmakuMatch: protectedProcedure
|
|
.input(danmakuSchemas.match)
|
|
.mutation(({ ctx, input }) =>
|
|
danmakuService.matchCandidates(ctx.userId, input.mediaItemId),
|
|
),
|
|
danmakuSelectMatch: protectedProcedure
|
|
.input(danmakuSchemas.selectMatch)
|
|
.mutation(({ ctx, input }) =>
|
|
danmakuService.selectMatch(ctx.userId, input.mediaItemId, input.episodeId),
|
|
),
|
|
danmakuSearchSource: protectedProcedure
|
|
.input(danmakuSchemas.searchSource)
|
|
.query(({ input }) => danmakuService.searchSource(input.keyword)),
|
|
danmakuSourceEpisodes: protectedProcedure
|
|
.input(danmakuSchemas.sourceEpisodes)
|
|
.query(({ input }) => danmakuService.sourceEpisodes(input.animeId)),
|
|
danmakuClearLocal: protectedProcedure
|
|
.input(danmakuSchemas.clearLocal)
|
|
.mutation(({ ctx, input }) =>
|
|
danmakuService.clearLocalDanmaku(ctx.userId, input.mediaItemId),
|
|
),
|
|
danmakuImport: protectedProcedure
|
|
.input(danmakuSchemas.import)
|
|
.mutation(({ ctx, input }) =>
|
|
danmakuService.importXml(ctx.userId, input.mediaItemId, input.xml),
|
|
),
|
|
danmakuGetSettings: protectedProcedure
|
|
.input(danmakuSchemas.getSettings)
|
|
.query(({ ctx }) => danmakuService.getPrefs(ctx.userId)),
|
|
danmakuSaveSettings: protectedProcedure
|
|
.input(danmakuSchemas.settings)
|
|
.mutation(({ ctx, input }) => danmakuService.savePrefs(ctx.userId, input)),
|
|
});
|