All files / app/service config.service.ts

80% Statements 36/45
55.55% Branches 5/9
36.36% Functions 4/11
78.04% Lines 32/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99        168x       3x           267x 267x 267x 267x 267x 267x 267x 267x 267x 267x 267x 267x 267x 267x   267x 267x 267x 267x 267x     267x         267x   267x 267x 267x 267x     267x     267x       168x                                     20x       114x                                      
import { HttpClient } from '@angular/common/http';
import { Injectable, isDevMode } from '@angular/core';
import { DateTime } from 'luxon';
import { tap } from 'rxjs/operators';
import { memo } from '../util/memo';
 
export function config(): ConfigService {
  // @ts-ignore
  return window.configService;
}
 
@Injectable({
  providedIn: 'root',
})
export class ConfigService {
  version = DateTime.now().toISO();
  title = 'Jasper';
  api = '//localhost:8081';
  electron = /electron/i.test(navigator.userAgent);
  logout = '';
  login = '';
  signup = '';
  scim = false;
  websockets = true;
  support = '+support';
  allowedSchemes = ['http:', 'https:', 'ftp:', 'tel:', 'mailto:', 'magnet:'];
  modSeals = ['seal', '+seal', 'seal', '_moderated'];
  editorSeals = ['plugin/qc'];
 
  maxPlugins = 1000;
  maxTemplates = 1000;
  maxExts = 1000;
  maxOrigins = 1000;
  fetchBatch = 50;
 
  // Debug token
  token = '';
 
  /**
   * Workaround for non-cookie based auth to scrape images before fetching.
   */
  prefetch = isDevMode();
 
  miniWidth = 380;
  mobileWidth = 740;
  tabletWidth = 948;
  hugeWidth = 1500;
 
  constructor(
    private http: HttpClient,
  ) {
    // @ts-ignore
    window.configService = this;
  }
 
  @memo
  get base() {
    return document.getElementsByTagName('base')[0].href;
  }
 
  get loginLink() {
    return this.login + '?rd=' + encodeURIComponent(''+window.location);
  }
 
  get load$() {
    return this.http.get(this.base + 'assets/config.json').pipe(
      tap((result: any) => {
        for (const k in this) {
          this[k] = result[k] || this[k];
        }
      }),
    );
  }
 
  get mini() {
    return window.innerWidth <= this.miniWidth;
  }
 
  get mobile() {
    return window.innerWidth <= this.mobileWidth;
  }
 
  get tablet() {
    return window.innerWidth <= this.tabletWidth;
  }
 
 
  get huge() {
    return window.innerWidth >= this.hugeWidth;
  }
 
  logIn() {
    if (this.login) {
      // @ts-ignore
      window.location = this.loginLink;
    }
  }
}