Skip to content

Commit

Permalink
feat(core): add plan file
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Jan 7, 2024
1 parent 6953474 commit 80e70fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
11 changes: 5 additions & 6 deletions packages/core/src/anime/anime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { fs as LocalFS } from 'breadfs/node';
import { parse } from 'yaml';
import { format } from 'date-fns';

import type { AnimePlan } from '../plan';
import type { AnimeSystem } from '../system';
import type { AnimePlan, PlanFile } from '../plan';
import type { AnimeSpace, StoragePath } from '../space';

import { AnimeSystemError, debug } from '../error';
Expand All @@ -25,10 +25,10 @@ export class Anime {

public readonly libraryDirectory: StoragePath;

public readonly relativeDirectory: string;

public readonly plan: AnimePlan;

public readonly planFile: PlanFile;

private readonly system: AnimeSystem;

private _lib: LocalLibrary | undefined;
Expand All @@ -47,9 +47,10 @@ export class Anime {
*/
private _dirty = false;

public constructor(system: AnimeSystem, plan: AnimePlan) {
public constructor(system: AnimeSystem, plan: AnimePlan, file: PlanFile) {
this.system = system;
this.plan = plan;
this.planFile = file;

const space = system.space;
const dirname = plan.title;
Expand All @@ -61,8 +62,6 @@ export class Anime {
this.libraryDirectory = plan.directory
? space.storage.library.resolve(plan.directory)
: space.storage.library.join(dirname);

this.relativeDirectory = plan.directory ? plan.directory : dirname;
}

public get space(): AnimeSpace {
Expand Down
7 changes: 1 addition & 6 deletions packages/core/src/system/introspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ export async function loadAnime(
filter: (anime: Anime) => boolean = (p) => p.plan.status === 'onair'
) {
const plans = await system.plans();
const animePlans = flatAnimePlan(plans);
const animes = animePlans.map((ap) => new Anime(system, ap));
const animes = plans.flatMap((p) => p.onair.map((ap) => new Anime(system, ap, p)));

// Detect directory naming conflict
{
Expand Down Expand Up @@ -144,7 +143,3 @@ export async function loadAnime(

return successed.filter(Boolean) as Anime[];
}

export function flatAnimePlan(plans: PlanFile[]) {
return plans.flatMap((p) => p.onair);
}

0 comments on commit 80e70fa

Please sign in to comment.