Changeset View
Changeset View
Standalone View
Standalone View
web/database/utils/db-utils.js
// @flow | // @flow | ||||
import { detect as detectBrowser } from 'detect-browser'; | import { detect as detectBrowser } from 'detect-browser'; | ||||
import { isStaff } from 'lib/shared/staff-utils.js'; | |||||
import { isDev } from 'lib/utils/dev-utils.js'; | |||||
import { DB_SUPPORTED_BROWSERS, DB_SUPPORTED_OS } from './constants.js'; | import { DB_SUPPORTED_BROWSERS, DB_SUPPORTED_OS } from './constants.js'; | ||||
import type { EmscriptenModule } from '../types/module.js'; | import type { EmscriptenModule } from '../types/module.js'; | ||||
import { type SQLiteQueryExecutor } from '../types/sqlite-query-executor.js'; | import { type SQLiteQueryExecutor } from '../types/sqlite-query-executor.js'; | ||||
const browser = detectBrowser(); | const browser = detectBrowser(); | ||||
function clearSensitiveData( | function clearSensitiveData( | ||||
dbModule: EmscriptenModule, | dbModule: EmscriptenModule, | ||||
Show All 18 Lines | function exportDatabaseContent( | ||||
dbModule: EmscriptenModule, | dbModule: EmscriptenModule, | ||||
path: string, | path: string, | ||||
): Uint8Array { | ): Uint8Array { | ||||
return dbModule.FS.readFile(path, { | return dbModule.FS.readFile(path, { | ||||
encoding: 'binary', | encoding: 'binary', | ||||
}); | }); | ||||
} | } | ||||
function isSQLiteSupported(currentLoggedInUserID: ?string): boolean { | function isSQLiteSupported(): boolean { | ||||
if (!currentLoggedInUserID) { | |||||
return false; | |||||
} | |||||
if (!isDev && (!currentLoggedInUserID || !isStaff(currentLoggedInUserID))) { | |||||
return false; | |||||
} | |||||
return ( | return ( | ||||
DB_SUPPORTED_OS.includes(browser.os) && | DB_SUPPORTED_OS.includes(browser.os) && | ||||
DB_SUPPORTED_BROWSERS.includes(browser.name) | DB_SUPPORTED_BROWSERS.includes(browser.name) | ||||
); | ); | ||||
} | } | ||||
const isDesktopSafari: boolean = | const isDesktopSafari: boolean = | ||||
browser && browser.name === 'safari' && browser.os === 'Mac OS'; | browser && browser.name === 'safari' && browser.os === 'Mac OS'; | ||||
export { | export { | ||||
isSQLiteSupported, | isSQLiteSupported, | ||||
isDesktopSafari, | isDesktopSafari, | ||||
importDatabaseContent, | importDatabaseContent, | ||||
exportDatabaseContent, | exportDatabaseContent, | ||||
clearSensitiveData, | clearSensitiveData, | ||||
}; | }; |