-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from csfloat/feature/extension-status
Adds Ping for Extension Status
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 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,51 @@ | ||
import {SimpleHandler} from './main'; | ||
import {RequestType} from './types'; | ||
import {environment} from '../../../environment'; | ||
import {HasPermissions} from './has_permissions'; | ||
import {ExtensionVersion} from './extension_version'; | ||
|
||
export interface PingExtensionStatusRequest {} | ||
|
||
export interface PingExtensionStatusResponse {} | ||
|
||
export const PingExtensionStatus = new SimpleHandler<PingExtensionStatusRequest, PingExtensionStatusResponse>( | ||
RequestType.PING_EXTENSION_STATUS, | ||
async (req) => { | ||
const steamPoweredPermissions = await HasPermissions.handleRequest( | ||
{ | ||
permissions: [], | ||
origins: ['*://*.steampowered.com/*'], | ||
}, | ||
{} | ||
); | ||
|
||
const steamCommunityPermissions = await HasPermissions.handleRequest( | ||
{ | ||
permissions: [], | ||
origins: ['*://*.steamcommunity.com/*'], | ||
}, | ||
{} | ||
); | ||
|
||
const versionResp = await ExtensionVersion.handleRequest({}, {}); | ||
|
||
const resp = await fetch(`${environment.csfloat_base_api_url}/v1/me/extension/status`, { | ||
credentials: 'include', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
steam_community_permission: steamCommunityPermissions.granted, | ||
steam_powered_permission: steamPoweredPermissions.granted, | ||
version: versionResp.version, | ||
}), | ||
}); | ||
|
||
if (resp.status !== 200) { | ||
throw new Error('invalid status'); | ||
} | ||
|
||
return resp.json() as Promise<PingExtensionStatusResponse>; | ||
} | ||
); |
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 |
---|---|---|
|
@@ -15,4 +15,5 @@ export enum RequestType { | |
TRADE_OFFER_STATUS, | ||
HAS_PERMISSIONS, | ||
PING_SETUP_EXTENSION, | ||
PING_EXTENSION_STATUS, | ||
} |
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