mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
use base64 for HTTP headers (#1795)
* use base64 for HTTP headers * fe for base64 headers Co-authored-by: Matt Hill <matthewonthemoon@gmail.com>
This commit is contained in:
@@ -47,10 +47,10 @@ pub fn db<M: Metadata>(ctx: RpcContext) -> DynMiddleware<M> {
|
|||||||
Err(dump) => serde_json::to_vec(&[dump]),
|
Err(dump) => serde_json::to_vec(&[dump]),
|
||||||
}
|
}
|
||||||
.with_kind(crate::ErrorKind::Serialization)?;
|
.with_kind(crate::ErrorKind::Serialization)?;
|
||||||
Ok::<_, Error>(
|
Ok::<_, Error>(base64::encode_config(
|
||||||
url::form_urlencoded::byte_serialize(&json)
|
&json,
|
||||||
.collect::<String>(),
|
base64::URL_SAFE,
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -60,10 +60,10 @@ pub fn db<M: Metadata>(ctx: RpcContext) -> DynMiddleware<M> {
|
|||||||
Err(e) => res.headers.append(
|
Err(e) => res.headers.append(
|
||||||
"X-Patch-Error",
|
"X-Patch-Error",
|
||||||
HeaderValue::from_str(
|
HeaderValue::from_str(
|
||||||
&url::form_urlencoded::byte_serialize(
|
&base64::encode_config(
|
||||||
e.to_string().as_bytes(),
|
&e.to_string(),
|
||||||
)
|
base64::URL_SAFE,
|
||||||
.collect::<String>(),
|
),
|
||||||
)?,
|
)?,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|||||||
1
frontend/package-lock.json
generated
1
frontend/package-lock.json
generated
@@ -23,6 +23,7 @@
|
|||||||
"@start9labs/emver": "^0.1.5",
|
"@start9labs/emver": "^0.1.5",
|
||||||
"aes-js": "^3.1.2",
|
"aes-js": "^3.1.2",
|
||||||
"ansi-to-html": "^0.7.2",
|
"ansi-to-html": "^0.7.2",
|
||||||
|
"base64-js": "^1.5.1",
|
||||||
"cbor": "npm:@jprochazk/cbor@^0.4.9",
|
"cbor": "npm:@jprochazk/cbor@^0.4.9",
|
||||||
"cbor-web": "^8.1.0",
|
"cbor-web": "^8.1.0",
|
||||||
"core-js": "^3.21.1",
|
"core-js": "^3.21.1",
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
"@start9labs/emver": "^0.1.5",
|
"@start9labs/emver": "^0.1.5",
|
||||||
"aes-js": "^3.1.2",
|
"aes-js": "^3.1.2",
|
||||||
"ansi-to-html": "^0.7.2",
|
"ansi-to-html": "^0.7.2",
|
||||||
|
"base64-js": "^1.5.1",
|
||||||
"cbor": "npm:@jprochazk/cbor@^0.4.9",
|
"cbor": "npm:@jprochazk/cbor@^0.4.9",
|
||||||
"cbor-web": "^8.1.0",
|
"cbor-web": "^8.1.0",
|
||||||
"core-js": "^3.21.1",
|
"core-js": "^3.21.1",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { AuthService } from '../auth.service'
|
|||||||
import { DOCUMENT } from '@angular/common'
|
import { DOCUMENT } from '@angular/common'
|
||||||
import { DataModel } from '../patch-db/data-model'
|
import { DataModel } from '../patch-db/data-model'
|
||||||
import { PatchDB, Update } from 'patch-db-client'
|
import { PatchDB, Update } from 'patch-db-client'
|
||||||
|
import * as Base64 from 'base64-js'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LiveApiService extends ApiService {
|
export class LiveApiService extends ApiService {
|
||||||
@@ -415,15 +416,22 @@ export class LiveApiService extends ApiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const res = await this.http.rpcRequest<T>(options)
|
const res = await this.http.rpcRequest<T>(options)
|
||||||
const encoded = res.headers.get('x-patch-updates')
|
const encodedUpdates = res.headers.get('x-patch-updates')
|
||||||
|
const encodedError = res.headers.get('x-patch-error')
|
||||||
|
|
||||||
if (encoded) {
|
if (encodedUpdates) {
|
||||||
const updates: Update<DataModel>[] = JSON.parse(
|
const decoded = new TextDecoder().decode(
|
||||||
decodeURIComponent(encoded),
|
Base64.toByteArray(encodedUpdates),
|
||||||
)
|
)
|
||||||
|
const updates: Update<DataModel>[] = JSON.parse(decoded)
|
||||||
this.patchStream$.next(updates)
|
this.patchStream$.next(updates)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (encodedError) {
|
||||||
|
const error = new TextDecoder().decode(Base64.toByteArray(encodedError))
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
|
||||||
const rpcRes = res.body
|
const rpcRes = res.body
|
||||||
|
|
||||||
if (isRpcError(rpcRes)) {
|
if (isRpcError(rpcRes)) {
|
||||||
|
|||||||
@@ -20,9 +20,6 @@
|
|||||||
"module": "es2020",
|
"module": "es2020",
|
||||||
"lib": ["es2020", "dom"],
|
"lib": ["es2020", "dom"],
|
||||||
"paths": {
|
"paths": {
|
||||||
"stream": ["./node_modules/stream-browserify"],
|
|
||||||
"crypto": ["./node_modules/crypto-browserify"],
|
|
||||||
"vm": ["./node_modules/vm-browserify"],
|
|
||||||
/* These paths are relative to each app base folder */
|
/* These paths are relative to each app base folder */
|
||||||
"@start9labs/marketplace": ["../marketplace/src/public-api"],
|
"@start9labs/marketplace": ["../marketplace/src/public-api"],
|
||||||
"@start9labs/shared": ["../shared/src/public-api"]
|
"@start9labs/shared": ["../shared/src/public-api"]
|
||||||
|
|||||||
Reference in New Issue
Block a user