Skip to content

Commit

Permalink
interfaces -> types, listtype as type
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaengelhard committed Feb 18, 2024
1 parent 3091809 commit 97e2881
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/classes/ClassLoginSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios, { AxiosInstance } from "axios";
import { CookieJar } from "tough-cookie";
import { wrapper } from "axios-cookiejar-support";
import * as cheerio from "cheerio";
import { Login } from "../interfaces/InterfaceUserData";
import { Login } from "../types/TypesUserData";
import { axiosDefaults } from "../config/axiosDefaults";

import fs from "fs";
Expand Down
2 changes: 1 addition & 1 deletion src/classes/ClassUser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Login } from "../interfaces/InterfaceUserData";
import { Login } from "../types/TypesUserData";

/**
* Class defining information about a single user
Expand Down
2 changes: 1 addition & 1 deletion src/classes/ClassWork.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import WorkContent from "../interfaces/InterfaceWorkContent";
import { WorkContent } from "../types/TypesWorkContent";
import getWorkContent from "../utils/getWorkContent";
import getWorkInfo from "../utils/getWorkInfo";
import WorkInfo from "./ClassWorkInfo";
Expand Down
2 changes: 1 addition & 1 deletion src/classes/ClassWorkInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Relationship,
SeriesInfo,
Tag,
} from "../interfaces/InterfaceWorkInfo";
} from "../types/TypesWorkInfo";
import User from "./ClassUser";

/**
Expand Down
5 changes: 1 addition & 4 deletions src/classes/ClassWorkUserData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
WorkHistory,
WorkBookmark,
} from "../interfaces/InterfaceWorkUsersData";
import { WorkHistory, WorkBookmark } from "../types/TypesWorkUsersData";
import User from "./ClassUser";

/**
Expand Down
7 changes: 0 additions & 7 deletions src/enums/EnumWorkLists.ts

This file was deleted.

12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import WorkList from "./classes/ClassWorkList";
import WorkUserData from "./classes/ClassWorkUserData";
import { axiosDefaults } from "./config/axiosDefaults";
import { LanguageCodes } from "./config/LanguageCodes";
import { Listtype } from "./enums/EnumWorkLists";
import { Login } from "./interfaces/InterfaceUserData";
import WorkContent, { Notes, Chapter } from "./interfaces/InterfaceWorkContent";

import { Login } from "./types/TypesUserData";
import { Notes, Chapter, WorkContent } from "./types/TypesWorkContent";
import {
Fandom,
Relationship,
Expand All @@ -20,9 +20,9 @@ import {
SeriesInfo,
Collection,
ChapterInformation,
} from "./interfaces/InterfaceWorkInfo";
import { PageSpan } from "./interfaces/InterfaceWorkList";
import { WorkHistory, WorkBookmark } from "./interfaces/InterfaceWorkUsersData";
} from "./types/TypesWorkInfo";
import { Listtype, PageSpan } from "./types/TypesWorkList";
import { WorkHistory, WorkBookmark } from "./types/TypesWorkUsersData";
import getWorkContent from "./utils/getWorkContent";
import getWorkInfo, {
getArchiveWarnings,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Type that describes the two parts of login data: username and password
*/
export interface Login {
export type Login = {
username: string;
password: string;
}
};
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* WorkConten is an object containing of the {@link Notes} at the beginning and the end of the work and an array of {@link Chapter}s
*/
export default interface WorkContent {
export type WorkContent = {
notes: Notes;
chapters: Chapter[];
}
};

export interface Notes {
export type Notes = {
preNote: string;
endNote: string;
}
};

export interface Chapter {
export type Chapter = {
chapterTitle?: string;
chapterSummary?: string;
chapterNotes?: string;
chapterContent?: string | null;
}
};
40 changes: 20 additions & 20 deletions src/interfaces/InterfaceWorkInfo.ts → src/types/TypesWorkInfo.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
export interface Fandom {
export type Fandom = {
fandomName: string;
fandomLink: string | undefined;
}
};

export interface Relationship {
export type Relationship = {
relationshipName: string;
relationshipLink: string | undefined;
}
};

export interface Character {
export type Character = {
characterName: string;
characterLink: string | undefined;
}
};

export interface Rating {
export type Rating = {
ratingName: string;
ratingLink: string | undefined;
}
};

