Add JSON input (#3)
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful

Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk>
Reviewed-on: #3
This commit is contained in:
2023-09-08 18:19:06 +00:00
parent 1b1c902667
commit 3e3d092c27
35 changed files with 1407 additions and 113 deletions

View File

@@ -0,0 +1,43 @@
namespace AnkiStatic
open System
open System.Security.Cryptography
open System.Text
type Note<'Model> =
{
Guid : uint64
ModelId : 'Model
LastModified : DateTimeOffset
UpdateSequenceNumber : int
/// Serialised space-separated as a string, with a space at the start and end.
Tags : string list
/// Serialised as a string separated by the 0x1f character
Fields : string list
/// In the Sqlite table, this is an int field.
/// Sqlite is dynamically typed and accepts strings in an int field.
/// But it will sort "correctly" in the sense that integers are compared as integers
/// for the purpose of sorting in this way.
SortField : Choice<string, int>
/// Unused
Flags : int
/// Unused
Data : string
}
member this.Checksum : uint =
let fromBase256 (firstCount : int) (bytes : byte[]) : uint =
let mutable answer = 0u
for b = 0 to firstCount - 1 do
answer <- answer * 256u
answer <- answer + uint bytes.[b]
answer
use sha1 = SHA1.Create ()
// TODO: in the wild, this actually strips HTML first
this.Fields.[0] |> Encoding.UTF8.GetBytes |> sha1.ComputeHash |> fromBase256 4
[<Measure>]
type note