mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-07 02:21:23 +00:00
Delete Rule WIP
This commit is contained in:
1 parent
ea6f09565f
commit
ecc8fd405e
6 files changed
+181
-29
No files matched your search
@@ -357,12 +357,16 @@ class ApiConfig {
|
||||
return `${this.getScheme()}://${this.getNewApiHost()}/twitch/event_rule/create`;
|
||||
}
|
||||
|
||||
deleteTwitchEventRule(eventRuleToken: string) : string {
|
||||
return `${this.getScheme()}://${this.getNewApiHost()}/twitch/event_rule/delete/${eventRuleToken}`;
|
||||
getTwitchEventRule(eventRuleToken: string) : string {
|
||||
return `${this.getScheme()}://${this.getNewApiHost()}/twitch/event_rule/${eventRuleToken}/info`;
|
||||
}
|
||||
|
||||
editTwitchEventRule(eventRuleToken: string) : string {
|
||||
return `${this.getScheme()}://${this.getNewApiHost()}/twitch/event_rule/update/${eventRuleToken}`;
|
||||
return `${this.getScheme()}://${this.getNewApiHost()}/twitch/event_rule/${eventRuleToken}/update`;
|
||||
}
|
||||
|
||||
deleteTwitchEventRule(eventRuleToken: string) : string {
|
||||
return `${this.getScheme()}://${this.getNewApiHost()}/twitch/event_rule/${eventRuleToken}/delete`;
|
||||
}
|
||||
|
||||
obsEventsWebsocket(twitchUsername: string) : string {
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { ApiConfig } from "../../ApiConfig";
|
||||
import { EventMatchPredicate } from "./shared/EventMatchPredicate";
|
||||
import { EventResponse } from "./shared/EventResponse";
|
||||
import { TwitchEventCategory } from "./shared/TwitchEventCategory";
|
||||
|
||||
export interface GetTwitchEventRuleSuccessResponse {
|
||||
success: boolean,
|
||||
twitch_event_rule: TwitchEventRule
|
||||
}
|
||||
|
||||
export interface TwitchEventRule {
|
||||
token: string,
|
||||
event_category: TwitchEventCategory,
|
||||
event_match_predicate: EventMatchPredicate,
|
||||
event_response: EventResponse,
|
||||
user_specified_rule_order: number,
|
||||
rule_is_disabled: boolean,
|
||||
created_at: Date,
|
||||
updated_at: Date,
|
||||
}
|
||||
|
||||
export interface GetTwitchEventRuleErrorResponse {
|
||||
success: boolean,
|
||||
}
|
||||
|
||||
type GetTwitchEventRuleResponse = GetTwitchEventRuleSuccessResponse | GetTwitchEventRuleErrorResponse;
|
||||
|
||||
export function GetTwitchEventRuleIsOk(response: GetTwitchEventRuleResponse): response is GetTwitchEventRuleSuccessResponse {
|
||||
return response?.success === true;
|
||||
}
|
||||
|
||||
export function GetTwitchEventRuleIsError(response: GetTwitchEventRuleResponse): response is GetTwitchEventRuleErrorResponse {
|
||||
return response?.success === false;
|
||||
}
|
||||
|
||||
export async function GetTwitchEventRule(ruleToken: string) : Promise<GetTwitchEventRuleResponse>
|
||||
{
|
||||
const endpoint = new ApiConfig().getTwitchEventRule(ruleToken);
|
||||
|
||||
return await fetch(endpoint, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(res => {
|
||||
if (!res) {
|
||||
return { success : false }; // TODO: This loses error semantics and is deprecated
|
||||
}
|
||||
|
||||
if (res && 'success' in res) {
|
||||
return res;
|
||||
} else {
|
||||
return { success : false };
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
return { success : false };
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user