Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix STW News #747

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/Endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
40 changes: 36 additions & 4 deletions src/managers/STWManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,48 @@ class STWManager extends Base {
* @param language The language of the news
* @throws {EpicgamesAPIError}
*/
public async getNews(language = this.client.config.language): Promise<STWNewsMessage[]> {
public async getNews(language = this.client.config.language, customPayload?: any): Promise<STWNewsMessage[]> {
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,
...customPayload,
},
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));
}

/**
Expand Down
49 changes: 29 additions & 20 deletions src/structures/stw/STWNewsMessage.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,70 @@
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
* @param data The news message data
*/
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));
}
}

Expand Down
44 changes: 44 additions & 0 deletions src/structures/stw/STWNewsMessageButton.ts
Original file line number Diff line number Diff line change
@@ -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;
50 changes: 50 additions & 0 deletions src/structures/stw/STWNewsMessageVideo.ts
Original file line number Diff line number Diff line change
@@ -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;
Loading