Do not run leveldb on content script

This commit is contained in:
projectmoon 2023-03-22 15:55:35 +01:00
parent 56dc20abff
commit ba349d96cf
3 changed files with 8 additions and 6 deletions

View File

@ -1,10 +1,14 @@
import { isStatePopulated, isStateClear, PartialStateUpdate, ExporterState, isStateAbleToRequest } from "../state";
import { Status } from '../state';
import { State } from '../state/level';
import { LevelState } from '../state/level';
import * as landsbankinn from '../landsbankinn';
import { fetchAccounts } from "../landsbankinn";
import { Actions, EnsureStateMessage, EnsureStateReply, GetAccountsReply } from './messages';
// State singleton (move to its own file if we eventually get more
// than 1 background script)
const State = new LevelState();
async function ensureDataPopulated(state: ExporterState) {
if (isStateAbleToRequest(state) && !isStatePopulated(state)) {
const accounts = await fetchAccounts(state);

View File

@ -7,7 +7,7 @@ type LevelError = Error | null | undefined;
//@ts-ignore
const errorNotFound = (err: LevelError) => err.code && err.code == 'LEVEL_NOT_FOUND';
class LevelState {
export class LevelState {
private _db = new Level('landsbankinn-exporter', { valueEncoding: 'json' });
private currentTTLHandle: number | undefined = -1;
@ -55,5 +55,3 @@ class LevelState {
return this.current;
}
}
export const State: LevelState = new LevelState();

View File

@ -2,10 +2,10 @@ How to get it working:
- [X] Landsbankinn API client for arbitrary transaction lists
- [ ] Transform raw transactions into friendlier ones (i.e. date objects)
- [X] Content script that can run all the time and puts a button somewhere (statements tab, and extension icon)
- [ ] Use config.ts to set TTL for state
- [X] Use config.ts to set TTL for state
- [ ] Background page that downloads all the shit and combines into CSV, then 'downloads' file.
- [X] Build up communication message passing to background page for downloads
- [ ] Don't run level on client.
- [X] Don't run level on client.
- [-] Investigate persistent = false + setTimeout
- [ ] Maybe can force clear state when page reloads itself?
- [X] Change ready true/false to lock state, of not updated, updating, ready