Files
cindy/scripts/file-peer-runtime.mjs
Dash 0a104b5ae9 feat(files): 统一远程文件读取并按需预览 HTML (#4346)
* feat: preview remote HTML snapshots with peer file transport

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(files): 网页预览准备使用中性加载提示

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(files): 使用 SHA-256 生成远程缓存标识

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(remote-files): guard preview requests and owner-scoped cache completion

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(remote-files): guard preview media reference ingestion

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(files): 统一两端音视频流式读取策略

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(mobile): 区分文件预览与下载的读取意图

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(files): 避免手机预览持有短期 peer 文件地址

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(security): 为正式包文件传输页面注入 CSP

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(mobile): 统一处理文件 WebView 进程终止

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(mobile): 为 HTML 快照拒绝设备权限

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(files): enforce snapshot budgets before OSS uploads

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(files): 按需预览远程 HTML 并支持 2 GiB 文件传输

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* test(files): 复用真实的跨平台 HTML 路径转换

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(mobile): HTML 入口加载失败进入重试态

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(mobile): 取消 HTML 预览连接超时任务

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* chore: regenerate design inventory after main merge

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(mobile): keep on-demand document errors retryable

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(files): cancel shared remote reads when unused

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(mobile): keep async preview reads alive

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(files): serialize desktop HTML preview resource copies

Reuse the existing file-read queue so one preview cannot overlap 2 GiB materializations.

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* test(desktop): 对齐主干 bootstrap 接线格式

GitHub CI 合入最新 main 后 bootstrap 换行变化,源码契约测试仍按旧单行断言。

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(files): allow SSH HTML preview and reuse on-demand paths

SSH on-demand HTML was rejected as 415. Repeated cache-busted requests now reuse the preview-owned file instead of fetching again.

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(files): keep on-demand preview files until close

Native on-demand responses no longer delete the materialized file when the first socket closes, and desktop reuses the preview-owned copy for the same path.

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

---------

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
2026-09-16 22:08:39 +07:00

15 lines
1.1 KiB
JavaScript

// Generate the WebView script before Hermes compiles the native JS bundle.
import { createRequire } from 'node:module';
import { readFile, writeFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
const require = createRequire(new URL('../apps/desktop/package.json', import.meta.url));
const { build } = require('esbuild');
const entry = fileURLToPath(new URL('../packages/device-link/src/filePeerRuntime.ts', import.meta.url));
const destination = new URL('../packages/device-link/src/filePeerRuntimeSource.ts', import.meta.url);
const output = await build({ entryPoints: [entry], bundle: true, write: false, format: 'iife', globalName: 'CindyFilePeerRuntime', target: 'es2020', minify: true });
const content = '// Generated by node scripts/file-peer-runtime.mjs. Do not edit.\n' +
'export const FILE_PEER_RUNTIME_SOURCE = ' + JSON.stringify(output.outputFiles[0].text) + ';\n';
if (process.argv.includes('--check')) {
if (await readFile(destination, 'utf8') !== content) throw new Error('Run node scripts/file-peer-runtime.mjs');
} else await writeFile(destination, content);