Skip to content

Commit

Permalink
fix(server): add missing validation
Browse files Browse the repository at this point in the history
- address lint issues
  • Loading branch information
mytlogos committed Aug 26, 2022
1 parent 6cb63a4 commit 28b21b3
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 337 deletions.
1 change: 1 addition & 0 deletions packages/core/src/database/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type ColumnType<U extends SqlPrimitive> = U extends "varchar"
? BoolColumn
: BasicColumn<U>;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function defineColumn<U extends SqlPrimitive>(type: U): ColumnType<U> {
return {
type,
Expand Down
58 changes: 1 addition & 57 deletions packages/core/src/database/schemaManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DatabaseSchema, Migration } from "./databaseTypes";
import { TableSchema } from "./tableSchema";
import { Trigger } from "./trigger";
import { delay, equalsIgnore, getElseSet } from "../tools";
import { delay, equalsIgnore } from "../tools";
import { DatabaseContext } from "./contexts/databaseContext";
import logger from "../logger";
import { EmptyPromise, Nullable } from "../types";
Expand Down Expand Up @@ -176,62 +176,6 @@ export class SchemaManager {
await context.updateDatabaseVersion(currentVersion);
logger.info("successfully migrated storage", { from: previousVersion, to: currentVersion });
}

private getShortest(previousVersion: number) {
const root: Root = {
children: [],
};
const fromVersionMap: Map<number, Node[]> = new Map();

for (const migration of this.migrations) {
const fromMigrations = getElseSet(fromVersionMap, migration.fromVersion, () => []);
fromMigrations.push({ migration, children: [], parents: [] });
}
for (const [from, value] of fromVersionMap.entries()) {
if (from === previousVersion) {
root.children.push(...value);

for (const node of value) {
node.parents.push(root);
}
}
if (from <= previousVersion) {
continue;
}
for (const node of value) {
const nodes = fromVersionMap.get(node.migration.toVersion);

if (nodes == null) {
continue;
}
node.children.push(...nodes);

for (const child of nodes) {
child.parents.push(node);
}
}
}
const currentPathMap: Map<Migration, Migration[]> = new Map();
const visited = [];
const queue: Array<Root | Node> = [root];

while (queue.length > 0) {
const firstElement: Root | Node = queue[0];
queue.splice(0, 1);

if (isNode(firstElement)) {
// TODO: 08.08.2019 implement this
}
}
}
}

function isRoot(value: any): value is Root {
return value.children && !value.migration;
}

function isNode(value: any): value is Node {
return value.children && value.migration;
}