export interface ArchiveWarning {
export type ArchiveWarning = {
warningName: string;
warningLink: string | undefined;
}
};

export interface Category {
export type Category = {
categoryName: string;
categoryLink: string | undefined;
}
};

export interface Tag {
export type Tag = {
tagName: string;
tagLink: string | undefined;
}
};

export interface SeriesInfo {
export type SeriesInfo = {
seriesName: string;
seriesLink: string | undefined;
seriesPart: number;
}
};

export interface Collection {
export type Collection = {
collectionName: string;
collectionLink: string | undefined;
}
};

export interface ChapterInformation {
export type ChapterInformation = {
chaptersWritten: number;
chaptersMax: number;
}
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/**
* a span of Pages that should be parsed when fetching a list of pages. The exclude key is an array of numbers that define the pages that should be ignored
*/
export interface PageSpan {
export type PageSpan = {
start: number;
end: number;
exclude?: number[];
}
};

export type Listtype = "History" | "Bookmarks";
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Tag } from "./InterfaceWorkInfo";
import { Tag } from "./TypesWorkInfo";

export interface WorkHistory {
export type WorkHistory = {
lastVisit: Date;
timesVisited: number;
ratio: number;
wordsRead: number;
}
};

export interface WorkBookmark {
export type WorkBookmark = {
dateBookmarked: Date;
bookmarkerTags?: Tag[];
bookmarkNotes?: string;
}
};
2 changes: 1 addition & 1 deletion src/utils/getWorkContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as cheerio from "cheerio";
import axios from "axios";
import fs from "fs";

import WorkContent from "../interfaces/InterfaceWorkContent";
import { getAxiosSuccess, getParsableInfodata } from "./helpers";
import { axiosDefaults } from "../config/axiosDefaults";
import { WorkContent } from "../types/TypesWorkContent";

/**
* This function takes a work id or cheerio object, parses the data and returns an object containing the forword, afterword and each chapter
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getWorkInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Relationship,
SeriesInfo,
Tag,
} from "../interfaces/InterfaceWorkInfo";
} from "../types/TypesWorkInfo";
import User from "../classes/ClassUser";

/**
Expand Down
21 changes: 9 additions & 12 deletions src/utils/getWorkList.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AxiosInstance, AxiosResponse } from "axios";
import * as cheerio from "cheerio";

import { Login } from "../interfaces/InterfaceUserData";
import { Listtype } from "../enums/EnumWorkLists";
import { PageSpan } from "../interfaces/InterfaceWorkList";
import { Login } from "../types/TypesUserData";

import { Listtype, PageSpan } from "../types/TypesWorkList";
import {
defineParseIntString,
delay,
Expand All @@ -14,10 +14,7 @@ import {
import { axiosDefaults } from "../config/axiosDefaults";
import WorkList from "../classes/ClassWorkList";
import Work from "../classes/ClassWork";
import {
WorkBookmark,
WorkHistory,
} from "../interfaces/InterfaceWorkUsersData";
import { WorkBookmark, WorkHistory } from "../types/TypesWorkUsersData";
import User from "../classes/ClassUser";
import WorkUserData from "../classes/ClassWorkUserData";
import WorkInfo, { WorkStats } from "../classes/ClassWorkInfo";
Expand All @@ -30,7 +27,7 @@ import {
Relationship,
SeriesInfo,
Tag,
} from "../interfaces/InterfaceWorkInfo";
} from "../types/TypesWorkInfo";

import LoginSession from "../classes/ClassLoginSession";

Expand All @@ -56,10 +53,10 @@ export default async function getWorkList(

let firstUrl = "";
switch (listtype) {
case Listtype.History:
case "History":
firstUrl = `/users/${encodeURIComponent(logindata.username)}/readings`;
break;
case Listtype.Bookmarks:
case "Bookmarks":
firstUrl = `/users/${encodeURIComponent(logindata.username)}/bookmarks`;
break;
default:
Expand Down Expand Up @@ -190,11 +187,11 @@ function parseListWork(
let userHistoryData: WorkHistory | undefined;
let userBookmarkData: WorkBookmark | undefined;
switch (listtype) {
case Listtype.History:
case "History":
userHistoryData = parseHistoryWork($);
break;

case Listtype.Bookmarks:
case "Bookmarks":
userBookmarkData = parseBookmarkWork($);
break;

Expand Down

0 comments on commit 97e2881

Please sign in to comment.