* add prettier

* lint-staged

* prettier

* upgrade husky
This commit is contained in:
nyagami
2024-03-23 22:00:29 +07:00
committed by GitHub
parent c22979b10f
commit 5f9a067ab9
113 changed files with 79244 additions and 50841 deletions
+51 -49
View File
@@ -1,32 +1,32 @@
import { Plugin } from "@typings/plugin";
import { fetchApi, fetchFile } from "@libs/fetch";
import { NovelStatus } from "@libs/novelStatus";
import dayjs from "dayjs";
import { Plugin } from '@typings/plugin';
import { fetchApi, fetchFile } from '@libs/fetch';
import { NovelStatus } from '@libs/novelStatus';
import dayjs from 'dayjs';
class Smakolykytl implements Plugin.PluginBase {
id = "smakolykytl";
name = "Смаколики";
site = "https://smakolykytl.site/";
version = "1.0.0";
icon = "src/uk/smakolykytl/icon.png";
id = 'smakolykytl';
name = 'Смаколики';
site = 'https://smakolykytl.site/';
version = '1.0.0';
icon = 'src/uk/smakolykytl/icon.png';
async popularNovels(
pageNo: number,
{ showLatestNovels, filters }: Plugin.PopularNovelsOptions,
): Promise<Plugin.NovelItem[]> {
const url = showLatestNovels
? "https://api.smakolykytl.site/api/user/updates"
: "https://api.smakolykytl.site/api/user/projects";
? 'https://api.smakolykytl.site/api/user/updates'
: 'https://api.smakolykytl.site/api/user/projects';
const result = await fetchApi(url);
const json = (await result.json()) as response;
const novels: Plugin.NovelItem[] = [];
(json?.projects || json?.updates)?.forEach((novel) =>
(json?.projects || json?.updates)?.forEach(novel =>
novels.push({
name: novel.title,
cover: novel.image.url,
path: "titles/" + novel.id,
path: 'titles/' + novel.id,
}),
);
@@ -34,42 +34,42 @@ class Smakolykytl implements Plugin.PluginBase {
}
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const id = novelPath.split("/").pop();
const id = novelPath.split('/').pop();
const result = await fetchApi(
"https://api.smakolykytl.site/api/user/projects/" + id,
'https://api.smakolykytl.site/api/user/projects/' + id,
);
const book = (await result.json()) as response;
const novel: Plugin.SourceNovel = {
path: novelPath,
name: book?.project?.title || "",
name: book?.project?.title || '',
cover: book?.project?.image?.url,
summary: book?.project?.description,
author: book?.project?.author,
status: book?.project?.status_translate.includes("Триває")
status: book?.project?.status_translate.includes('Триває')
? NovelStatus.Ongoing
: NovelStatus.Completed,
};
const tags = [book?.project?.genres, book?.project?.tags]
.flat()
.map((tags) => tags?.title)
.filter((tags) => tags);
.map(tags => tags?.title)
.filter(tags => tags);
if (tags.length) {
novel.genres = tags.join(", ");
novel.genres = tags.join(', ');
}
const chapters: Plugin.ChapterItem[] = [];
const res = await fetchApi(
"https://api.smakolykytl.site/api/user/projects/" + id + "/books",
'https://api.smakolykytl.site/api/user/projects/' + id + '/books',
);
const data = (await res.json()) as response;
data?.books?.forEach((volume) =>
volume?.chapters?.forEach((chapter) =>
data?.books?.forEach(volume =>
volume?.chapters?.forEach(chapter =>
chapters.push({
name: volume.title + " " + chapter.title,
path: "read/" + chapter.id,
releaseTime: dayjs(chapter.modifiedAt).format("LLL"),
name: volume.title + ' ' + chapter.title,
path: 'read/' + chapter.id,
releaseTime: dayjs(chapter.modifiedAt).format('LLL'),
chapterNumber: chapters.length + 1,
}),
),
@@ -80,33 +80,35 @@ class Smakolykytl implements Plugin.PluginBase {
}
async parseChapter(chapterPath: string): Promise<string> {
const id = chapterPath.split("/").pop();
const id = chapterPath.split('/').pop();
const result = await fetchApi(
"https://api.smakolykytl.site/api/user/chapters/" + id,
'https://api.smakolykytl.site/api/user/chapters/' + id,
);
const json = (await result.json()) as response;
const chapterRaw: HTML[] = JSON.parse(json?.chapter?.content || "[]");
const chapterRaw: HTML[] = JSON.parse(json?.chapter?.content || '[]');
const chapterText = jsonToHtml(chapterRaw);
return chapterText;
}
async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> {
const result = await fetchApi("https://api.smakolykytl.site/api/user/projects");
const result = await fetchApi(
'https://api.smakolykytl.site/api/user/projects',
);
const json = (await result.json()) as response;
const searchTitle = searchTerm.toLowerCase();
const novels: Plugin.NovelItem[] = [];
json?.projects
?.filter(
({ title, id }) =>
title.toLowerCase().includes(searchTitle) || String(id) == searchTerm,
)
?.forEach((novel) =>
?.forEach(novel =>
novels.push({
name: novel.title,
cover: novel.image.url,
path: "titles/" + novel.id,
path: 'titles/' + novel.id,
}),
);
return novels;
@@ -117,34 +119,34 @@ class Smakolykytl implements Plugin.PluginBase {
export default new Smakolykytl();
function jsonToHtml(json: HTML[], html: string = "") {
json.forEach((element) => {
function jsonToHtml(json: HTML[], html: string = '') {
json.forEach(element => {
switch (element.type) {
case "hardBreak":
html += "<br>";
case 'hardBreak':
html += '<br>';
break;
case "horizontalRule":
html += "<hr>";
case 'horizontalRule':
html += '<hr>';
break;
case "image":
case 'image':
if (element.attrs) {
const attrs = Object.entries(element.attrs)
.filter((attr) => attr?.[1])
.map((attr) => `${attr[0]}="${attr[1]}"`);
html += "<img " + attrs.join("; ") + ">";
.filter(attr => attr?.[1])
.map(attr => `${attr[0]}="${attr[1]}"`);
html += '<img ' + attrs.join('; ') + '>';
}
break;
case "paragraph":
case 'paragraph':
html +=
"<p>" +
(element.content ? jsonToHtml(element.content) : "<br>") +
"</p>";
'<p>' +
(element.content ? jsonToHtml(element.content) : '<br>') +
'</p>';
break;
case "text":
case 'text':
html += element.text;
break;
default:
html += JSON.stringify(element, null, "\t"); //maybe I missed something.
html += JSON.stringify(element, null, '\t'); //maybe I missed something.
break;
}
});