Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:undyingwraith/ipmc into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
undyingwraith committed Jun 18, 2024
2 parents 9181f78 + f901938 commit c543715
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/Services/IndexManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ export class IndexManager implements IIndexManager {
if (library.upstream != undefined && index != undefined) {
try {
const cid = await this.ipfs.resolve(library.upstream);
const indexer = isMovieLibrary(library) ? new MovieIndexFetcher(this.ipfs, library) : isSeriesLibrary(library) ? new SeriesIndexFetcher(this.ipfs, library) : undefined;
if (index.value?.cid != cid || indexer?.version !== index.value?.indexer) {
const indexer = isMovieLibrary(library) ? new MovieIndexFetcher(this.ipfs) : isSeriesLibrary(library) ? new SeriesIndexFetcher(this.ipfs) : undefined;
if (index.value?.cid != cid || indexer?.version !== index.value.indexer) {
if (indexer == undefined) {
throw new Error(`Unknown library type [${library.type}]`);
}

const newIndex = await indexer.fetchIndex();
const newIndex = await indexer.fetchIndex(cid);

index.value = {
cid: cid,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Services/Indexer/IIndexFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface IIndexFetcher<TIndex> {
fetchIndex(): Promise<TIndex>;
fetchIndex(cid: string): Promise<TIndex>;
version: string;
}
10 changes: 5 additions & 5 deletions packages/core/src/Services/Indexer/MovieIndexFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { IIpfsService, IGenericLibrary, IMovieMetaData, IFileInfo } from 'ipmc-interfaces';
import { IIndexFetcher } from './IIndexFetcher';
import { IFileInfo, IIpfsService, IMovieMetaData } from 'ipmc-interfaces';
import { Regexes } from '../../Regexes';
import { IIndexFetcher } from './IIndexFetcher';

export class MovieIndexFetcher implements IIndexFetcher<IMovieMetaData[]> {
constructor(private readonly node: IIpfsService, private readonly lib: IGenericLibrary<IMovieMetaData, 'movie'>) {
constructor(private readonly node: IIpfsService) {
}

public version = '0';

public async fetchIndex(): Promise<IMovieMetaData[]> {
const files = (await this.node.ls(this.lib.root.toString())).filter(f => f.type == 'dir');
public async fetchIndex(cid: string): Promise<IMovieMetaData[]> {
const files = (await this.node.ls(cid)).filter(f => f.type == 'dir');
const index = [];
for (const file of files) {
index.push(await this.extractMovieMetaData(this.node, file));
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/Services/Indexer/SeriesIndexFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { IIpfsService, IEpisodeMetaData, IGenericLibrary, ISeasonMetaData, ISeriesMetaData, IFileInfo } from 'ipmc-interfaces';
import { IIndexFetcher } from './IIndexFetcher';
import { IEpisodeMetaData, IFileInfo, IIpfsService, ISeasonMetaData, ISeriesMetaData } from 'ipmc-interfaces';
import { Regexes } from '../../Regexes';
import { IIndexFetcher } from './IIndexFetcher';

export class SeriesIndexFetcher implements IIndexFetcher<ISeriesMetaData[]> {
constructor(private readonly node: IIpfsService, private readonly lib: IGenericLibrary<ISeriesMetaData, 'series'>) {
constructor(private readonly node: IIpfsService) {
}

public version = '0';

public async fetchIndex(): Promise<ISeriesMetaData[]> {
const files = (await this.node.ls(this.lib.root.toString())).filter(f => f.type == 'dir');
public async fetchIndex(cid: string): Promise<ISeriesMetaData[]> {
const files = (await this.node.ls(cid)).filter(f => f.type == 'dir');
const index = [];
for (const file of files) {
index.push(await this.extractSeriesMetaData(this.node, file));
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/components/organisms/Library.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import { Display } from '../pages/LibraryManager';
import { ErrorBoundary } from '../atoms/ErrorBoundary';
import { createFilter } from 'ipmc-core';
import { useService } from '../../context/AppContext';
import { useWatcher } from '../../hooks';

export function Library(props: {
display: ReadonlySignal<Display>;
query: ReadonlySignal<string | undefined>;
library: string;
}) {
const { display, library } = props;
const index = useService<IIndexManager>(IIndexManagerSymbol).indexes.get(library)!;
const indexManager = useService<IIndexManager>(IIndexManagerSymbol);
const index = useWatcher(indexManager.indexes.get(library)!.value);
const selected = useSignal<IFileInfo | undefined>(undefined);


Expand Down

0 comments on commit c543715

Please sign in to comment.