diff --git a/src/services/asyncStorage.ts b/src/services/asyncStorage.ts index 4a021b5d..e69de29b 100644 --- a/src/services/asyncStorage.ts +++ b/src/services/asyncStorage.ts @@ -1,88 +0,0 @@ -/* import _AsyncStorage from "@react-native-async-storage/async-storage" */ - -/** - * Loads a string from storage. - * - * @param key The key to fetch. - */ -/* const loadString = async function (key: string): Promise { - try { - return await _AsyncStorage.getItem(key) - } catch { - // not sure why this would fail... even reading the RN docs I'm unclear - return null - } -} */ - -/** - * Saves a string to storage. - * - * @param key The key to fetch. - * @param value The value to store. - */ -/* const saveString = async function (key: string, value: string): Promise { - try { - await _AsyncStorage.setItem(key, value) - return true - } catch { - return false - } -} */ - -/** - * Loads something from storage and runs it thru JSON.parse. - * - * @param key The key to fetch. - */ -/* const load = async function (key: string): Promise { - try { - const almostThere = await _AsyncStorage.getItem(key) - return JSON.parse(almostThere as string) - } catch { - return null - } -} */ - -/** - * Saves an object to storage. - * - * @param key The key to fetch. - * @param value The value to store. - */ -/* const save = async function (key: string, value: any): Promise { - try { - await _AsyncStorage.setItem(key, JSON.stringify(value)) - return true - } catch { - return false - } -} */ - -/** - * Removes something from storage. - * - * @param key The key to kill. - */ -/* const remove = async function (key: string): Promise { - try { - await _AsyncStorage.removeItem(key) - } catch {} -} */ - -/** - * Burn it all to the ground. - */ -/* const cleanAll = async function (): Promise { - try { - await _AsyncStorage.clear() - } catch {} -} - -export const AsyncStorage = { - loadString, - saveString, - load, - save, - remove, - cleanAll -} */ \ No newline at end of file diff --git a/src/services/torService.ts b/src/services/torService.ts index ad28115b..e69de29b 100644 --- a/src/services/torService.ts +++ b/src/services/torService.ts @@ -1,129 +0,0 @@ -// import Tor, { RequestMethod, TorType } from 'react-native-tor' -import AppError, { Err } from '../utils/AppError'; -import { log } from './logService'; - -/* let _tor: TorType -let _globalRequestOptions: Partial = {}; - -const getInstance = function () { - if (!_tor) { - _tor = Tor() - log.trace('Tor initialized') - } - - return _tor -} - -type RequestArgs = { - endpoint: string; - requestBody?: Record; - headers?: Record; - method?: string | RequestMethod, -}; - -type RequestOptions = RequestArgs & Omit; - - -const setGlobalRequestOptions = function (options: Partial): void { - _globalRequestOptions = options; -} - -const _request = async function({ - endpoint, - requestBody, - headers: requestHeaders, - method: requestMethod, - ...options -}: RequestOptions): Promise { - - const tor = getInstance() - - log.trace('[_request]', 'Starting tor if not yet running') - await tor.startIfNotStarted() - log.trace('_request', 'Tor daemon started') - - const body = requestBody ? JSON.stringify(requestBody) : undefined; - const method = requestMethod ? requestMethod : RequestMethod.GET - const headers = { - ...{ Accept: 'application/json, text/plain' }, - ...(body ? { 'Content-Type': 'application/json' } : undefined), - ...requestHeaders - }; - - switch (method.toLowerCase()) { - case RequestMethod.GET: - log.trace('[GET] tor request', {endpoint}) - const getResult = await tor.get(endpoint, headers, true); - if (getResult.json) { - log.trace('[GET] tor response', {response: getResult.json}) - return getResult.json; - } - break; - case RequestMethod.POST: - log.trace('[POST] tor request', {endpoint}) - const postResult = await tor.post( - endpoint, - body || '', - headers, - true - ); - if (postResult.json) { - log.trace('[POST] tor response', {response: postResult.json}) - return postResult.json; - } - break; - case RequestMethod.DELETE: - const deleteResult = await tor.delete(endpoint, body, headers, true); - if (deleteResult.json) { - return deleteResult.json; - } - break; - } - - throw new AppError(Err.VALIDATION_ERROR, 'Invalid method', {method}) -} - -const torRequest = async function(options: RequestOptions): Promise { - const response = await _request({ ...options, ..._globalRequestOptions }); - checkResponse(response); - return response as T; -} - - -const start = async () => { - const tor = getInstance() - await tor.startIfNotStarted() -} - - -const stop = async () => { - const tor = getInstance() - await tor.stopIfRunning() -} - - -const getStatus = async () => { - const tor = getInstance() - const status = await tor.getDaemonStatus() - return status -} - - -const checkResponse = function(data: any) { - if (!isObj(data)) { - throw new AppError(Err.VALIDATION_ERROR, 'Invalid data', {data}) - } -} - -const isObj = function(v: unknown): v is object { - return typeof v === 'object'; -} - -export const TorDaemon = { - start, - stop, - getStatus, - getInstance, - torRequest, - setGlobalRequestOptions, -} */ \ No newline at end of file