Skip to content

Commit

Permalink
Fix android web
Browse files Browse the repository at this point in the history
  • Loading branch information
LDprg committed Jan 22, 2023
1 parent 0134a76 commit c6357fc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 32 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package="io.ionic.starter">

<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
78 changes: 46 additions & 32 deletions src/app/api.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Injectable} from '@angular/core';
import {Storage} from '@ionic/storage-angular';
import { CapacitorHttp } from '@capacitor/core';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -37,14 +38,15 @@ export class ApiService {
console.log('signIn');
let url = new URL(this.endpoint + '/api/auth/signin');

return fetch(url, {
return CapacitorHttp.request({
url: url.toString(),
method: 'POST',
headers: this.headers,
body: JSON.stringify({
data: JSON.stringify({
email: email,
password: password
})
}).then(res => res.json()).then(res => {
}).then(res => res.data).then(res => {
if (res.accessToken) {
this.setToken(res.accessToken);
}
Expand All @@ -56,15 +58,16 @@ export class ApiService {
console.log('register');
let url = new URL(this.endpoint + '/api/auth/signup');

return fetch(url, {
return CapacitorHttp.request({
url: url.toString(),
method: 'POST',
headers: this.headers,
body: JSON.stringify({
data: JSON.stringify({
email: email,
username: username,
password: password
})
}).then(res => res.json());
}).then(res => res.data);
}

public isLoggedIn() {
Expand All @@ -79,10 +82,11 @@ export class ApiService {
if (this.accessToken)
url.searchParams.append('accessToken', this.accessToken);

return fetch(url, {
return CapacitorHttp.request({
url: url.toString(),
method: 'GET',
headers: this.headers,
}).then(res => res.json()).then(res => {
}).then(res => res.data).then(res => {
if (res.id) {
this.id = res.id;
this.username = res.username;
Expand Down Expand Up @@ -117,20 +121,22 @@ export class ApiService {
this.username = "";
this.email = "";

return fetch(url, {
return CapacitorHttp.request({
url: url.toString(),
method: 'POST',
headers: this.headers
}).then(res => res.json());
}).then(res => res.data);
}

public searchSets(search: string, count: number = 10) {
console.log('searchSets');
let url = new URL(this.endpoint + '/api/set/search/' + search + "/" + count);

return fetch(url, {
return CapacitorHttp.request({
url:url.toString(),
method: 'GET',
headers: this.headers,
}).then(res => res.json());
}).then(res => res.data);
}

public getUserSets() {
Expand All @@ -140,10 +146,11 @@ export class ApiService {
if (this.accessToken)
url.searchParams.append('accessToken', this.accessToken);

return fetch(url, {
return CapacitorHttp.request({
url: url.toString(),
method: 'GET',
headers: this.headers,
}).then(res => res.json());
}).then(res => res.data);
}

public createSet(set: any) {
Expand All @@ -153,11 +160,12 @@ export class ApiService {
if (this.accessToken)
url.searchParams.append('accessToken', this.accessToken);

return fetch(url, {
return CapacitorHttp.request({
url: url.toString(),
method: 'POST',
headers: this.headers,
body: JSON.stringify(set)
}).then(res => res.json());
data: JSON.stringify(set)
}).then(res => res.data);
}

public updateSet(id: number, set: any) {
Expand All @@ -167,11 +175,12 @@ export class ApiService {
if (this.accessToken)
url.searchParams.append('accessToken', this.accessToken);

return fetch(url, {
return CapacitorHttp.request({
url: url.toString(),
method: 'PUT',
headers: this.headers,
body: JSON.stringify(set)
}).then(res => res.json());
data: JSON.stringify(set)
}).then(res => res.data);
}

public deleteSet(id: string) {
Expand All @@ -181,20 +190,22 @@ export class ApiService {
if (this.accessToken)
url.searchParams.append('accessToken', this.accessToken);

return fetch(url, {
return CapacitorHttp.request({
url: url.toString(),
method: 'DELETE',
headers: this.headers,
}).then(res => res.json());
}).then(res => res.data);
}

public getSet(id: string) {
console.log('getSet');
let url = new URL(this.endpoint + '/api/set/' + id);

return fetch(url, {
return CapacitorHttp.request({
url: url.toString(),
method: 'GET',
headers: this.headers,
}).then(res => res.json());
}).then(res => res.data);
}

public getUserStats(id: string) {
Expand All @@ -204,10 +215,11 @@ export class ApiService {
if (this.accessToken)
url.searchParams.append('accessToken', this.accessToken);

return fetch(url, {
return CapacitorHttp.request({
url: url.toString(),
method: 'GET',
headers: this.headers,
}).then(res => res.json());
}).then(res => res.data);
}

public updateUserStats(id: string, card: string, type: string) {
Expand All @@ -217,13 +229,14 @@ export class ApiService {
if (this.accessToken)
url.searchParams.append('accessToken', this.accessToken);

return fetch(url, {
return CapacitorHttp.request({
url: url.toString(),
method: 'PUT',
headers: this.headers,
body: JSON.stringify({
data: JSON.stringify({
type: type
})
}).then(res => res.json());
}).then(res => res.data);
}

public updateUserStared(id: string, card: string, stared: boolean) {
Expand All @@ -233,13 +246,14 @@ export class ApiService {
if (this.accessToken)
url.searchParams.append('accessToken', this.accessToken);

return fetch(url, {
return CapacitorHttp.request({
url: url.toString(),
method: 'PUT',
headers: this.headers,
body: JSON.stringify({
data: JSON.stringify({
stared: stared
})
}).then(res => res.json());
}).then(res => res.data);
}

private setToken(token: string) {
Expand Down

0 comments on commit c6357fc

Please sign in to comment.