diff --git a/frontend/projects/ui/src/app/pages/server-routes/sideload/sideload.page.ts b/frontend/projects/ui/src/app/pages/server-routes/sideload/sideload.page.ts index 10b3ea827..baaf5a9ec 100644 --- a/frontend/projects/ui/src/app/pages/server-routes/sideload/sideload.page.ts +++ b/frontend/projects/ui/src/app/pages/server-routes/sideload/sideload.page.ts @@ -95,8 +95,9 @@ export class SideloadPage { manifest: this.toUpload.manifest!, icon: this.toUpload.icon!, }) - const buffer = await blobToBuffer(this.toUpload.file!) - this.api.uploadPackage(guid, buffer).catch(e => console.error(e)) + this.api + .uploadPackage(guid, this.toUpload.file!) + .catch(e => console.error(e)) this.navCtrl.navigateRoot('/services') } catch (e: any) { @@ -190,20 +191,24 @@ async function readBlobAsDataURL( } async function blobToDataURL(data: Blob | File): Promise { const res = await readBlobAsDataURL(data) - if (res instanceof ArrayBuffer) + if (res instanceof ArrayBuffer) { throw new Error('readBlobAsDataURL response should not be an array buffer') - if (res == null) + } + if (res == null) { throw new Error('readBlobAsDataURL response should not be null') + } if (typeof res === 'string') return res throw new Error('no possible blob to data url resolution found') } async function blobToBuffer(data: Blob | File): Promise { const res = await readBlobToArrayBuffer(data) - if (res instanceof String) + if (res instanceof String) { throw new Error('readBlobToArrayBuffer response should not be a string') - if (res == null) + } + if (res == null) { throw new Error('readBlobToArrayBuffer response should not be null') + } if (res instanceof ArrayBuffer) return res throw new Error('no possible blob to array buffer resolution found') } diff --git a/frontend/projects/ui/src/app/services/api/embassy-api.service.ts b/frontend/projects/ui/src/app/services/api/embassy-api.service.ts index 7e2645ca2..c37fcc716 100644 --- a/frontend/projects/ui/src/app/services/api/embassy-api.service.ts +++ b/frontend/projects/ui/src/app/services/api/embassy-api.service.ts @@ -1,6 +1,6 @@ import { BehaviorSubject, Observable } from 'rxjs' import { Update } from 'patch-db-client' -import { RR, Encrypted } from './api.types' +import { Encrypted, RR } from './api.types' import { DataModel } from 'src/app/services/patch-db/data-model' import { Log } from '@start9labs/shared' import { WebSocketSubjectConfig } from 'rxjs/webSocket' @@ -30,7 +30,7 @@ export abstract class ApiService { abstract getStatic(url: string): Promise // for sideloading packages - abstract uploadPackage(guid: string, body: ArrayBuffer): Promise + abstract uploadPackage(guid: string, body: Blob): Promise // db diff --git a/frontend/projects/ui/src/app/services/api/embassy-live-api.service.ts b/frontend/projects/ui/src/app/services/api/embassy-live-api.service.ts index cc17cc65b..3ad146c69 100644 --- a/frontend/projects/ui/src/app/services/api/embassy-live-api.service.ts +++ b/frontend/projects/ui/src/app/services/api/embassy-live-api.service.ts @@ -44,7 +44,7 @@ export class LiveApiService extends ApiService { } // for sideloading packages - async uploadPackage(guid: string, body: ArrayBuffer): Promise { + async uploadPackage(guid: string, body: Blob): Promise { return this.httpRequest({ method: Method.POST, body, diff --git a/frontend/projects/ui/src/app/services/api/embassy-mock-api.service.ts b/frontend/projects/ui/src/app/services/api/embassy-mock-api.service.ts index ff0ba1f7f..db7810d28 100644 --- a/frontend/projects/ui/src/app/services/api/embassy-mock-api.service.ts +++ b/frontend/projects/ui/src/app/services/api/embassy-mock-api.service.ts @@ -1,12 +1,12 @@ import { Injectable } from '@angular/core' -import { pauseFor, Log } from '@start9labs/shared' +import { Log, pauseFor } from '@start9labs/shared' import { ApiService } from './embassy-api.service' import { - PatchOp, - Update, Operation, - RemoveOperation, + PatchOp, pathFromArray, + RemoveOperation, + Update, } from 'patch-db-client' import { DataModel, @@ -87,7 +87,7 @@ export class MockApiService extends ApiService { return markdown } - async uploadPackage(guid: string, body: ArrayBuffer): Promise { + async uploadPackage(guid: string, body: Blob): Promise { await pauseFor(2000) return 'success' }