Open Fumesover opened 5 years ago
@Fumesover You are might interested in joining the CodiMD community channel to work with us on the new API. Your input would be very welcome :+1:
As the server currently provides and manages the note state anyway, we should find a better way than reimplementing OT in order to update notes.
If it makes it easier @SISheogorath, the CLI only needs a way to update the entire note contents at once (so no need for OT or individual line/diff-based edits).
I'm trying to figure out how to edit a note directly from the command line, unfortunately I can't delete text successfully. So I leave here what I found, and if someone can make it work, it would be a great addition to this client.
First of all, let's authentificate cf #9. (Idk if it's necessary)
Then, connecting to the socket.
Then, all messages must be passed to
$SERVER/socket.io/?noteId=$NOTEID&EIO=3&transport=polling&t=$(python yeast.py)&sid\=$TOKEN
, TOKEN is the token we just picked up.To do so:
This will send the data from the file
msg_0
to the socket.As an example, on a fresh new note:
With msg_4 containing
61:42["operation",0,["test"],{"ranges":[{"anchor":4,"head":4}]}]
Then, by analyzing the different possible messages I think the format is as follows:
$1:42["operation",$2,["$3",$4],{"ranges":[{"anchor":$5,"head":$5}]}]
:
For example:
61:42["operation",0,["test"],{"ranges":[{"anchor":4,"head":4}]}]
65:42["operation",0,["01234",-4],{"ranges":[{"anchor":5,"head":5}]}]
59:42["operation",0,[4,-1],{"ranges":[{"anchor":4,"head":4}]}]
This payloads are working when I'm inspecting the network on my browser, but I can't reproduce it (text deletion) by using curl. Even if the socket returns
ok
to me every time.I hope I can help, if someone can figure out how to do it. This is the last thing before being able to edit notes from codimd-cli.
PS: here you can find the source file