Skip to content

Commit

Permalink
Fix Asura stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNetsky committed Sep 22, 2024
1 parent 23f4639 commit c5dcf38
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 39 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"@typescript-eslint/parser": "^5.57.1",
"eslint": "^7.27.0",
"eslint-plugin-modules-newline": "^0.0.6",
"simple-url": "^1.1.8",
"typescript": "^4.9.5"
},
"dependencies": {
Expand All @@ -28,6 +27,7 @@
"cheerio": "^1.0.0-rc.12",
"entities": "^4.4.0",
"nodemon": "^2.0.22",
"ts-node": "^10.2.1"
"ts-node": "^10.2.1",
"url": "^0.11.4"
}
}
79 changes: 46 additions & 33 deletions src/AsuraScans/AsuraScans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
TagSection
} from '@paperback/types'

import { parse } from 'url'

import { AsuraScansParser } from './AsuraScansParser'
import { URLBuilder } from './UrlBuilder'
import {
Expand All @@ -42,13 +44,11 @@ import {
SourceStateManager
} from '@paperback/types/lib'

import simpleUrl from 'simple-url'

const ASURASCANS_DOMAIN = 'https://asuracomic.net'
const ASURASCANS_API_DOMAIN = 'https://gg.asuracomic.net'

export const AsuraScansInfo: SourceInfo = {
version: '4.1.8',
version: '4.2.0',
name: 'AsuraScans',
description: 'Extension that pulls manga from AsuraScans',
author: 'Seyden',
Expand Down Expand Up @@ -117,26 +117,32 @@ export class AsuraScans implements ChapterProviding, HomePageSectionsProviding,
}
}

const path: any = simpleUrl.parse(request.url, true)
if (!path.protocol || path.protocol == 'http') {
path.protocol = 'https'
request.url = simpleUrl.create(path)
const urlObject = parse(request.url)

if (!urlObject.protocol || urlObject.protocol === 'http:') {
urlObject.protocol = 'https:'
request.url = urlObject.toString()
}

if (path.host.includes('localhost')) {
const url: string = await this.getBaseUrl()
path.host = simpleUrl.parse(url, true).host
request.url = simpleUrl.create(path)

if (urlObject.hostname?.includes('localhost')) {
const baseUrl = await this.getBaseUrl()
const baseHost = parse(baseUrl).host ?? ''
urlObject.host = baseHost
request.url = urlObject.toString()
}


if (isImgLink(request.url)) {
const overrideUrl: string = await this.stateManager.retrieve('Domain')
if (overrideUrl && overrideUrl != this.baseUrl) {
const basePath: any = simpleUrl.parse(this.baseUrl, true)
const overridePath: any = simpleUrl.parse(overrideUrl, true)
if (path.host.includes(basePath.host) || path.host.includes(overridePath.host)) {
path.host = overridePath.host
request.url = simpleUrl.create(path)

if (overrideUrl && overrideUrl !== this.baseUrl) {
const basePath = parse(this.baseUrl)
const overridePath = parse(overrideUrl)

if (urlObject.host?.includes(basePath.host ?? '') || urlObject.host?.includes(overridePath.host ?? '')) {
urlObject.host = overridePath.host
request.url = urlObject.toString()
}
}
}
Expand Down Expand Up @@ -260,25 +266,22 @@ export class AsuraScans implements ChapterProviding, HomePageSectionsProviding,

for (const key in this.mangaDataRequests) {
const tempRequest = this.mangaDataRequests[key]
if (tempRequest!.expires < Date.now()) {
if (tempRequest?.expires && tempRequest.expires < Date.now()) {
delete this.mangaDataRequests[key]
}
}

this.mangaDataRequests[mangaId] = {
expires: Date.now() + 5000,
data: new Promise<string>(async (resolve, reject) => {
try {
const result = await this.getMangaData(mangaId)
resolve(result)
}
catch (e) {
reject(e)
}
data: new Promise<string>((resolve, reject) => {
this.getMangaData(mangaId)
.then((result) => resolve(result))
.catch((e) => reject(e))
})
}

return this.mangaDataRequests[mangaId]!.data

return this.mangaDataRequests[mangaId]?.data

Check failure on line 284 in src/AsuraScans/AsuraScans.ts

View workflow job for this annotation

GitHub Actions / Bundle and Publish Sources (20.x)

Type 'string | undefined' is not assignable to type 'string'.
}

async getMangaSlug(mangaId: string): Promise<string> {
Expand All @@ -289,7 +292,7 @@ export class AsuraScans implements ChapterProviding, HomePageSectionsProviding,
await this.stateManager.store(`${mangaId}:slug`, link)
}

// @ts-ignore
//@ts-expect-error Force async function
async getMangaShareUrl(mangaId: string): Promise<string> {
const slug = await this.getMangaSlug(mangaId)
if (!slug) {
Expand Down Expand Up @@ -419,7 +422,7 @@ export class AsuraScans implements ChapterProviding, HomePageSectionsProviding,
.addQueryParameter('page', page.toString())

if (query?.title) {
urlBuilder = urlBuilder.addQueryParameter('name', encodeURIComponent(query?.title.replace(/[’‘´`'\-][a-z]*/g, '%') ?? ''))
urlBuilder = urlBuilder.addQueryParameter('name', encodeURIComponent(query?.title.replace(/[’‘´`'-][a-z]*/g, '%') ?? ''))
}

urlBuilder = urlBuilder
Expand Down Expand Up @@ -460,10 +463,20 @@ export class AsuraScans implements ChapterProviding, HomePageSectionsProviding,
continue
}

promises.push(new Promise(async () => {
section.section.items = await this.parser.parseHomeSection($, section, this)
sectionCallback(section.section)
}))
promises.push(
new Promise<void>((resolve) => {
this.parser.parseHomeSection($, section, this)
.then((items) => {
section.section.items = items
sectionCallback(section.section)
resolve() // Resolve once the work is done
})
.catch((error) => {
throw new Error(error)
})
})
)

}

// Make sure the function completes
Expand Down
7 changes: 3 additions & 4 deletions src/AsuraScans/AsuraScansParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {

import entities = require('entities')
import {
FilterItem,
Filters
} from './AsuraScansInterfaces'

Expand Down Expand Up @@ -44,7 +43,7 @@ export class AsuraScansParser {
await source.setMangaSlug(mangaId, `series/${slug}`)
}

const rawStatus = comicObj.comic.status.name.trim()
const rawStatus = comicObj.comic?.status?.name?.trim() ?? ''
let status
switch (rawStatus.toLowerCase()) {
case source.manga_StatusTypes.DROPPED.toLowerCase():
Expand Down Expand Up @@ -190,8 +189,8 @@ export class AsuraScansParser {
{ id: 'chapters:250', label: '+250' }
]

const createTags = (filterItems: FilterItem[], prefix: string): Tag[] => {
return filterItems.map(item => ({
const createTags = (filterItems: any, prefix: string): Tag[] => {
return filterItems.map((item: { id: any; value: any; name: any }) => ({
id: `${prefix}:${item.id ?? item.value}`, // Use `id` or `value` for `order` items
label: item.name
}))
Expand Down

0 comments on commit c5dcf38

Please sign in to comment.