mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-30 00:21:16 +00:00
Simplify fetch-code
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
c52d66cea7
commit
5f5fcf6824
6 changed files with 20 additions and 16 deletions
|
@ -81,25 +81,22 @@ export default defineComponent({
|
|||
})
|
||||
},
|
||||
|
||||
fetchAuthURLs(): Promise<void> {
|
||||
return fetch('config-editor/auth-urls', this.$root?.fetchOpts)
|
||||
.then((resp: Response) => this.$root?.parseResponseFromJSON(resp))
|
||||
fetchAuthURLs(): Promise<void> | undefined {
|
||||
return this.$root?.fetchJSON('config-editor/auth-urls')
|
||||
.then((data: any) => {
|
||||
this.authURLs = data
|
||||
})
|
||||
},
|
||||
|
||||
fetchBotProfile(user: string): Promise<void> {
|
||||
return fetch(`config-editor/user?user=${user}`, this.$root?.fetchOpts)
|
||||
.then((resp: Response) => this.$root?.parseResponseFromJSON(resp))
|
||||
fetchBotProfile(user: string): Promise<void> | undefined {
|
||||
return this.$root?.fetchJSON(`config-editor/user?user=${user}`)
|
||||
.then((data: any) => {
|
||||
this.botProfile = data
|
||||
})
|
||||
},
|
||||
|
||||
fetchGeneralConfig(): Promise<void> {
|
||||
return fetch('config-editor/general', this.$root?.fetchOpts)
|
||||
.then((resp: Response) => this.$root?.parseResponseFromJSON(resp))
|
||||
fetchGeneralConfig(): Promise<void> | undefined {
|
||||
return this.$root?.fetchJSON('config-editor/general')
|
||||
.then((data: any) => {
|
||||
this.generalConfig = data
|
||||
})
|
||||
|
@ -109,7 +106,7 @@ export default defineComponent({
|
|||
mounted() {
|
||||
this.fetchAuthURLs()
|
||||
this.fetchGeneralConfig()
|
||||
.then(() => this.fetchBotProfile(this.generalConfig.bot_name))
|
||||
?.then(() => this.fetchBotProfile(this.generalConfig.bot_name))
|
||||
},
|
||||
|
||||
name: 'TwitchBotEditorBotAuth',
|
||||
|
|
|
@ -31,8 +31,7 @@ export default defineComponent({
|
|||
|
||||
methods: {
|
||||
fetchRaffleCount(): void {
|
||||
fetch('raffle/', this.$root?.fetchOpts)
|
||||
.then((resp: Response) => this.$root?.parseResponseFromJSON(resp))
|
||||
this.$root?.fetchJSON('raffle/')
|
||||
.then((data: any) => {
|
||||
this.activeRaffles = data.filter((raffle: any) => raffle.status === 'active').length
|
||||
this.loading = false
|
||||
|
|
|
@ -41,8 +41,7 @@ export default defineComponent({
|
|||
|
||||
methods: {
|
||||
fetchStatus(): void {
|
||||
fetch('status/status.json?fail-status=200')
|
||||
.then((resp: Response) => resp.json())
|
||||
this.$root?.fetchJSON('status/status.json?fail-status=200')
|
||||
.then((data: any) => {
|
||||
this.status = data
|
||||
})
|
||||
|
|
|
@ -42,8 +42,7 @@ export default defineComponent({
|
|||
|
||||
methods: {
|
||||
fetchGeneralConfig(): void {
|
||||
fetch('config-editor/general', this.$root?.fetchOpts)
|
||||
.then((resp: Response) => this.$root?.parseResponseFromJSON(resp))
|
||||
this.$root?.fetchJSON('config-editor/general')
|
||||
.then((data: any) => {
|
||||
this.botScopes = data.channel_scopes[data.bot_name] || []
|
||||
this.loading = false
|
||||
|
|
2
src/global.d.ts
vendored
2
src/global.d.ts
vendored
|
@ -14,6 +14,7 @@ type EditorVars = {
|
|||
Version: string
|
||||
}
|
||||
|
||||
type FetchJSONFunction = (path: string, opts: Object = {}) => Promise<any>
|
||||
type ParseResponseFunction = (resp: Response) => Promise<any>
|
||||
type TickerRegisterFunction = (id: string, func: TimerHandler, intervalMs: number) => void
|
||||
type TickerUnregisterFunction = (id: string) => void
|
||||
|
@ -31,6 +32,7 @@ declare module '@vue/runtime-core' {
|
|||
|
||||
// On the $root
|
||||
check403: CheckAccessFunction
|
||||
fetchJSON: FetchJSONFunction
|
||||
fetchOpts: RequestInit
|
||||
parseResponseFromJSON: ParseResponseFunction
|
||||
registerTicker: TickerRegisterFunction
|
||||
|
|
|
@ -74,6 +74,14 @@ const app = createApp({
|
|||
return resp
|
||||
},
|
||||
|
||||
fetchJSON(path: string, opts: Object = {}): Promise<any> {
|
||||
return fetch(path, {
|
||||
...this.fetchOpts,
|
||||
...opts,
|
||||
})
|
||||
.then((resp: Response) => this.parseResponseFromJSON(resp))
|
||||
},
|
||||
|
||||
loadVars(): Promise<void | Response> {
|
||||
return fetch('editor/vars.json')
|
||||
.then((resp: Response) => resp.json())
|
||||
|
|
Loading…
Reference in a new issue