From c815d407b4c9d288f73bd9d48e4828b05a47e6c8 Mon Sep 17 00:00:00 2001 From: tnfAngel <57068341+tnfAngel@users.noreply.github.com> Date: Sat, 9 Dec 2023 21:12:25 +0000 Subject: [PATCH 1/2] Fix STW News --- resources/Endpoints.ts | 1 + src/managers/STWManager.ts | 37 ++++++++++++++-- src/structures/stw/STWNewsMessage.ts | 49 ++++++++++++--------- src/structures/stw/STWNewsMessageButton.ts | 44 +++++++++++++++++++ src/structures/stw/STWNewsMessageVideo.ts | 50 ++++++++++++++++++++++ 5 files changed, 158 insertions(+), 23 deletions(-) create mode 100644 src/structures/stw/STWNewsMessageButton.ts create mode 100644 src/structures/stw/STWNewsMessageVideo.ts diff --git a/resources/Endpoints.ts b/resources/Endpoints.ts index ea92639e..bd952636 100644 --- a/resources/Endpoints.ts +++ b/resources/Endpoints.ts @@ -46,6 +46,7 @@ export default Object.freeze({ // SAVE THE WORLD STW_WORLD_INFO: 'https://fngw-mcp-gc-livefn.ol.epicgames.com/fortnite/api/game/v2/world/info', + STW_NEWS_MOTD: 'https://prm-dialogue-public-api-prod.edea.live.use1a.on.epicgames.com/api/v1/fortnite-br/surfaces/stw-motd/target', // ACCOUNT ACCOUNT_MULTIPLE: 'https://account-public-service-prod.ol.epicgames.com/account/api/public/account', diff --git a/src/managers/STWManager.ts b/src/managers/STWManager.ts index 06a32ce1..fbbc7037 100644 --- a/src/managers/STWManager.ts +++ b/src/managers/STWManager.ts @@ -49,14 +49,45 @@ class STWManager extends Base { */ public async getNews(language = this.client.config.language): Promise { const newsResponse = await this.client.http.epicgamesRequest({ - method: 'GET', - url: `${Endpoints.BR_NEWS}/savetheworldnews?lang=${language}`, + method: 'POST', + url: Endpoints.STW_NEWS_MOTD, + data: { + accountLevel: 0, + alienArtifacts: 0, + battlepass: false, + battlepassItemsClaimed: 0, + battlepassLevel: 1, + battlepassStars: 0, + completedQuests: [], + countOfDragonBalls: 0, + country: 'DE', + dateLastPlayed: '1901-12-13T20:45:52.000Z', + dateLastPlayedArena: '1901-12-13T20:45:52.000Z', + dateLastPlayedSaveTheWorld: '2022-11-01T23:25:31.000Z', + dateLastPlayedTournament: '1901-12-13T20:45:52.000Z', + daysSinceLastSession: 44153.14098048611, + globalCash: 0, + isRestricted: true, + language, + lifetimeWins: 0, + onLogin: true, + ownsSaveTheWorld: true, + platform: 'Windows', + progressiveBackblingStage: 0, + seasonHoursPlayed: 0, + serverRegion: 'EU', + socialTags: [], + stylePoints: 0, + subscription: false, + totalHoursPlayed: 0, + unlockedPages: 1, + }, headers: { 'Accept-Language': language, }, }, AuthSessionStoreKey.Fortnite); - return newsResponse.news.messages.map((m: any) => new STWNewsMessage(this.client, m)); + return newsResponse?.contentItems.map((m: any) => new STWNewsMessage(this.client, m)); } /** diff --git a/src/structures/stw/STWNewsMessage.ts b/src/structures/stw/STWNewsMessage.ts index ce1ffc1c..d93ba81c 100644 --- a/src/structures/stw/STWNewsMessage.ts +++ b/src/structures/stw/STWNewsMessage.ts @@ -1,45 +1,51 @@ import Base from '../../Base'; import Image from '../Image'; +import STWNewsMessageButton from './STWNewsMessageButton'; import type Client from '../../Client'; /** * Represents a fortnite save the world news message */ class STWNewsMessage extends Base { + /** + * The news message's entry type + */ + public contentType: string; + /** * The news message's title */ public title: string; /** - * The news message's body + * The news message's tab title */ - public body: string; + public tabTitle: string; /** - * The news message's image + * The news message's body */ - public image: Image; + public body: string; /** - * The news message's type + * The news message's buttons */ - public type: string; + public buttons?: STWNewsMessageButton[]; /** - * The news message's adspace + * The news message's images */ - public adspace: string; + public images?: Image[]; /** - * Whether the news message is hidden + * The news message's teaser title */ - public isHidden: boolean; + public teaserTitle?: string; /** - * Whether the news message is a spotlight + * The news message's teaser image */ - public isSpotlight: boolean; + public teaserImages?: Image[]; /** * @param client The main client @@ -47,15 +53,18 @@ class STWNewsMessage extends Base { */ constructor(client: Client, data: any) { super(client); + const newsData = data.contentFields; + + this.contentType = data.contentType; + + this.title = newsData.FullScreenTitle; + this.tabTitle = newsData.FullScreenTabTitle; - this.title = data.title; - this.body = data.body; - this.image = new Image(this.client, { url: data.image }); - // eslint-disable-next-line no-underscore-dangle - this.type = data._type; - this.adspace = data.adspace; - this.isHidden = data.hidden; - this.isSpotlight = data.spotlight; + this.body = newsData.FullScreenBody; + this.buttons = newsData.Buttons?.map((b: any) => new STWNewsMessageButton(this.client, b)); + this.images = newsData.FullScreenBackground?.Image?.map((i: any) => new Image(this.client, i)); + this.teaserTitle = newsData.TeaserTitle; + this.teaserImages = newsData.TeaserBackground?.Image?.map((i: any) => new Image(this.client, i)); } } diff --git a/src/structures/stw/STWNewsMessageButton.ts b/src/structures/stw/STWNewsMessageButton.ts new file mode 100644 index 00000000..9f70b7c1 --- /dev/null +++ b/src/structures/stw/STWNewsMessageButton.ts @@ -0,0 +1,44 @@ +import Base from '../../Base'; +import STWNewsMessageVideo from './STWNewsMessageVideo'; +import type Client from '../../Client'; + +/** + * Represents a STW news message button + */ +class STWNewsMessageButton extends Base { + /** + * The button's action + */ + public action?: { + type: string; + video?: STWNewsMessageVideo; + }; + + /** + * The button's style + */ + public style: string; + + /** + * The button's style + */ + public text: string; + /** + * @param client The main client + * @param data The buttons's data + */ + constructor(client: Client, data: any) { + super(client); + + const action = data.Action; + this.action = { + // eslint-disable-next-line no-underscore-dangle + type: action._type, + video: action.video ? new STWNewsMessageVideo(client, action.video) : undefined, + }; + this.style = data.Style; + this.text = data.Text; + } +} + +export default STWNewsMessageButton; diff --git a/src/structures/stw/STWNewsMessageVideo.ts b/src/structures/stw/STWNewsMessageVideo.ts new file mode 100644 index 00000000..fe8d347b --- /dev/null +++ b/src/structures/stw/STWNewsMessageVideo.ts @@ -0,0 +1,50 @@ +import Base from '../../Base'; +import type Client from '../../Client'; + +/** + * Represents a fortnite STW news message video + */ +class STWNewsMessageVideo extends Base { + /** + * The video's id + */ + public id: string; + + /** + * Whether the video should autoplay + */ + public autoplay: boolean; + + /** + * The video's string + */ + public videoString: string; + + /** + * Whether the video has streaming enabled + */ + public streamingEnabled: boolean; + + /** + * @param client The main client + * @param data The STW news message video data + */ + constructor(client: Client, data: any) { + super(client); + + this.id = data.UID; + this.autoplay = data.Autoplay; + this.videoString = data.VideoString; + this.streamingEnabled = data.StreamingEnabled; + } + + /** + * Downloads the video + * @throws {AxiosError} + */ + public async download() { + return this.client.downloadBlurlStream(this.id); + } +} + +export default STWNewsMessageVideo; From 0d337ce4d54e74096ad693abc52f27f5bd93b108 Mon Sep 17 00:00:00 2001 From: tnfAngel <57068341+tnfAngel@users.noreply.github.com> Date: Sat, 9 Dec 2023 21:23:44 +0000 Subject: [PATCH 2/2] specify a custom payload parameter --- src/managers/STWManager.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/managers/STWManager.ts b/src/managers/STWManager.ts index fbbc7037..0e3cb67c 100644 --- a/src/managers/STWManager.ts +++ b/src/managers/STWManager.ts @@ -47,7 +47,7 @@ class STWManager extends Base { * @param language The language of the news * @throws {EpicgamesAPIError} */ - public async getNews(language = this.client.config.language): Promise { + public async getNews(language = this.client.config.language, customPayload?: any): Promise { const newsResponse = await this.client.http.epicgamesRequest({ method: 'POST', url: Endpoints.STW_NEWS_MOTD, @@ -81,6 +81,7 @@ class STWManager extends Base { subscription: false, totalHoursPlayed: 0, unlockedPages: 1, + ...customPayload, }, headers: { 'Accept-Language': language,