mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-08 17:06:15 -08:00
feat(data-service): add fetchData method to DataService and its implementations
This commit is contained in:
1 parent
67e2c54e6f
commit
64d4d54dbe
3 files changed
+26
-3
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import { Params } from '@angular/router';
|
||||
|
||||
export abstract class DataService {
|
||||
get isElectron(): boolean {
|
||||
return !!(window && window.process && (window.process as any).type);
|
||||
@@ -11,6 +13,7 @@ export abstract class DataService {
|
||||
abstract getAppVersion(): string;
|
||||
abstract sendIpcEvent(type: string, payload?: unknown);
|
||||
abstract removeAllListeners(type: string): void;
|
||||
abstract fetchData(url: string, queryParams: Params): any;
|
||||
abstract listenOn(
|
||||
command: string,
|
||||
callback: (...args: any[]) => void
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { Params } from '@angular/router';
|
||||
import { SwUpdate } from '@angular/service-worker';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
@@ -236,4 +237,8 @@ export class PwaService extends DataService {
|
||||
getAppEnvironment(): string {
|
||||
return 'pwa';
|
||||
}
|
||||
|
||||
fetchData(url: string, queryParams: Params) {
|
||||
// not implemented
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Params } from '@angular/router';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { fetch } from '@tauri-apps/plugin-http';
|
||||
import { parse } from 'iptv-playlist-parser';
|
||||
@@ -37,7 +38,6 @@ export class TauriService extends DataService {
|
||||
payload as { url: string; params: Record<string, string> }
|
||||
);
|
||||
} else if (type === 'STALKER_REQUEST') {
|
||||
console.log('STALKER_REQUEST');
|
||||
this.fetchStalkerData(
|
||||
payload as {
|
||||
url: string;
|
||||
@@ -83,7 +83,6 @@ export class TauriService extends DataService {
|
||||
params: Record<string, string>;
|
||||
}) {
|
||||
try {
|
||||
console.log(payload);
|
||||
const url = new URL(payload.url);
|
||||
|
||||
Object.entries(payload.params).forEach(([key, value]) => {
|
||||
@@ -104,7 +103,6 @@ export class TauriService extends DataService {
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
console.log(result);
|
||||
window.postMessage({
|
||||
type: 'STALKER_RESPONSE',
|
||||
payload: result,
|
||||
@@ -203,4 +201,21 @@ export class TauriService extends DataService {
|
||||
getAppEnvironment(): string {
|
||||
return 'tauri';
|
||||
}
|
||||
|
||||
async fetchData(url: string, queryParams: Params) {
|
||||
const urlObject = new URL(url);
|
||||
Object.entries(queryParams).forEach(([key, value]) => {
|
||||
urlObject.searchParams.append(key, value);
|
||||
});
|
||||
const response = await fetch(urlObject.toString());
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Error: ${response.statusText} (Status: ${response.status})`
|
||||
);
|
||||
}
|
||||
|
||||
console.log(url, queryParams);
|
||||
const result = await response.json();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user