-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into feature/profile_editing
- Loading branch information
Showing
43 changed files
with
1,309 additions
and
1,269 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import { IKeyValueStoreSymbol, IObjectStoreSymbol } from 'ipmc-interfaces'; | ||
import { IIndexManagerSymbol, IKeyValueStoreSymbol, IObjectStoreSymbol } from 'ipmc-interfaces'; | ||
import { MemoryKeyValueStore } from '../Services/MemoryKeyValueStore'; | ||
import { ObjectStore } from '../Services/ObjectStore'; | ||
import { IModule } from './IModule'; | ||
import { IndexManager } from '../Services/IndexManager'; | ||
import { TaskManager } from '../Services/TaskManager'; | ||
import { ITaskManagerSymbol } from 'ipmc-interfaces'; | ||
|
||
export const CoreModule: IModule = (app) => { | ||
app.register(MemoryKeyValueStore, IKeyValueStoreSymbol); | ||
app.register(ObjectStore, IObjectStoreSymbol); | ||
app.register(IndexManager, IIndexManagerSymbol); | ||
app.register(TaskManager, ITaskManagerSymbol); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { Signal } from '@preact/signals-core'; | ||
import { inject, injectable, postConstruct, preDestroy } from 'inversify'; | ||
import { IIndexManager, IIpfsService, IIpfsServiceSymbol, ILibrary, ILibraryIndex, IObjectStore, IObjectStoreSymbol, IProfile, IProfileSymbol, ITask, isMovieLibrary, isSeriesLibrary } from 'ipmc-interfaces'; | ||
import { MovieIndexFetcher, SeriesIndexFetcher } from './Indexer'; | ||
import { ITaskManager, ITaskManagerSymbol } from 'ipmc-interfaces'; | ||
|
||
@injectable() | ||
export class IndexManager implements IIndexManager { | ||
public constructor( | ||
@inject(IProfileSymbol) private readonly profile: IProfile, | ||
@inject(IIpfsServiceSymbol) private readonly ipfs: IIpfsService, | ||
@inject(IObjectStoreSymbol) private readonly objectStore: IObjectStore, | ||
@inject(ITaskManagerSymbol) private readonly taskManager: ITaskManager | ||
) { | ||
for (const lib of this.profile.libraries) { | ||
this.libraries.set(lib.name, new Signal<ILibrary>(lib)); | ||
const indexSignal = new Signal<ILibraryIndex<any> | undefined>(this.objectStore.get(this.getIndexStorageKey(lib.name))); | ||
this.indexes.set(lib.name, indexSignal); | ||
indexSignal.subscribe((newState) => { | ||
if (newState !== undefined) { | ||
this.objectStore.set(this.getIndexStorageKey(lib.name), newState); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
@postConstruct() | ||
public start(): void { | ||
this.triggerUpdate(); | ||
this.timer = setInterval(() => { | ||
this.triggerUpdate(); | ||
}, 15 * 60 * 1000); | ||
} | ||
|
||
@preDestroy() | ||
public stop(): void { | ||
clearInterval(this.timer); | ||
} | ||
|
||
public indexes = new Map<string, Signal<ILibraryIndex<any> | undefined>>(); | ||
|
||
public tasks = new Signal<ITask[]>([]); | ||
|
||
private getIndexStorageKey(name: string) { | ||
return `${this.profile.id}_index_${name}`; | ||
} | ||
|
||
private triggerUpdate(): void { | ||
for (const library of this.libraries.values()) { | ||
const lib = library.value; | ||
if (!this.updates.has(lib.name)) { | ||
this.taskManager.runTask({ | ||
task: () => this.updateLibrary(lib), | ||
title: '', | ||
onEnd: () => { | ||
this.updates.delete(lib.name); | ||
}, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
private async updateLibrary(library: ILibrary): Promise<void> { | ||
const index = this.indexes.get(library.name); | ||
if (library.upstream != undefined && index != undefined) { | ||
try { | ||
const cid = await this.ipfs.resolve(library.upstream); | ||
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(cid); | ||
|
||
index.value = { | ||
cid: cid, | ||
indexer: indexer.version, | ||
index: newIndex, | ||
}; | ||
} | ||
} catch (ex) { | ||
console.error(ex); | ||
} | ||
} | ||
} | ||
|
||
private libraries = new Map<string, Signal<ILibrary>>(); | ||
|
||
private updates = new Map<string, Promise<void>>(); | ||
|
||
private timer: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export interface IIndexFetcher<TIndex> { | ||
fetchIndex(): Promise<TIndex>; | ||
fetchIndex(cid: string): Promise<TIndex>; | ||
version: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { type IIndexFetcher } from './IIndexFetcher'; | ||
export { MovieIndexFetcher } from './MovieIndexFetcher'; | ||
export { SeriesIndexFetcher } from './SeriesIndexFetcher'; |
103 changes: 0 additions & 103 deletions
103
packages/core/src/Services/ProfileManager/BaseProfileManager.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.