API: getting one blog does not accept ?body=html, but getting all blogs does

未关闭
#829 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
go
领域
api, backend

调研方向

首先定位 /api/collections/{alias}/posts 和 /api/collections/{alias}/posts/{slug} 的 handlers 或入口点,然后比较每个 route 如何读取 body 查询参数。验证单个 post 的响应是否像 collection 响应一样遵循 ?body=html,并确认省略该参数时两个 route 仍会返回预期的数据。

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

描述

enhancement
Describe the bug

When using the WriteFreely API to get all of a blog's posts, you can pass the parameter ?body=html to get HTML-formatted blog bodies.
/api/collections/test/posts?body=html

{
  "code": 200,
  "data": {
    "alias": "test",
    "title": "Test Blog",
    "description": "Hello, world!",
    "style_sheet": "",
    "public": true,
    "format": "blog",
    "views": 0,
    "url": "https://example.com/test/",
    "verification_link": "",
    "total_posts": 1,
    "posts": [
      {
        "id": "34hr3jrjjt",
        "slug": "test",
        "appearance": "norm",
        "language": "en",
        "rtl": false,
        "created": "2023-08-23T00:00:00-05:00",
        "updated": "2023-10-11T21:06:45-05:00",
        "title": "Test",
        "body": "<h1>This is a test.</h1>\n<a href="https://example.com/">Hello, world!</a>",
        "tags": [],
        "paid": false,
        "views": 1
      }
    ],
    "Format": null
  }
}

However, when getting one of a blog's posts, this parameter is no longer accepted and the body becomes Markdown.
/api/collections/test/posts/test?body=html

{
  "code": 200,
  "data": {
    "id": "34hr3jrjjt",
    "slug": "test",
    "appearance": "norm",
    "language": "en",
    "rtl": false,
    "created": "2023-08-23T00:00:00-05:00",
    "updated": "2023-10-11T21:06:45-05:00",
    "title": "Test",
    "body": "# This is a test.\n[Hello, world!](https://example.com/)",
    "tags": [],
    "paid": false,
    "views": 1
  }
}
Expected behavior

The API should accept the ?body=html parameter on both routes, so blogs can be returned in HTML, regardless of the method.

Application configuration
  • Single mode or Multi-user mode?: Multiple users
  • Database?: mysql
  • Open registration?: Invite-only
  • Federation enabled?: yes

Version or last commit: WriteFreely v0.14.0 on Ubuntu 22.04.3 LTS x86_64

主要语言
Go
星标
5.3k
派生
413
平均合并
3 天 5 小时
30 天内合并 PR
4

环境准备

从这里开始

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

writefreely/writefreely 的其他 Issue

查看 writefreely/writefreely 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

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