Files
wordpress-theme-aksrt/assets/creator-studio
kate522 a5386f72c6 fix(submit): make the draft chain survive continuous writing, reloads and flaky networks
Autosave only ran after 4s of idle, and every keystroke reset that timer, so a
writer who never stopped had zero saves (measured: 15s of typing = 0 requests).
Saving also never rebound the URL, so a new draft could not be found again after
a reload, the local backup was cleared on every autosave, and a failed save had
no retry and stayed failed once the network came back.

Client
- autosave: keep the idle debounce but add a 30s max-wait window that is not
  reset by further keystrokes, and retry failures at 5s / 15s / 60s
- bind `?edit=<id>` into the URL once the server returns a post id, so reloads,
  new tabs and history all reopen the same draft
- only clear the local backup when the save settled and nothing changed since
- key the local backup by draft id instead of the constant `jio-studio-0`
- restore snapshots through hydrateBlocks so code blocks come back editable
- never disable publish while an autosave is in flight, and mark autosave
  states separately (自动保存中… / 已自动保存 / 自动保存失败,将重试)
- on 409, adopt the server rev and tell the author instead of failing silently
- status bar reports the real save state instead of a bogus Markdown hint

Server
- draft saves no longer rewrite the lifecycle: pending / future / publish /
  private posts keep their status, so an autosave cannot pull a submitted post
  out of the review queue
- drafts and autosaves stop consuming the publish flood quota, which is meant to
  cap actual publishing (measured: 4 drafts used to burn 4 slots)
- autosave skips wp_save_post_revision for both plain drafts and submission
  versions; manual saves and submits still create a revision to roll back to
- media-only drafts (image / table / code / hr) count as content
- the response now carries the resulting status so the client can tell
  "just submitted" from "still under review"

Tests cover the max-wait window, retry schedule, URL binding, backup clearing,
status labelling and every server-side draft rule.
2026-11-10 17:58:22 +08:00
..

Jio Creator Studio(前台沉浸式创作工作台)

面向作者的前台写作体验:WordPress TinyMCE 负责 HTML 正文编辑,React + TypeScript 负责两行固定顶栏(站点身份 + 居中工具条)、写作工作台与发布抽屉,Jio 服务端继续作为权限、审核、付费与附件交付的唯一权威。

启动

cd assets/creator-studio
npm install            # 首次安装(packages 已锁定 WordPress 6.4 时代的版本)
npm run build          # 产物写入 assets/creator-studio/build/

build/ 是构建产物,不进版本库(与 assets/admin/build 同一约定);部署时在目标机上执行上面的 npm run build。

PHP 读取 build/index.asset.php(依赖清单 + 版本)并只在投稿模板加载,构建产物缺失时自动回退到原有 TinyMCE 投稿表单。

使用前提

  • 已登录且具备 new_post_add(编辑已有文章需作者本人或审核权限)。
  • 私有附件(付费资料)需要在 wp-config.php 里配置私有目录:
define('JIO_PRIVATE_STORAGE_DIR', '/var/private/jio-assets'); // ABSPATH 之外

若目录位于站点根目录内,还必须在 Web 服务器层禁止访问,并显式声明:

define('JIO_PRIVATE_STORAGE_VERIFIED', true);

未配置时付费资料上传/下载接口返回 501(fail closed),普通图片与视频上传不受影响。

关键行为

场景 行为
新文章草稿/投稿 复用 FrontSubmit::persist();草稿为 draft,投稿按 new_post_audit_no 决定 publish 或 pending
编辑已发布文章 写入私有改稿版本(jio_submission),线上文章与永久链接保持不变
审核通过 后台「文章 → 改稿审核」一次性应用内容、摘要、分类、标签、封面与付费设置
自动保存 云端 4 秒防抖 + rev 版本号;冲突返回 409,不覆盖较新内容
本地恢复 仅保存标题与 TinyMCE HTML 正文,恢复前询问用户
付费附件 上传到私有存储,只保存随机 asset_key;下载先取短期令牌,服务端每次复核订单/VIP/配额

相关代码

  • 服务端:src/Core/CreatorRest.php、CreatorStudio.php、SubmissionVersion.php、PreviewToken.php
  • 安全交付:src/Content/PrivateAssets.php、src/Content/ProtectedDownload.php
  • 原生审核:src/Admin/Native/SubmissionReview.php
  • 前端:assets/creator-studio/src/(index.tsx / components/editor-toolbar.tsx / panels/ / hooks/ / services/ / styles/)
  • 契约测试:tests/widget-system/creator-studio-contract.test.cjs

测试

node --test tests/widget-system/*.test.cjs
php tools/audit-psr4-paths.php