Skip to content

Commit 258dbda

Browse files
authored
Merge pull request #31 from NeoScript/encode_decode_utf8
Update the encoding and decoding to use utf-8
2 parents 17a4d60 + d49de7f commit 258dbda

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

webapp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webapp",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve",

webapp/src/app/components/projects/projects.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ export class ProjectsComponent implements OnInit {
5151
handlePublishRequest(event: { topic: Topic, message: string, attributes: { [key: string]: string } }) {
5252
console.log("publish message request:", event.message)
5353

54+
const encoder = new TextEncoder()
55+
const encoded = btoa(String.fromCharCode(...encoder.encode(event.message)))
5456
const pubsubMessage: PubsubMessage = {
55-
data: btoa(event.message),
57+
data: encoded,
5658
attributes: event.attributes
5759
}
5860

webapp/src/app/components/subscription-details/subscription-details.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ <h3>Subscription Details</h3>
3737
}
3838
</div>
3939
</div>
40-
}
40+
}

webapp/src/app/components/subscription-details/subscription-details.component.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AsyncPipe, DatePipe, JsonPipe } from '@angular/common';
55
import { MatButton } from '@angular/material/button';
66
import { MatIcon } from '@angular/material/icon';
77
import { MatSuffix } from '@angular/material/form-field';
8+
import { StringDecoder } from 'string_decoder';
89

910
@Component({
1011
selector: 'app-subscription-details',
@@ -39,11 +40,11 @@ export class SubscriptionDetailsComponent implements OnInit {
3940
})
4041
}
4142

42-
convertMessageData(b64data: string) {
43-
console.log('doing translation on ', b64data)
44-
const result = atob(b64data)
45-
console.log(b64data, " -> ", result)
46-
return result
43+
convertMessageData(encodedInput: string) {
44+
const binaryString = atob(encodedInput);
45+
const uint8Array = new Uint8Array([...binaryString].map(char => char.charCodeAt(0)));
46+
const decoder = new TextDecoder();
47+
return decoder.decode(uint8Array);
4748
}
4849

4950
printSomething(data: any) {

webapp/src/app/services/pubsub.service.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class PubsubService {
2424

2525
constructor() {
2626
const prevHost = localStorage.getItem("host")
27-
if(prevHost){
27+
if (prevHost) {
2828
console.log('loaded previous host', prevHost)
2929
this._currentHost$.next(prevHost)
3030
}
@@ -38,7 +38,7 @@ export class PubsubService {
3838
)
3939
}
4040

41-
setHost(hostUrl: string){
41+
setHost(hostUrl: string) {
4242
this._currentHost$.next(hostUrl)
4343

4444
localStorage.setItem("host", hostUrl)
@@ -58,7 +58,7 @@ export class PubsubService {
5858
localStorage.setItem("projects", jsonList)
5959
}
6060

61-
createTopic(projectId: string, topicId: string){
61+
createTopic(projectId: string, topicId: string) {
6262
const url = `${this._currentHost$.value}/v1/projects/${projectId}/topics/${topicId}`
6363

6464
return this.http.put<Topic>(url, {})
@@ -68,13 +68,13 @@ export class PubsubService {
6868
return this.http.get<{ topics: Topic[] }>(`${this._currentHost$.value}/v1/projects/${projectId}/topics`).pipe(map(incoming => incoming?.topics || []))
6969
}
7070

71-
createSubscription(projectId: string, request: NewSubscriptionRequest){
71+
createSubscription(projectId: string, request: NewSubscriptionRequest) {
7272
const url = `${this._currentHost$.value}/v1/projects/${projectId}/subscriptions/${request.name}`
7373

74-
return this.http.put<Subscription>(url, {topic: request.topic, pushConfig: request.pushConfig})
74+
return this.http.put<Subscription>(url, { topic: request.topic, pushConfig: request.pushConfig })
7575
}
7676

77-
deleteSubscription(subscriptionPath: string){
77+
deleteSubscription(subscriptionPath: string) {
7878
const url = `${this._currentHost$.value}/v1/${subscriptionPath}`
7979
return this.http.delete(url)
8080
}
@@ -83,8 +83,8 @@ export class PubsubService {
8383
return this.http.get<{ subscriptions?: string[] }>(`${this._currentHost$.value}/v1/projects/${projectId}/subscriptions`)
8484
.pipe(
8585
map(incoming => incoming.subscriptions), // first we pull out the subscriptions object
86-
map(subNames => subNames??[]),
87-
map(subNames => subNames.map(name => ({ name, topic: 'undefined' } as Subscription)) ) // now we convert each string to a Subscription object (idk why, I think just wanted to learn rxjs mapping...)
86+
map(subNames => subNames ?? []),
87+
map(subNames => subNames.map(name => ({ name, topic: 'undefined' } as Subscription))) // now we convert each string to a Subscription object (idk why, I think just wanted to learn rxjs mapping...)
8888
)
8989
}
9090

@@ -95,12 +95,12 @@ export class PubsubService {
9595
return this.http.get<{ subscriptions?: string[] }>(url)
9696
.pipe(
9797
map(incoming => incoming.subscriptions),
98-
map(subNames => subNames??[]),
98+
map(subNames => subNames ?? []),
9999
map(subNames => subNames.map(name => ({ name, topic: 'undefined' } as Subscription))) // now we convert each string to a Subscription object (idk why, I think just wanted to learn rxjs mapping...)
100100
)
101101
}
102102

103-
getSubscriptionDetails(subscriptionPath: string){
103+
getSubscriptionDetails(subscriptionPath: string) {
104104
const url = `${this._currentHost$.value}/v1/${subscriptionPath}`
105105
return this.http.get<Subscription>(url)
106106
}
@@ -113,14 +113,14 @@ export class PubsubService {
113113
).pipe(map(incoming => incoming.receivedMessages ?? []))
114114
}
115115

116-
ackMessage(subscriptionPath:string, ackIds: string[]){
116+
ackMessage(subscriptionPath: string, ackIds: string[]) {
117117
const url = `${this._currentHost$.value}/v1/${subscriptionPath}:acknowledge`
118-
return this.http.post(url, {ackIds})
118+
return this.http.post(url, { ackIds })
119119
}
120120

121-
publishMessages(topicPath: string, messages: PubsubMessage[]){
121+
publishMessages(topicPath: string, messages: PubsubMessage[]) {
122122
const url = `${this._currentHost$.value}/v1/${topicPath}:publish`
123-
return this.http.post<{messageIds: string[]}>(url, {messages})
123+
return this.http.post<{ messageIds: string[] }>(url, { messages })
124124
}
125125
}
126126

@@ -141,14 +141,14 @@ export interface ReceivedMessage {
141141
}
142142

143143
export interface PubsubMessage {
144-
data: string
144+
data: string
145145
attributes?: { [key: string]: string }
146146
messageId?: string
147147
publishTime?: string
148148
orderingKey?: string
149149
}
150150

151-
export interface PushConfig{
151+
export interface PushConfig {
152152
pushEndpoint: string
153-
attributes?: {[key: string]: string}
153+
attributes?: { [key: string]: string }
154154
}

0 commit comments

Comments
 (0)