2024-03-28 21:42:32 +00:00
|
|
|
import TorModule from '../../lib/native/TorModule';
|
2022-09-28 12:08:16 +00:00
|
|
|
|
|
|
|
class TorClient {
|
2024-03-28 21:42:32 +00:00
|
|
|
daemon: object;
|
2022-09-28 12:08:16 +00:00
|
|
|
|
|
|
|
constructor() {
|
2024-03-28 21:42:32 +00:00
|
|
|
this.daemon = {};
|
2022-09-28 12:08:16 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 16:45:05 +00:00
|
|
|
public get: (baseUrl: string, path: string, headers: object) => Promise<object> = async (
|
|
|
|
baseUrl,
|
|
|
|
path,
|
|
|
|
headers,
|
|
|
|
) => {
|
2022-09-28 12:08:16 +00:00
|
|
|
return await new Promise<object>(async (resolve, reject) => {
|
|
|
|
try {
|
2024-03-28 21:42:32 +00:00
|
|
|
const response = await TorModule.sendRequest(
|
|
|
|
'GET',
|
|
|
|
`${baseUrl}${path}`,
|
|
|
|
JSON.stringify(headers),
|
|
|
|
'{}',
|
|
|
|
);
|
|
|
|
resolve(JSON.parse(response));
|
2022-09-28 12:08:16 +00:00
|
|
|
} catch (error) {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-11-07 16:45:05 +00:00
|
|
|
public delete: (baseUrl: string, path: string, headers: object) => Promise<object> = async (
|
|
|
|
baseUrl,
|
|
|
|
path,
|
|
|
|
headers,
|
|
|
|
) => {
|
2022-09-28 12:08:16 +00:00
|
|
|
return await new Promise<object>(async (resolve, reject) => {
|
|
|
|
try {
|
2024-03-28 21:42:32 +00:00
|
|
|
const response = await TorModule.sendRequest(
|
|
|
|
'DELETE',
|
|
|
|
`${baseUrl}${path}`,
|
|
|
|
JSON.stringify(headers),
|
|
|
|
'{}',
|
|
|
|
);
|
|
|
|
resolve(JSON.parse(response));
|
2022-09-28 12:08:16 +00:00
|
|
|
} catch (error) {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-11-07 16:45:05 +00:00
|
|
|
public request: (baseUrl: string, path: string) => Promise<object> = async (
|
|
|
|
baseUrl: string,
|
|
|
|
path,
|
|
|
|
) => {
|
2022-09-28 12:08:16 +00:00
|
|
|
return await new Promise<object>(async (resolve, reject) => {
|
|
|
|
try {
|
2024-03-28 21:42:32 +00:00
|
|
|
// const response = await this.daemon
|
|
|
|
// .request(`${baseUrl}${path}`, 'GET', '', {}, true)
|
|
|
|
// .then((resp) => {
|
|
|
|
// resolve(resp);
|
|
|
|
// });
|
|
|
|
// resolve(response);
|
2022-09-28 12:08:16 +00:00
|
|
|
} catch (error) {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-11-07 16:45:05 +00:00
|
|
|
public post: (baseUrl: string, path: string, body: object, headers: object) => Promise<object> =
|
|
|
|
async (baseUrl, path, body, headers) => {
|
|
|
|
return await new Promise<object>(async (resolve, reject) => {
|
|
|
|
try {
|
|
|
|
const json = JSON.stringify(body);
|
2024-03-28 21:42:32 +00:00
|
|
|
const response = await TorModule.sendRequest(
|
|
|
|
'POST',
|
|
|
|
`${baseUrl}${path}`,
|
|
|
|
JSON.stringify(headers),
|
|
|
|
json,
|
|
|
|
);
|
|
|
|
resolve(JSON.parse(response));
|
2022-11-07 16:45:05 +00:00
|
|
|
} catch (error) {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2022-09-28 12:08:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default TorClient;
|