-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding the pinned servers data.
- Loading branch information
Showing
20 changed files
with
173 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { CfxPinnedServersResponse } from "src/types/CfxPinnedServers"; | ||
export default class CfxPinnedServers { | ||
pinIfEmpty: boolean; | ||
pinnedServers: string[]; | ||
noAdServerId: string; | ||
noAdServer: { | ||
title: string; | ||
ids: string[]; | ||
}; | ||
constructor(summary: CfxPinnedServersResponse); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class CfxPinnedServers { | ||
pinIfEmpty; | ||
pinnedServers; | ||
noAdServerId; | ||
noAdServer; | ||
constructor(summary) { | ||
this.pinIfEmpty = summary.pinIfEmpty; | ||
this.pinnedServers = summary.pinnedServers; | ||
this.noAdServerId = summary.noAdServerId; | ||
this.noAdServer = summary.noAdServer; | ||
} | ||
} | ||
exports.default = CfxPinnedServers; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import CfxPinnedServers from "../models/CfxPinnedServers"; | ||
export default class CfxPinnedServersModule { | ||
static instance: CfxPinnedServersModule | null; | ||
static get(): CfxPinnedServersModule; | ||
retrieve(): Promise<CfxPinnedServers | undefined>; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const types_1 = require("../types"); | ||
const CfxPinnedServers_1 = __importDefault(require("../models/CfxPinnedServers")); | ||
const axios_1 = __importDefault(require("axios")); | ||
class CfxPinnedServersModule { | ||
static instance = null; | ||
static get() { | ||
if (this.instance === null) | ||
this.instance = new CfxPinnedServersModule(); | ||
return this.instance; | ||
} | ||
async retrieve() { | ||
try { | ||
const response = await axios_1.default.get(types_1.CFX_PINNED_SERVERS, { | ||
headers: { "User-Agent": "cfx" }, | ||
}); | ||
return new CfxPinnedServers_1.default(response.data); | ||
} | ||
catch (error) { | ||
throw new Error("Internal error occurred"); | ||
} | ||
} | ||
} | ||
exports.default = CfxPinnedServersModule; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CFX_STATUS_UNRESOLVED = exports.CFX_STATUS_COMPONENTS = exports.CFX_STATUS_SUMMARY = exports.CFX_MASTERLIST = void 0; | ||
exports.CFX_PINNED_SERVERS = exports.CFX_STATUS_UNRESOLVED = exports.CFX_STATUS_COMPONENTS = exports.CFX_STATUS_SUMMARY = exports.CFX_MASTERLIST = void 0; | ||
exports.CFX_MASTERLIST = "https://servers-frontend.fivem.net/api/servers/single/"; | ||
exports.CFX_STATUS_SUMMARY = "https://status.cfx.re/api/v2/status.json"; | ||
exports.CFX_STATUS_COMPONENTS = "https://status.cfx.re/api/v2/components.json"; | ||
exports.CFX_STATUS_UNRESOLVED = "https://status.cfx.re/api/v2/incidents/unresolved.json"; | ||
exports.CFX_PINNED_SERVERS = "https://runtime.fivem.net/pins.json"; |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface CfxPinnedServersResponse { | ||
pinIfEmpty: boolean; | ||
pinnedServers: string[]; | ||
noAdServerId: string; | ||
noAdServer: { | ||
title: string; | ||
ids: string[]; | ||
}; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { CfxPinnedServersResponse } from "src/types/CfxPinnedServers" | ||
|
||
export default class CfxPinnedServers { | ||
pinIfEmpty: boolean | ||
pinnedServers: string[] | ||
noAdServerId: string | ||
noAdServer: { | ||
title: string, | ||
ids: string[] | ||
} | ||
|
||
constructor(summary: CfxPinnedServersResponse) { | ||
this.pinIfEmpty = summary.pinIfEmpty | ||
this.pinnedServers = summary.pinnedServers | ||
this.noAdServerId = summary.noAdServerId | ||
this.noAdServer = summary.noAdServer | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { CFX_PINNED_SERVERS } from "../types" | ||
import CfxPinnedServers from "../models/CfxPinnedServers" | ||
import axios from "axios" | ||
|
||
export default class CfxPinnedServersModule { | ||
static instance: CfxPinnedServersModule | null = null | ||
|
||
static get() { | ||
if (this.instance === null) this.instance = new CfxPinnedServersModule() | ||
return this.instance | ||
} | ||
|
||
async retrieve(): Promise<CfxPinnedServers | undefined> { | ||
try { | ||
const response = await axios.get(CFX_PINNED_SERVERS, { | ||
headers: { "User-Agent": "cfx" }, | ||
}) | ||
|
||
return new CfxPinnedServers(response.data) | ||
} catch (error) { | ||
throw new Error("Internal error occurred") | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface CfxPinnedServersResponse { | ||
pinIfEmpty: boolean | ||
pinnedServers: string[] | ||
noAdServerId: string | ||
noAdServer: { | ||
title: string, | ||
ids: string[] | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import CfxPinnedServersModule from "../src/modules/CfxPinnedServers.module" | ||
import CfxPinnedServers from "../src/models/CfxPinnedServers" | ||
import { fetchPinnedServers } from "../src" | ||
|
||
describe("Tests for CfxPinnedServers module", function () { | ||
|
||
test("Default behaviour of the CfxPinnedServers.retrieve function", async function () { | ||
|
||
try { | ||
const instance = new CfxPinnedServersModule(), | ||
pinnedServers = await instance.retrieve() | ||
expect(pinnedServers).toBeInstanceOf(CfxPinnedServers) | ||
} catch (error) { | ||
// If there is a catch, it's mostly due to Cfx.re server | ||
// because the route won't take any argument. | ||
expect(error).toBeInstanceOf(Error) | ||
} | ||
}) | ||
|
||
test("Default behaviour of the fetchPinnedServers function", async function () { | ||
try { | ||
const status = await fetchPinnedServers() | ||
expect(status).toBeInstanceOf(CfxPinnedServers) | ||
} catch (error) { | ||
// If there is a catch, it's mostly due to Cfx.re server | ||
// because the route won't take any argument. | ||
expect(error).toBeInstanceOf(Error) | ||
} | ||
}) | ||
}) |
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