mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
do not load array buffer into memory
This commit is contained in:
committed by
Aiden McClelland
parent
f29c7ba4f2
commit
fd166c4433
@@ -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<string> {
|
||||
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<ArrayBuffer> {
|
||||
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')
|
||||
}
|
||||
|
||||
@@ -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<string>
|
||||
|
||||
// for sideloading packages
|
||||
abstract uploadPackage(guid: string, body: ArrayBuffer): Promise<string>
|
||||
abstract uploadPackage(guid: string, body: Blob): Promise<string>
|
||||
|
||||
// db
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ export class LiveApiService extends ApiService {
|
||||
}
|
||||
|
||||
// for sideloading packages
|
||||
async uploadPackage(guid: string, body: ArrayBuffer): Promise<string> {
|
||||
async uploadPackage(guid: string, body: Blob): Promise<string> {
|
||||
return this.httpRequest({
|
||||
method: Method.POST,
|
||||
body,
|
||||
|
||||
@@ -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<string> {
|
||||
async uploadPackage(guid: string, body: Blob): Promise<string> {
|
||||
await pauseFor(2000)
|
||||
return 'success'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user