Find out how socket.io works in order to edit notes.

未关闭
#10 2 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
python, shell
领域
cli

调研方向

先从 issue 中的 socket 命令和 payload 示例开始,然后检查 gist 中链接的源代码,并将 curl 请求与浏览器网络消息进行比较。使用 yeast.py、msg_0 和 msg_4 作为参考入口点。当 CLI 可以通过 socket 协议编辑笔记(包括删除文本)时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

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)

codimd login --email [email protected] password

Then, connecting to the socket.

NOTEID=3_jUrZCYRTOtcEAJG6Oywg

# The socket url
URL=$CODIMD_SERVER/socket.io/?noteId=$NOTEID\&EIO=3\&transport=polling

# get the 'io' token
curl -c /tmp/codimd-cookies.txt \
    -b /tmp/codimd-cookies.txt \
    $URL\&t=$(python yeast.py) \
    &> /dev/null

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:

TOKEN=$(cat /tmp/codimd-cookies.txt | grep io | awk '{print $7}')

curl -b /tmp/codimd-cookies.txt \
    $URL\&t\=$(python yeast.py)\&sid\=$TOKEN \
    -H "Content-Type: text/plain;charset=UTF-8" \
    -d @msg_0

This will send the data from the file msg_0 to the socket.

As an example, on a fresh new note:

#!/bin/bash

SERVER=https://xxxxxxxxxxxxxx
NOTEID=xxxxxxxxxxxxxxxxxxxxxx

URL=$SERVER/socket.io/?noteId=$NOTEID\&EIO=3\&transport=polling

curl -c /tmp/codimd-cookies.txt \
    -b /tmp/codimd-cookies.txt \
    $URL\&t=$(python yeast.py) \
    &> /dev/null

TOKEN=$(cat /tmp/codimd-cookies.txt | grep io | awk '{print $7}')

curl -b /tmp/codimd-cookies.txt \
    $URL\&t\=$(python yeast.py)\&sid\=$TOKEN \
    -H "Content-Type: text/plain;charset=UTF-8" \
    -d @msg_4 

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}]}]

  • $1 is the len of the message after :
  • $2 is the number of the operation (starts at 0, then must be increased by one at each request)
  • $3 is the text that you want to add (optional)
  • $4 is the number of chars to remove (optional)
  • $5 is the location of the modification

For example:

  • Add test to the note
    • 61:42["operation",0,["test"],{"ranges":[{"anchor":4,"head":4}]}]
  • Remove test and replace it by 01234
    • 65:42["operation",0,["01234",-4],{"ranges":[{"anchor":5,"head":5}]}]
  • Remove the last char
    • 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

主要语言
Shell
星标
166
派生
39
平均合并
1 小时 27 分钟
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

hedgedoc/cli 的其他 Issue

查看 hedgedoc/cli 的全部 Issue

相似的 Issue

更多 Shell/Bash Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。