Skip to content

Commit

Permalink
feat: enable strictNullChecks
Browse files Browse the repository at this point in the history
feat: enable `noImplicitAny`

chore: remove sync data access

fix loading package data for affected dependencies

chore: properly get alt marketplace data

update patchdb client to allow for emit on undefined values
  • Loading branch information
waterplea authored and elvece committed Jun 18, 2022
1 parent 948fb79 commit 6b4907a
Show file tree
Hide file tree
Showing 99 changed files with 673 additions and 534 deletions.
66 changes: 40 additions & 26 deletions frontend/projects/diagnostic-ui/src/app/pages/logs/logs.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,47 @@ export class LogsPage {
scrollToBottomButton = false
isOnBottom = true

constructor (
private readonly api: ApiService,
) { }
constructor(private readonly api: ApiService) {}

ngOnInit () {
ngOnInit() {
this.getLogs()
}

async getLogs () {
async getLogs() {
try {
// get logs
const logs = await this.fetch()
if (!logs.length) return

if (!logs?.length) return

const container = document.getElementById('container')
const beforeContainerHeight = container.scrollHeight
const newLogs = document.getElementById('template').cloneNode(true) as HTMLElement
newLogs.innerHTML = logs.map(l => `${l.timestamp} ${convert.toHtml(l.message)}`).join('\n') + (logs.length ? '\n' : '')
const beforeContainerHeight = container?.scrollHeight || 0
const newLogs = document.getElementById('template')?.cloneNode(true)

if (!(newLogs instanceof HTMLElement)) return

container.prepend(newLogs)
const afterContainerHeight = container.scrollHeight
newLogs.innerHTML =
logs
.map(l => `${l.timestamp} ${convert.toHtml(l.message)}`)
.join('\n') + (logs.length ? '\n' : '')
container?.prepend(newLogs)

const afterContainerHeight = container?.scrollHeight || 0

// scroll down
scrollBy(0, afterContainerHeight - beforeContainerHeight)
this.content.scrollToPoint(0, afterContainerHeight - beforeContainerHeight)
this.content.scrollToPoint(
0,
afterContainerHeight - beforeContainerHeight,
)

if (logs.length < this.limit) {
this.needInfinite = false
}

} catch (e) { }
} catch (e) {}
}

async fetch (isBefore: boolean = true) {
async fetch(isBefore: boolean = true) {
try {
const cursor = isBefore ? this.startCursor : this.endCursor

Expand All @@ -81,33 +88,40 @@ export class LogsPage {
}
}

async loadMore () {
async loadMore() {
try {
this.loadingMore = true
const logs = await this.fetch(false)
if (!logs.length) return this.loadingMore = false

if (!logs?.length) return (this.loadingMore = false)

const container = document.getElementById('container')
const newLogs = document.getElementById('template').cloneNode(true) as HTMLElement
newLogs.innerHTML = logs.map(l => `${l.timestamp} ${convert.toHtml(l.message)}`).join('\n') + (logs.length ? '\n' : '')
container.append(newLogs)
const newLogs = document.getElementById('template')?.cloneNode(true)

if (!(newLogs instanceof HTMLElement)) return

newLogs.innerHTML =
logs
.map(l => `${l.timestamp} ${convert.toHtml(l.message)}`)
.join('\n') + (logs.length ? '\n' : '')
container?.append(newLogs)
this.loadingMore = false
this.scrollEvent()
} catch (e) { }
} catch (e) {}
}

scrollEvent () {
scrollEvent() {
const buttonDiv = document.getElementById('button-div')
this.isOnBottom = buttonDiv.getBoundingClientRect().top < window.innerHeight
this.isOnBottom =
!!buttonDiv && buttonDiv.getBoundingClientRect().top < window.innerHeight
}

scrollToBottom () {
scrollToBottom() {
this.content.scrollToBottom(500)
}

async loadData (e: any): Promise<void> {
async loadData(e: any): Promise<void> {
await this.getLogs()
e.target.complete()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@ export class MockApiService extends ApiService {

async restart(): Promise<void> {
await pauseFor(1000)
return null
}

async forgetDrive(): Promise<void> {
await pauseFor(1000)
return null
}

async repairDisk(): Promise<void> {
await pauseFor(1000)
return null
}

async getLogs(params: GetLogsReq): Promise<GetLogsRes> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core'
import { HttpClient, HttpErrorResponse } from '@angular/common/http'
import { HttpClient } from '@angular/common/http'
import { HttpError, RpcError } from '@start9labs/shared'

@Injectable({
Expand All @@ -12,6 +12,8 @@ export class HttpService {
const res = await this.httpRequest<RPCResponse<T>>(options)
if (isRpcError(res)) throw new RpcError(res.error)
if (isRpcSuccess(res)) return res.result

throw new Error('Unknown RPC response')
}

async httpRequest<T>(body: RPCOptions): Promise<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChangeDetectionStrategy, Component, ElementRef } from '@angular/core'
import { ActivatedRoute } from '@angular/router'
import { getPkgId } from '@start9labs/shared'
import { AbstractMarketplaceService } from '../../services/marketplace.service'

@Component({
Expand All @@ -9,7 +10,7 @@ import { AbstractMarketplaceService } from '../../services/marketplace.service'
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ReleaseNotesComponent {
private readonly pkgId = this.route.snapshot.paramMap.get('pkgId')
private readonly pkgId = getPkgId(this.route)

private selected: string | null = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class AdditionalComponent {
const alert = await this.alertCtrl.create({
header: 'Versions',
inputs: this.pkg.versions
.sort((a, b) => -1 * this.emver.compare(a, b))
.sort((a, b) => -1 * (this.emver.compare(a, b) || 0))
.map(v => ({
name: v, // for CSS
type: 'radio',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NgModule, Pipe, PipeTransform } from '@angular/core'
import Fuse from 'fuse.js/dist/fuse.min.js'
import Fuse from 'fuse.js'

import { MarketplacePkg } from '../types/marketplace-pkg'
import { MarketplaceManifest } from '../types/marketplace-manifest'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ export abstract class AbstractMarketplaceService {

abstract getPackageMarkdown(type: string, pkgId: string): Observable<string>

abstract getPackage(id: string, version: string): Observable<MarketplacePkg>
abstract getPackage(
id: string,
version: string,
): Observable<MarketplacePkg | null>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Component, Input, ViewChild } from '@angular/core'
import { IonInput, ModalController } from '@ionic/angular'
import { DiskInfo, CifsBackupTarget, DiskBackupTarget } from 'src/app/services/api/api.service'
import {
DiskInfo,
CifsBackupTarget,
DiskBackupTarget,
} from 'src/app/services/api/api.service'
import * as argon2 from '@start9labs/argon2'

@Component({
Expand All @@ -21,26 +25,27 @@ export class PasswordPage {
passwordVer = ''
unmasked2 = false

constructor (
private modalController: ModalController,
) { }
constructor(private modalController: ModalController) {}

ngAfterViewInit () {
ngAfterViewInit() {
setTimeout(() => this.elem.setFocus(), 400)
}

async verifyPw () {
if (!this.target || !this.target['embassy-os']) this.pwError = 'No recovery target' // unreachable
async verifyPw() {
if (!this.target || !this.target['embassy-os'])
this.pwError = 'No recovery target' // unreachable

try {
argon2.verify(this.target['embassy-os']['password-hash'], this.password)
const passwordHash = this.target['embassy-os']?.['password-hash'] || ''

argon2.verify(passwordHash, this.password)
this.modalController.dismiss({ password: this.password }, 'success')
} catch (e) {
this.pwError = 'Incorrect password provided'
}
}

async submitPw () {
async submitPw() {
this.validate()
if (this.password !== this.passwordVer) {
this.verError = '*passwords do not match'
Expand All @@ -50,8 +55,8 @@ export class PasswordPage {
this.modalController.dismiss({ password: this.password }, 'success')
}

validate () {
if (!!this.target) return this.pwError = ''
validate() {
if (!!this.target) return (this.pwError = '')

if (this.passwordVer) {
this.checkVer()
Expand All @@ -64,11 +69,12 @@ export class PasswordPage {
}
}

checkVer () {
this.verError = this.password !== this.passwordVer ? 'Passwords do not match' : ''
checkVer() {
this.verError =
this.password !== this.passwordVer ? 'Passwords do not match' : ''
}

cancel () {
cancel() {
this.modalController.dismiss()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ export class ProdKeyModal {
productKey = ''
unmasked = false

constructor (
constructor(
private readonly modalController: ModalController,
private readonly apiService: ApiService,
private readonly loadingCtrl: LoadingController,
private readonly httpService: HttpService,
) { }
) {}

ngAfterViewInit () {
ngAfterViewInit() {
setTimeout(() => this.elem.setFocus(), 400)
}

async verifyProductKey () {
if (!this.productKey) return
async verifyProductKey() {
if (!this.productKey || !this.target.logicalname) return

const loader = await this.loadingCtrl.create({
message: 'Verifying Product Key',
Expand All @@ -48,7 +48,7 @@ export class ProdKeyModal {
}
}

cancel () {
cancel() {
this.modalController.dismiss()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export class RecoverPage {
'embassy-os': p['embassy-os'],
}
this.mappedDrives.push({
hasValidBackup: p['embassy-os']?.full,
is02x: drive['embassy-os']?.version.startsWith('0.2'),
hasValidBackup: !!p['embassy-os']?.full,
is02x: !!drive['embassy-os']?.version.startsWith('0.2'),
drive,
})
})
Expand Down Expand Up @@ -111,7 +111,8 @@ export class RecoverPage {
{
text: 'Use Drive',
handler: async () => {
await this.importDrive(importableDrive.guid)
if (importableDrive.guid)
await this.importDrive(importableDrive.guid)
},
},
],
Expand Down Expand Up @@ -148,20 +149,23 @@ export class RecoverPage {
}

async select(target: DiskBackupTarget) {
const is02x = target['embassy-os'].version.startsWith('0.2')
const is02x = target['embassy-os']?.version.startsWith('0.2')
const { logicalname } = target

if (!logicalname) return

if (this.stateService.hasProductKey) {
if (is02x) {
this.selectRecoverySource(target.logicalname)
this.selectRecoverySource(logicalname)
} else {
const modal = await this.modalController.create({
component: PasswordPage,
componentProps: { target },
cssClass: 'alertlike-modal',
})
modal.onDidDismiss().then(res => {
if (res.data && res.data.password) {
this.selectRecoverySource(target.logicalname, res.data.password)
if (res.data?.password) {
this.selectRecoverySource(logicalname, res.data.password)
}
})
await modal.present()
Expand All @@ -188,8 +192,8 @@ export class RecoverPage {
cssClass: 'alertlike-modal',
})
modal.onDidDismiss().then(res => {
if (res.data && res.data.productKey) {
this.selectRecoverySource(target.logicalname)
if (res.data?.productKey) {
this.selectRecoverySource(logicalname)
}
})
await modal.present()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class SuccessPage {
await this.stateService.completeEmbassy()
document
.getElementById('install-cert')
.setAttribute(
?.setAttribute(
'href',
'data:application/x-x509-ca-cert;base64,' +
encodeURIComponent(this.stateService.cert),
Expand Down Expand Up @@ -56,20 +56,24 @@ export class SuccessPage {
}

installCert() {
document.getElementById('install-cert').click()
document.getElementById('install-cert')?.click()
}

download() {
document.getElementById('tor-addr').innerHTML = this.stateService.torAddress
document.getElementById('lan-addr').innerHTML = this.stateService.lanAddress
const torAddress = document.getElementById('tor-addr')
const lanAddress = document.getElementById('lan-addr')

if (torAddress) torAddress.innerHTML = this.stateService.torAddress
if (lanAddress) lanAddress.innerHTML = this.stateService.lanAddress

document
.getElementById('cert')
.setAttribute(
?.setAttribute(
'href',
'data:application/x-x509-ca-cert;base64,' +
encodeURIComponent(this.stateService.cert),
)
let html = document.getElementById('downloadable').innerHTML
let html = document.getElementById('downloadable')?.innerHTML || ''
const filename = 'embassy-info.html'

const elem = document.createElement('a')
Expand Down
Loading

0 comments on commit 6b4907a

Please sign in to comment.