Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tnfAngel committed Dec 9, 2023
1 parent c713a03 commit c384696
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/managers/STWManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Endpoints from '../../resources/Endpoints';
import { AuthSessionStoreKey } from '../../resources/enums';
import EpicgamesAPIError from '../exceptions/EpicgamesAPIError';
import STWProfile from '../structures/stw/STWProfile';
import type STWNewsMessage from '../structures/stw/STWNewsMessage';
import STWNewsMessage from '../structures/stw/STWNewsMessage';
import type { STWWorldInfoData } from '../../resources/structs';

/**
Expand Down Expand Up @@ -87,7 +87,7 @@ class STWManager extends Base {
},
}, AuthSessionStoreKey.Fortnite);

return newsResponse;
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;

0 comments on commit c384696

Please sign in to comment.