Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
641 changes: 357 additions & 284 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"prepare": "husky"
},
"devDependencies": {
"@paperback/toolchain": "^1.0.0-alpha.87",
"@paperback/types": "^1.0.0-alpha.87",
"@paperback/toolchain": "^1.0.0-alpha.89",
"@paperback/types": "^1.0.0-alpha.89",
"@types/chai": "^5.2.3",
"chai": "^6.2.2",
"husky": "^9.1.7",
"oxfmt": "^0.51.0",
"oxlint": "^1.66.0",
"oxfmt": "^0.53.0",
"oxlint": "^1.68.0",
"oxlint-tsgolint": "^0.23.0",
"typescript": "^6.0.3"
}
Expand Down
30 changes: 30 additions & 0 deletions src/AniList/GraphQL/DiscoverSectionsAndSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ query Query(
source_in: $sourceIn
sort: $sort
) {
averageScore
chapters
coverImage {
extraLarge
Expand All @@ -64,6 +65,16 @@ query Query(
genres
id
isAdult
staff {
edges {
node {
name {
full
}
}
role
}
}
status
synonyms
title {
Expand Down Expand Up @@ -116,12 +127,14 @@ type DiscoverSectionsAndSearchPageInfo = {
};

type DiscoverSectionsAndSearchMedia = {
averageScore: number | null;
chapters: number | null;
coverImage: DiscoverSectionsAndSearchCoverImage;
format: string;
genres: string[];
id: number;
isAdult: boolean;
staff: DiscoverSectionsAndSearchStaff;
status: string;
title: DiscoverSectionsAndSearchTitle;
volumes: number | null;
Expand All @@ -134,6 +147,23 @@ export type DiscoverSectionsAndSearchCoverImage = {
medium: string;
};

export type DiscoverSectionsAndSearchStaff = {
edges: DiscoverSectionsAndSearchStaffEdge[];
};

export type DiscoverSectionsAndSearchStaffEdge = {
node: DiscoverSectionsAndSearchStaffNode;
role: string;
};

export type DiscoverSectionsAndSearchStaffNode = {
name: DiscoverSectionsAndSearchStaffName;
};

export type DiscoverSectionsAndSearchStaffName = {
full: string;
};

export type DiscoverSectionsAndSearchTitle = {
english: string | null;
native: string | null;
Expand Down
3 changes: 3 additions & 0 deletions src/AniList/Implementations/DiscoverSection/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ export class DiscoverSectionImplementation implements DiscoverSectionProviding {
let sort: string;

let countryOfOrigin: string | undefined;
let featured;
switch (section.id) {
case "trending-now":
sort = MediaSort.TRENDING_DESC.id;
featured = true;
break;
case "all-time-popular":
sort = MediaSort.POPULARITY_DESC.id;
Expand Down Expand Up @@ -89,6 +91,7 @@ export class DiscoverSectionImplementation implements DiscoverSectionProviding {
variables,
false,
metadata,
featured,
);
}
}
29 changes: 6 additions & 23 deletions src/AniList/Implementations/SearchResults/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export type SearchMetadata = {
startYears?: string;
chapterCounts?: string;
volumeCounts?: string;
adult?: "included" | "excluded";
doujin?: "included" | "excluded";
trackedTitles?: "included" | "excluded";
flags?: { [id: string]: "included" | "excluded" };
tags?: { [id: string]: "included" | "excluded" };
};

Expand All @@ -50,9 +48,7 @@ export class AniListAdvancedSearchForm extends AdvancedSearchForm {
private startYears: string;
private chapterCounts: string;
private volumeCounts: string;
private adult: "" | "included" | "excluded";
private doujin: "" | "included" | "excluded";
private trackedTitles: "" | "included" | "excluded";
private flags: Record<string, "included" | "excluded">;
private tags: Record<string, "included" | "excluded">;

constructor(searchQuery: SearchQuery<SearchMetadata>) {
Expand Down Expand Up @@ -87,9 +83,7 @@ export class AniListAdvancedSearchForm extends AdvancedSearchForm {
this.startYears = meta.startYears ?? "";
this.chapterCounts = meta.chapterCounts ?? "";
this.volumeCounts = meta.volumeCounts ?? "";
this.adult = meta.adult ?? "";
this.doujin = meta.doujin ?? "";
this.trackedTitles = meta.trackedTitles ?? "";
this.flags = { ...meta.flags };
this.tags = { ...meta.tags };
}

Expand Down Expand Up @@ -202,11 +196,7 @@ export class AniListAdvancedSearchForm extends AdvancedSearchForm {
id: "flags",
header: "Flags",
layout: "list",
value: {
...(this.adult ? { adult: this.adult } : {}),
...(this.doujin ? { doujin: this.doujin } : {}),
...(this.trackedTitles ? { trackedTitles: this.trackedTitles } : {}),
},
value: this.flags,
items: [
{ id: "adult", title: "Adult" },
{ id: "doujin", title: "Doujin" },
Expand Down Expand Up @@ -286,12 +276,6 @@ export class AniListAdvancedSearchForm extends AdvancedSearchForm {
this.volumeCounts = value;
}

async handleFlagsChange(value: Record<string, "included" | "excluded">): Promise<void> {
this.adult = value.adult ?? "";
this.doujin = value.doujin ?? "";
this.trackedTitles = value.trackedTitles ?? "";
}

async handleTagsChange(value: Record<string, "included" | "excluded">): Promise<void> {
this.tags = value;
}
Expand All @@ -308,9 +292,8 @@ export class AniListAdvancedSearchForm extends AdvancedSearchForm {
if (this.startYears) result.startYears = this.startYears;
if (this.chapterCounts) result.chapterCounts = this.chapterCounts;
if (this.volumeCounts) result.volumeCounts = this.volumeCounts;
if (this.adult) result.adult = this.adult;
if (this.doujin) result.doujin = this.doujin;
if (this.trackedTitles) result.trackedTitles = this.trackedTitles;

if (Object.keys(this.flags).length > 0) result.flags = this.flags;

if (Object.keys(this.tags).length > 0) result.tags = this.tags;

Expand Down
64 changes: 37 additions & 27 deletions src/AniList/Implementations/SearchResults/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,33 +194,43 @@ export class SearchResultsImplementation
}
}

switch (meta.adult) {
case "included":
variables.isAdult = true;
break;
case "excluded":
variables.isAdult = false;
break;
}

switch (meta.doujin) {
case "included":
variables.isLicensed = false;
break;
case "excluded":
variables.isLicensed = true;
break;
}

switch (meta.trackedTitles) {
case "included":
variables.onList = true;
needsAuth = true;
break;
case "excluded":
variables.onList = false;
needsAuth = true;
break;
if (meta.flags) {
for (const [id, state] of Object.entries(meta.flags)) {
switch (id) {
case "adult":
switch (state) {
case "included":
variables.isAdult = true;
break;
case "excluded":
variables.isAdult = false;
break;
}
break;
case "doujin":
switch (state) {
case "included":
variables.isLicensed = false;
break;
case "excluded":
variables.isLicensed = true;
break;
}
break;
case "trackedTitles":
switch (state) {
case "included":
variables.onList = true;
needsAuth = true;
break;
case "excluded":
variables.onList = false;
needsAuth = true;
break;
}
break;
}
}
}

if (meta.tags) {
Expand Down
42 changes: 42 additions & 0 deletions src/AniList/Implementations/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function getItems<ResultItemType>(
queryVariables: DiscoverSectionsAndSearchVariables,
needsAuth: boolean,
metadata: number | undefined,
featured?: boolean,
): Promise<PagedResults<ResultItemType>> {
const items: ResultItemType[] = [];

Expand Down Expand Up @@ -84,12 +85,53 @@ export async function getItems<ResultItemType>(
subtitle = MediaStatus.RELEASING.label;
}

let supertitle;
Comment thread
celarye marked this conversation as resolved.
let infoItems;
if (featured) {
let author, artist;
for (const staff of searchResult.staff.edges) {
if (staff.role.startsWith("Story & Art")) {
author = staff.node.name.full;
artist = undefined;
break;
}
if (
!author &&
(staff.role.startsWith("Story") || staff.role.startsWith("Original Story"))
) {
author = staff.node.name.full;
if (author && artist) break;
}
if (staff.role.startsWith("Art")) {
artist = staff.node.name.full;
if (author && artist) break;
}
}

if (author && artist) {
supertitle = `${author}, ${artist}`;
} else if (author) {
supertitle = author;
} else if (artist) {
supertitle = artist;
}

if (searchResult.averageScore) {
infoItems = [
{ symbol: "book", text: subtitle },
{ symbol: "percent", text: `${searchResult.averageScore}` },
] as const;
}
}

items.push({
mangaId: searchResult.id.toString(),
title,
imageUrl: searchResult.coverImage.large,
contentRating,
subtitle,
supertitle,
infoItems,
} as ResultItemType);
}

Expand Down
2 changes: 1 addition & 1 deletion src/AniList/pbconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ContentRating, type ExtensionInfo, SourceIntents } from "@paperback/typ
export default {
name: "AniList",
description: "Extension that integrates with anilist.co for tracking and collection management.",
version: "1.0.0-alpha.16",
version: "1.0.0-alpha.17",
icon: "icon.png",
language: "en",
contentRating: ContentRating.EVERYONE,
Expand Down