-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced removed google CDN handling.
- Loading branch information
1 parent
f4584bb
commit bd434e6
Showing
4 changed files
with
29 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,54 @@ | ||
import type { BanlistInfo, Card, EnvironmentConfig } from "@/core/lib"; | ||
import { Environment } from "@/core/lib"; | ||
|
||
export class ResourceService { | ||
static readonly #YGOPRODECK_IMAGE_BASE_URL = | ||
"https://images.ygoprodeck.com/images"; | ||
static readonly #CDN_BASE_URL = | ||
"https://storage.googleapis.com/ygoprodeck.com"; | ||
static readonly #YGOPRODECK_ICON_BASE_URL = | ||
"https://images.ygoprodeck.com/images/cards/icons"; | ||
|
||
readonly #environmentConfig: EnvironmentConfig; | ||
|
||
constructor(environmentConfig: EnvironmentConfig) { | ||
this.#environmentConfig = environmentConfig; | ||
} | ||
|
||
/** | ||
* Gets the version of the card image URL that should be used. | ||
* This may include additional CDN data. | ||
* | ||
* @param initialCardImageUrl Card image URL returned from the ygoprodeck API. | ||
* @return The URL that should be used. | ||
*/ | ||
getEffectiveCardImageUrl(initialCardImageUrl: string): string { | ||
if ( | ||
this.#environmentConfig.getEnvironment() == Environment.YGOPRODECK | ||
) { | ||
return initialCardImageUrl.replace( | ||
ResourceService.#CDN_BASE_URL + "/pics_small", | ||
ResourceService.#YGOPRODECK_IMAGE_BASE_URL + "/cards_small" | ||
); | ||
} | ||
return initialCardImageUrl; | ||
} | ||
|
||
getPlaceholderCardImageUrl(): string { | ||
return this.getEffectiveCardImageUrl( | ||
`${ResourceService.#CDN_BASE_URL}/pics_small/4035199.jpg` | ||
); | ||
return "https://images.ygoprodeck.com/images/cards/4035199.jpg"; | ||
} | ||
|
||
getTypeImageUrl(card: Card): string { | ||
return `${this.#getAssetBaseUrl()}/${encodeURIComponent( | ||
card.type.name | ||
)}.jpg`; | ||
return `${ | ||
ResourceService.#YGOPRODECK_ICON_BASE_URL | ||
}/${encodeURIComponent(card.type.name)}.jpg`; | ||
} | ||
|
||
getSubTypeImageUrl(card: Card): string { | ||
return `${this.#getAssetBaseUrl()}/race/${encodeURIComponent( | ||
card.subType | ||
)}.png`; | ||
return `${ | ||
ResourceService.#YGOPRODECK_ICON_BASE_URL | ||
}/race/${encodeURIComponent(card.subType)}.png`; | ||
} | ||
|
||
getAttributeImageUrl(card: Card): string { | ||
return `${this.#getAssetBaseUrl()}/attributes/${encodeURIComponent( | ||
card.attribute! | ||
)}.jpg`; | ||
return `${ | ||
ResourceService.#YGOPRODECK_ICON_BASE_URL | ||
}/attributes/${encodeURIComponent(card.attribute!)}.jpg`; | ||
} | ||
|
||
getAtkImageUrl(): string { | ||
return `${this.#getAssetBaseUrl()}/misc/atk.png`; | ||
return `${ResourceService.#YGOPRODECK_ICON_BASE_URL}/misc/atk.png`; | ||
} | ||
|
||
getLevelImageUrl(): string { | ||
return `${this.#getAssetBaseUrl()}/misc/level.png`; | ||
return `${ResourceService.#YGOPRODECK_ICON_BASE_URL}/misc/level.png`; | ||
} | ||
|
||
getLinkMarkerImageUrl(): string { | ||
return `${this.#getAssetBaseUrl()}/linkarrows/Right.png`; | ||
return `${ | ||
ResourceService.#YGOPRODECK_ICON_BASE_URL | ||
}/linkarrows/Right.png`; | ||
} | ||
|
||
getBanStateImageUrl(card: Card, format: keyof BanlistInfo): string { | ||
return `${this.#getAssetBaseUrl()}/${encodeURIComponent( | ||
card.banlist[format].name | ||
)}.png`; | ||
} | ||
|
||
#getAssetBaseUrl(): string { | ||
return this.#environmentConfig.getEnvironment() == | ||
Environment.YGOPRODECK | ||
? `${ResourceService.#YGOPRODECK_IMAGE_BASE_URL}/cards/icons` | ||
: `${ResourceService.#CDN_BASE_URL}/assets`; | ||
return `${ | ||
ResourceService.#YGOPRODECK_ICON_BASE_URL | ||
}/${encodeURIComponent(card.banlist[format].name)}.png`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters