Commit 84218941 authored by Emiliano Balbuena's avatar Emiliano Balbuena

(chore): Remove unused service dep

1 merge request!656WIP: SSO for Pro sites
Pipeline #96021706 failed with stages
in 31 minutes and 36 seconds
import { Cookie } from '../../services/cookie';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { environment } from '../../../environments/environment';
import { Location } from '@angular/common';
import { SiteService } from '../services/site.service';
/**
* API Class
......@@ -11,11 +9,11 @@ export class MindsHttpClient {
base: string = '/';
cookie: Cookie = new Cookie();
static _(http: HttpClient, site: SiteService) {
return new MindsHttpClient(http, site);
static _(http: HttpClient) {
return new MindsHttpClient(http);
}
constructor(public http: HttpClient, protected site: SiteService) {}
constructor(public http: HttpClient) {}
/**
* Return a GET request
......
......@@ -347,7 +347,7 @@ PlotlyModule.plotlyjs = PlotlyJS;
{
provide: MindsHttpClient,
useFactory: MindsHttpClient._,
deps: [HttpClient, SiteService],
deps: [HttpClient],
},
{
provide: NSFWSelectorCreatorService,
......
......@@ -2,7 +2,6 @@ import { Cookie } from '../cookie';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { environment } from '../../../environments/environment';
import { Location } from '@angular/common';
import { SiteService } from '../../common/services/site.service';
/**
* API Class
......@@ -11,15 +10,11 @@ export class Client {
base: string = '/';
cookie: Cookie = new Cookie();
static _(http: HttpClient, location: Location, site: SiteService) {
return new Client(http, location, site);
static _(http: HttpClient, location: Location) {
return new Client(http, location);
}
constructor(
public http: HttpClient,
public location: Location,
protected site: SiteService
) {}
constructor(public http: HttpClient, public location: Location) {}
/**
* Return a GET request
......@@ -60,21 +55,23 @@ export class Client {
getRaw(endpoint: string, data: Object = {}, options: Object = {}) {
endpoint += '?' + this.buildParams(data);
return new Promise((resolve, reject) => {
this.http.get(this.base + endpoint, this.buildOptions(options)).subscribe(
res => {
return resolve(res);
},
err => {
if (err.data && !err.data()) {
return reject(err || new Error('GET error'));
}
if (err.status === 401 && err.error.loggedin === false) {
window.location.href = '/login';
this.http
.get(this.base + endpoint, this.buildOptions(options, true))
.subscribe(
res => {
return resolve(res);
},
err => {
if (err.data && !err.data()) {
return reject(err || new Error('GET error'));
}
if (err.status === 401 && err.error.loggedin === false) {
window.location.href = '/login';
return reject(err);
}
return reject(err);
}
return reject(err);
}
);
);
});
}
......@@ -122,7 +119,7 @@ export class Client {
postRaw(url: string, data: Object = {}, options: Object = {}) {
return new Promise((resolve, reject) => {
this.http
.post(url, JSON.stringify(data), this.buildOptions(options))
.post(url, JSON.stringify(data), this.buildOptions(options, true))
.subscribe(
res => {
var data: any = res;
......@@ -227,7 +224,7 @@ export class Client {
/**
* Build the options
*/
private buildOptions(options: Object) {
private buildOptions(options: Object, withCredentials: boolean = false) {
const XSRF_TOKEN = this.cookie.get('XSRF-TOKEN') || '';
const headers = {
......@@ -240,7 +237,9 @@ export class Client {
cache: true,
};
builtOptions['withCredentials'] = true;
if (withCredentials) {
builtOptions['withCredentials'] = true;
}
return Object.assign(options, builtOptions);
}
......
import { Cookie } from '../cookie';
import { HttpClient } from '@angular/common/http';
import { SiteService } from '../../common/services/site.service';
/**
* API Class
......@@ -9,11 +8,11 @@ export class Upload {
base: string = '/';
cookie: Cookie = new Cookie();
static _(http: HttpClient, site: SiteService) {
return new Upload(http, site);
static _(http: HttpClient) {
return new Upload(http);
}
constructor(public http: HttpClient, protected site: SiteService) {}
constructor(public http: HttpClient) {}
/**
* Return a POST request
......
......@@ -67,12 +67,12 @@ export const MINDS_PROVIDERS: any[] = [
{
provide: Client,
useFactory: Client._,
deps: [HttpClient, Location, SiteService],
deps: [HttpClient, Location],
},
{
provide: Upload,
useFactory: Upload._,
deps: [HttpClient, SiteService],
deps: [HttpClient],
},
{
provide: Storage,
......
Please register or to comment