interface Root {
Expand Down
2 changes: 1 addition & 1 deletion packages/scraper/src/externals/custom/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function traceWrap<T extends (...args: any[]) => any>(target: T): T {
const store = getStore() as undefined | TraceStore;

// no store means no tracing, so exit as light weight as possible
if (!store || !store.get("enableTrace")) {
if (!store?.get("enableTrace")) {
return target(...args);
}

Expand Down
95 changes: 0 additions & 95 deletions packages/scraper/src/externals/direct/directTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,34 +165,6 @@ export interface SearchResult {
done: boolean;
}

function searchForWords(
linkSelector: string,
medium: TocSearchMedium,
uri: string,
searchLink: (parameter: string) => string,
): (searchString: string) => Promise<SearchResult> {
return async (word: string): Promise<SearchResult> => {
const $ = await request.getCheerio({ url: searchLink(word) });

const links = $(linkSelector);

if (!links.length) {
return { done: true };
}
for (let i = 0; i < links.length; i++) {
const linkElement = links.eq(i);

const text = sanitizeString(getText(linkElement));

if (equalsIgnore(text, medium.title) || medium.synonyms.some((s) => equalsIgnore(text, s))) {
const tocLink = linkElement.attr("href") as string;
return { value: new url.URL(tocLink, uri).href, done: true };
}
}
return { done: false };
};
}

export async function searchToc(
medium: TocSearchMedium,
tocScraper: TocScraper,
Expand Down Expand Up @@ -472,10 +444,6 @@ function isUnusedPiece(value: Node): value is UnusedPiece {
return value.type === "unusedPiece";
}

function isPartPiece(value: any): value is PartPiece {
return value.episodes;
}

function isTocMetaPiece(value: any): value is TocMetaPiece {
return Number.isInteger(value.mediumType);
}
Expand Down Expand Up @@ -629,65 +597,6 @@ interface TocScrapeState {
tocMeta?: InternalToc;
}

function adjustPartialIndices(contentIndex: number, contents: InternalTocContent[], ascending: boolean): void {
const content = contents[contentIndex] as InternalTocEpisode;
const partialLimit = content.partCount;

if (partialLimit) {
const totalIndex = content.totalIndex;
const currentPartialIndex = content.partialIndex;

if (currentPartialIndex == null) {
logger.warn("partialLimit but no partialIndex for: " + stringify(content));
} else {
for (let j = contentIndex + 1; j < contents.length; j++) {
const next = contents[j];

if (!isInternalEpisode(next) || !next.match) {
continue;
}
if (next.totalIndex !== totalIndex) {
break;
}
const nextPartialIndex = currentPartialIndex + (ascending ? 1 : -1);

if (nextPartialIndex < 1 || nextPartialIndex > partialLimit) {
break;
}
if (next.partialIndex != null && next.partialIndex !== nextPartialIndex) {
logger.warn(
`trying to overwrite partialIndex on existing one with ${nextPartialIndex}: ${stringify(content)}`,
);
} else {
next.partialIndex = nextPartialIndex;
next.combiIndex = combiIndex(next);
}
}
for (let j = contentIndex - 1; j >= 0; j--) {
const previous = contents[j];

if (!isInternalEpisode(previous) || !previous.match) {
continue;
}
if (previous.totalIndex !== totalIndex) {
break;
}
const nextPartialIndex = currentPartialIndex + (ascending ? -1 : 1);

if (nextPartialIndex < 1 || nextPartialIndex > partialLimit) {
break;
}
if (previous.partialIndex != null && previous.partialIndex !== nextPartialIndex) {
logger.warn("trying to overwrite partialIndex on existing one: " + stringify(content));
} else {
previous.partialIndex = nextPartialIndex;
previous.combiIndex = combiIndex(previous);
}
}
}
}
}

function convertToTocEpisode(totalIndex: number, partialIndex: number, index: number, value: UnusedPiece) {
const episode: InternalTocEpisode = {
type: "episode",
Expand Down Expand Up @@ -809,11 +718,7 @@ function adjustTocContentsLinked(contents: TocLinkedList, state: TocScrapeState)
}
}
let minPartialIndex;
let startPiecesCount = 0;
for (const content of contents.iterate(ascending)) {
if (isUnusedPiece(content)) {
startPiecesCount++;
}
if (isInternalEpisode(content)) {
if (content.totalIndex === 0) {
minPartialIndex = content.partialIndex;
Expand Down
3 changes: 1 addition & 2 deletions packages/scraper/src/externals/direct/mangaHasuScraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ async function scrapeNews(): Promise<NewsScrapeResult> {
continue;
}
let partIndices;
let partTitle;

if (groups[2]) {
partIndices = extractIndices(groups, 2, 3, 5);
Expand All @@ -148,7 +147,7 @@ async function scrapeNews(): Promise<NewsScrapeResult> {
});
continue;
}
partTitle = `Vol. ${partIndices.combi}`;
// partTitle = `Vol. ${partIndices.combi}`;
// TODO: unused part title, should this be removed or used?
}

Expand Down
4 changes: 2 additions & 2 deletions packages/scraper/src/externals/direct/mangadexScraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface ChapterResponse {
status: string;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface ChapterTocResponse {
manga: MangaChapter;
chapter: Record<string, ChapterChapterItem>;
Expand Down Expand Up @@ -225,7 +226,6 @@ async function scrapeNews(): Promise<NewsScrapeResult> {
continue;
}
let partIndices;
let partTitle;

if (groups[2]) {
partIndices = extractIndices(groups, 2, 3, 5);
Expand All @@ -235,7 +235,7 @@ async function scrapeNews(): Promise<NewsScrapeResult> {
continue;
}

partTitle = `Vol. ${partIndices.combi}`;
// partTitle = `Vol. ${partIndices.combi}`;
// TODO: unused part title, should this be removed or used?
}
episodeNews.push({
Expand Down
Loading

0 comments on commit 28b21b3

Please sign in to comment.