Skip to content

Commit

Permalink
Download kind should be an enumarated type from TS perspective to avo…
Browse files Browse the repository at this point in the history
…id mistakes
  • Loading branch information
benoit74 committed Feb 10, 2025
1 parent 88bbeec commit 9699603
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class Downloader {
})
}

public async downloadContent(_url: string, kind: string, retry = true): Promise<{ content: Buffer | string; contentType: string; setCookie: string | null }> {
public async downloadContent(_url: string, kind: DonwloadKind, retry = true): Promise<{ content: Buffer | string; contentType: string; setCookie: string | null }> {
if (!_url) {
throw new Error(`Parameter [${_url}] is not a valid url`)
}
Expand Down Expand Up @@ -459,7 +459,7 @@ class Downloader {
return null
}

private getJSONCb = <T>(url: string, kind: string, handler: (...args: any[]) => any): void => {
private getJSONCb = <T>(url: string, kind: DonwloadKind, handler: (...args: any[]) => any): void => {
logger.info(`Getting JSON from [${url}]`)
axios
.get<T>(url, this.jsonRequestOptions)
Expand Down Expand Up @@ -527,7 +527,7 @@ class Downloader {
}
}

private getContentCb = async (url: string, kind: string, handler: any): Promise<void> => {
private getContentCb = async (url: string, kind: DonwloadKind, handler: any): Promise<void> => {
logger.info(`Downloading [${url}]`)
try {
if (this.optimisationCacheUrl && kind === 'image') {
Expand Down Expand Up @@ -645,7 +645,7 @@ class Downloader {
}
}

private backoffCall(handler: (...args: any[]) => void, url: string, kind: string, callback: (...args: any[]) => void | Promise<void>): void {
private backoffCall(handler: (...args: any[]) => void, url: string, kind: DonwloadKind, callback: (...args: any[]) => void | Promise<void>): void {
const call = backoff.call(handler, url, kind, callback)
call.setStrategy(this.backoffOptions.strategy)
call.retryIf(this.backoffOptions.retryIf)
Expand Down
4 changes: 3 additions & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ declare module 'imagemin-webp'

type DominoElement = any

type DonwloadKind = 'image' | 'json' | 'media' | 'video' | 'subtitle' | 'module' | 'css' | 'data'

type Callback = (err?: any, data?: any, extra?: any) => void
interface KVS<T> {
[key: string]: T
Expand Down Expand Up @@ -42,7 +44,7 @@ type FileDetail = {
namespace?: string
mult?: number
width?: number
kind: string
kind: DonwloadKind
}

type ArticleRedirect = {
Expand Down

0 comments on commit 9699603

Please sign in to comment.