Correctly configure eslint & fix general issues
This commit is contained in:
parent
3b3f66645e
commit
ca0760ccb4
13 changed files with 167 additions and 1308 deletions
|
@ -21,14 +21,14 @@ export class lazyKv {
|
|||
|
||||
async get<T>(key: string, fallback?: T): Promise<T> {
|
||||
const data = await readFile(this.path, 'utf-8');
|
||||
const json = JSON.parse(data);
|
||||
const json = JSON.parse(data) as Record<string, T>;
|
||||
|
||||
return json[key] ?? (fallback || null);
|
||||
}
|
||||
|
||||
async set<T>(key: string, value: T): Promise<void> {
|
||||
const data = await readFile(this.path, 'utf-8');
|
||||
const json = JSON.parse(data);
|
||||
const json = JSON.parse(data) as Record<string, T>;
|
||||
|
||||
json[key] = value;
|
||||
|
||||
|
@ -37,7 +37,7 @@ export class lazyKv {
|
|||
|
||||
async delete(key: string): Promise<void> {
|
||||
const data = await readFile(this.path, 'utf-8');
|
||||
const json = JSON.parse(data);
|
||||
const json = JSON.parse(data) as Record<string, unknown>;
|
||||
|
||||
delete json[key];
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ void (async () => {
|
|||
|
||||
const manga = await getManga(mangaId);
|
||||
const chapters = await getAllChapters(mangaId);
|
||||
const latestChapter = await getLatestChapter(chapters);
|
||||
const latestChapter = getLatestChapter(chapters);
|
||||
const cover = await getCover(manga);
|
||||
|
||||
if (lastChapterId !== latestChapter.id) {
|
||||
|
@ -68,6 +68,6 @@ void (async () => {
|
|||
}
|
||||
};
|
||||
|
||||
setInterval(async () => checkForUpdates(), checkInterval * 1000);
|
||||
setInterval(() => void checkForUpdates(), checkInterval * 1000);
|
||||
await checkForUpdates();
|
||||
})();
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import axios from 'axios';
|
||||
import { sleep } from '../utils/sleep';
|
||||
import { Chapter } from '../types';
|
||||
import { getUserAgent } from '../utils/user-agent';
|
||||
|
||||
export const getAllChapters = async (id: string): Promise<Chapter[]> => {
|
||||
let nextPage = false;
|
||||
let offset = 0;
|
||||
|
||||
let chapters: Chapter[] = [];
|
||||
const chapters: Chapter[] = [];
|
||||
do {
|
||||
const response = await axios.get<{
|
||||
data: Chapter[];
|
||||
|
@ -19,8 +20,7 @@ export const getAllChapters = async (id: string): Promise<Chapter[]> => {
|
|||
offset,
|
||||
},
|
||||
headers: {
|
||||
'User-Agent':
|
||||
'Personal Chapter Update Tracker (Maintained by: https://pfy.ch)',
|
||||
'User-Agent': getUserAgent(),
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -41,9 +41,7 @@ export const getAllChapters = async (id: string): Promise<Chapter[]> => {
|
|||
return chapters;
|
||||
};
|
||||
|
||||
export const getLatestChapter = async (
|
||||
chapters: Chapter[],
|
||||
): Promise<Chapter> => {
|
||||
export const getLatestChapter = (chapters: Chapter[]): Chapter => {
|
||||
let latestFoundByChapterNumber = {
|
||||
id: '',
|
||||
chapter: 0,
|
||||
|
@ -63,5 +61,5 @@ export const getLatestChapter = async (
|
|||
|
||||
return chapters.find(
|
||||
(chapter) => chapter.id === latestFoundByChapterNumber.id,
|
||||
) as Chapter;
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import axios from 'axios';
|
||||
import { Manga } from './manga';
|
||||
import { Manga } from '../types';
|
||||
import { getUserAgent } from '../utils/user-agent';
|
||||
|
||||
export const getCover = async (manga: Manga): Promise<string> => {
|
||||
const coverId = Object.values(manga.relationships).find(
|
||||
|
@ -10,15 +11,13 @@ export const getCover = async (manga: Manga): Promise<string> => {
|
|||
return '';
|
||||
}
|
||||
|
||||
const response = await axios.get(
|
||||
`https://api.mangadex.org/cover/${coverId}`,
|
||||
{
|
||||
headers: {
|
||||
'User-Agent':
|
||||
'Personal Chapter Update Tracker (Maintained by: https://pfy.ch)',
|
||||
},
|
||||
const response = await axios.get<{
|
||||
data: { attributes: { fileName: string } };
|
||||
}>(`https://api.mangadex.org/cover/${coverId}`, {
|
||||
headers: {
|
||||
'User-Agent': getUserAgent(),
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
return `https://mangadex.org/covers/${manga.id}/${response.data.data.attributes.fileName}`;
|
||||
};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import axios from 'axios';
|
||||
import { Manga } from '../types';
|
||||
import { getUserAgent } from '../utils/user-agent';
|
||||
|
||||
export const getManga = async (id: string): Promise<Manga> => {
|
||||
const response = await axios.get<{
|
||||
|
@ -9,8 +10,7 @@ export const getManga = async (id: string): Promise<Manga> => {
|
|||
total: number;
|
||||
}>(`https://api.mangadex.org/manga/${id}`, {
|
||||
headers: {
|
||||
'User-Agent':
|
||||
'Personal Chapter Update Tracker (Maintained by: https://pfy.ch)',
|
||||
'User-Agent': getUserAgent(),
|
||||
},
|
||||
});
|
||||
|
||||
|
|
6
src/utils/user-agent.ts
Normal file
6
src/utils/user-agent.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
export const getUserAgent = () => {
|
||||
return (
|
||||
process.env.USER_AGENT ||
|
||||
'Personal Chapter Update Tracker (https://git.pfy.ch/pfych/chapter-tracker)'
|
||||
);
|
||||
};
|
|
@ -1,7 +1,6 @@
|
|||
/* eslint-disable camelcase */
|
||||
import axios from 'axios';
|
||||
import { Manga } from '../mangadex/manga';
|
||||
import { Chapter } from '../mangadex/chapters';
|
||||
import { Chapter, Manga } from '../types';
|
||||
|
||||
export const sendWebhook = async (args: {
|
||||
webhookUrl: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue