archive.social/docs/utils/SuccessLog.md

77 wiersze
3.0 KiB
Markdown
Czysty Zwykły widok Historia

2022-11-21 18:31:31 +00:00
<a name="utils.module_SuccessLog"></a>
2022-11-21 17:30:34 +00:00
2022-11-21 18:31:31 +00:00
## SuccessLog
2022-11-22 19:08:28 +00:00
thread-keeper
2022-11-21 17:30:34 +00:00
**Author**: The Harvard Library Innovation Lab
**License**: MIT
2022-11-21 18:31:31 +00:00
* [SuccessLog](#utils.module_SuccessLog)
* [.SuccessLog](#utils.module_SuccessLog.SuccessLog)
* [new exports.SuccessLog()](#new_utils.module_SuccessLog.SuccessLog_new)
* [.filepath](#utils.module_SuccessLog.SuccessLog+filepath) : <code>string</code>
2022-11-29 20:39:08 +00:00
* [.add(identifier, why, pdfBytes)](#utils.module_SuccessLog.SuccessLog+add)
2022-11-21 18:31:31 +00:00
* [.findHashInLogs(hash)](#utils.module_SuccessLog.SuccessLog+findHashInLogs) ⇒ <code>boolean</code>
* [.reset()](#utils.module_SuccessLog.SuccessLog+reset) ⇒ <code>void</code>
2022-11-21 17:30:34 +00:00
2022-11-21 18:31:31 +00:00
<a name="utils.module_SuccessLog.SuccessLog"></a>
2022-11-21 17:30:34 +00:00
2022-11-21 18:31:31 +00:00
### SuccessLog.SuccessLog
2022-11-22 19:08:28 +00:00
Utility class for handling success logs. Keeps trace of the hashes of the PDFs that were generated.
2022-11-21 18:31:31 +00:00
**Kind**: static class of [<code>SuccessLog</code>](#utils.module_SuccessLog)
2022-11-21 17:30:34 +00:00
2022-11-21 18:31:31 +00:00
* [.SuccessLog](#utils.module_SuccessLog.SuccessLog)
* [new exports.SuccessLog()](#new_utils.module_SuccessLog.SuccessLog_new)
* [.filepath](#utils.module_SuccessLog.SuccessLog+filepath) : <code>string</code>
2022-11-29 20:39:08 +00:00
* [.add(identifier, why, pdfBytes)](#utils.module_SuccessLog.SuccessLog+add)
2022-11-21 18:31:31 +00:00
* [.findHashInLogs(hash)](#utils.module_SuccessLog.SuccessLog+findHashInLogs) ⇒ <code>boolean</code>
* [.reset()](#utils.module_SuccessLog.SuccessLog+reset) ⇒ <code>void</code>
2022-11-21 17:30:34 +00:00
2022-11-21 18:31:31 +00:00
<a name="new_utils.module_SuccessLog.SuccessLog_new"></a>
2022-11-21 17:30:34 +00:00
#### new exports.SuccessLog()
On init:
- Create log file if it doesn't exist
- Load hashes from file into `this.#hashes`.
2022-11-21 18:31:31 +00:00
<a name="utils.module_SuccessLog.SuccessLog+filepath"></a>
2022-11-21 17:30:34 +00:00
#### successLog.filepath : <code>string</code>
Complete path to `success-log.json`.
2022-11-21 18:31:31 +00:00
**Kind**: instance property of [<code>SuccessLog</code>](#utils.module_SuccessLog.SuccessLog)
<a name="utils.module_SuccessLog.SuccessLog+add"></a>
2022-11-21 17:30:34 +00:00
2022-11-29 20:39:08 +00:00
#### successLog.add(identifier, why, pdfBytes)
2022-11-21 17:30:34 +00:00
Calculates hash of a PDF an:
- Creates a success log entry
- Updates `this.#hashes` (so it doesn't need to reload from file)
2022-11-21 18:31:31 +00:00
**Kind**: instance method of [<code>SuccessLog</code>](#utils.module_SuccessLog.SuccessLog)
2022-11-21 17:30:34 +00:00
| Param | Type | Description |
| --- | --- | --- |
2022-11-29 20:39:08 +00:00
| identifier | <code>string</code> | Can be an IP or access key |
| why | <code>string</code> | Reason for creating this archive |
2022-11-21 17:30:34 +00:00
| pdfBytes | <code>Buffer</code> | Used to store a SHA512 hash of the PDF that was delivered |
2022-11-21 18:31:31 +00:00
<a name="utils.module_SuccessLog.SuccessLog+findHashInLogs"></a>
2022-11-21 17:30:34 +00:00
#### successLog.findHashInLogs(hash) ⇒ <code>boolean</code>
Checks whether or not a given hash is present in the logs.
2022-11-21 18:31:31 +00:00
**Kind**: instance method of [<code>SuccessLog</code>](#utils.module_SuccessLog.SuccessLog)
2022-11-21 17:30:34 +00:00
| Param | Type |
| --- | --- |
| hash | <code>string</code> |
2022-11-21 18:31:31 +00:00
<a name="utils.module_SuccessLog.SuccessLog+reset"></a>
2022-11-21 17:30:34 +00:00
#### successLog.reset() ⇒ <code>void</code>
Resets `success-log.json`.
Also clears `this.#hashes`.
2022-11-21 18:31:31 +00:00
**Kind**: instance method of [<code>SuccessLog</code>](#utils.module_SuccessLog.SuccessLog)