diff options
author | Volpeon <git@volpeon.ink> | 2021-10-19 21:32:39 +0200 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2021-10-19 21:32:39 +0200 |
commit | b5a0a0c57b9a63e5b33b5a65a5390012d54987f8 (patch) | |
tree | 546a8e43e0e625028007c38101acf681d4f85a81 /src/services | |
parent | Throw error if db fails to load (diff) | |
download | feralbot-b5a0a0c57b9a63e5b33b5a65a5390012d54987f8.tar.gz feralbot-b5a0a0c57b9a63e5b33b5a65a5390012d54987f8.tar.bz2 feralbot-b5a0a0c57b9a63e5b33b5a65a5390012d54987f8.zip |
Fix JSON parsing
Diffstat (limited to 'src/services')
-rw-r--r-- | src/services/postDatabase.ts | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/services/postDatabase.ts b/src/services/postDatabase.ts index a782af8..0fa741b 100644 --- a/src/services/postDatabase.ts +++ b/src/services/postDatabase.ts | |||
@@ -36,7 +36,12 @@ export class PostDatabase { | |||
36 | } | 36 | } |
37 | 37 | ||
38 | const fileContent = await fs.readFile(this.filePath, "utf8"); | 38 | const fileContent = await fs.readFile(this.filePath, "utf8"); |
39 | const entries = t.array(PostDatabaseEntryC).decode(fileContent); | 39 | const entries = f.function.pipe( |
40 | fileContent, | ||
41 | f.json.parse, | ||
42 | f.either.mapLeft(() => []), | ||
43 | f.either.chain(t.array(PostDatabaseEntryC).decode) | ||
44 | ); | ||
40 | 45 | ||
41 | if (f.either.isRight(entries)) { | 46 | if (f.either.isRight(entries)) { |
42 | this.entries = this.max ? entries.right.slice(-1 * this.max) : entries.right; | 47 | this.entries = this.max ? entries.right.slice(-1 * this.max) : entries.right; |