Skip to content

Commit

Permalink
Get Files from Tor
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaSat committed Sep 20, 2022
1 parent c8fcec3 commit 1885f18
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion frontend/src/services/Native/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface ReactNativeWebView {
export interface NativeWebViewMessageHttp {
id?: number
category: 'http'
type: 'post' | 'get' | 'put' | 'delete'
type: 'post' | 'get' | 'put' | 'delete' | 'file'
path: string
headers?: object
body?: object
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/services/Native/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NativeRobosats {
}
}

public postMessage: (message: NativeWebViewMessage) => Promise<object> = (message) => {
public postMessage: (message: NativeWebViewMessage) => Promise<{[key: string]: any}> = (message) => {
this.messageCounter += 1
message.id = this.messageCounter
const json = JSON.stringify(message)
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/services/api/ApiNativeClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class ApiNativeClient implements ApiClient {
path
})
};

public fileImageUrl: (path: string) => Promise<string | undefined> = async (path) => {
const fileB64 = await window.NativeRobosats?.postMessage({
category: 'http',
type: 'file',
path
})

return `data:image/png;base64,${fileB64?.b64Data}`
};
}

export default ApiNativeClient;
12 changes: 8 additions & 4 deletions mobile/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ const App = () => {
.then((response: object) => {
injectMessage(data.id, response);
});
} else if (data.type === 'delete') {
torClient.delete(data.path, data.headers).then((response: object) => {
injectMessage(data.id, response);
});
} else if (data.type === 'file') {
torClient.request(data.path).then((response: object) => {
injectMessage(data.id, response);
});
}
} else if (data.type === 'delete') {
torClient.delete(data.path, data.headers).then((response: object) => {
injectMessage(data.id, response);
});
}
};

Expand Down
18 changes: 18 additions & 0 deletions mobile/services/Tor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ class TorClient {
});
};

public request: (path: string) => Promise<object> = async path => {
await this.startDaemon();

return new Promise<object>(async (resolve, reject) => {
try {
const response = await this.daemon
.request(`${this.baseUrl}${path}`, 'GET', '', {}, true)
.then(resp => {
resolve(resp);
});

resolve(response);
} catch (error) {
reject(error);
}
});
};

public post: (
path: string,
body: object,
Expand Down

0 comments on commit 1885f18

Please sign in to comment.