ai_co_discuss 0.5.37 → 0.5.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backend/server.py +3 -2
- package/backend/windows_thumbnail.py +3 -1
- package/docs/en/guide/rooms.md +2 -2
- package/docs/guide/rooms.md +2 -2
- package/frontend/locales/en/settings.json +2 -0
- package/package.json +1 -1
- package/runner/discussion_launch.mjs +45 -4
- package/web/admin.js +1 -1
- package/web/app.js +47 -5
- package/web/i18n.js +1 -1
- package/web/markdown.js +5 -5
- package/web/modern.css +1 -1
- package/web/modern.js +66 -66
package/backend/server.py
CHANGED
|
@@ -4108,8 +4108,9 @@ class DiscussionHandler(BaseHTTPRequestHandler):
|
|
|
4108
4108
|
payload = {"site": site}
|
|
4109
4109
|
if command == "room-config" and "participants" in payload:
|
|
4110
4110
|
return self.save_local_room_configuration(command, payload)
|
|
4111
|
-
# The computer's own page plays a project media file straight from disk by a ticket, with ranges for seeking
|
|
4112
|
-
|
|
4111
|
+
# The computer's own page plays a project media file straight from disk by a ticket, with ranges for seeking;
|
|
4112
|
+
# a thumbnail comes back whole, as to another device.
|
|
4113
|
+
if command == "room-media" and not self.bridge_origin and payload.get("thumbnail") is not True:
|
|
4113
4114
|
return self.issue_media_ticket(payload)
|
|
4114
4115
|
# A connected website's page is another device's entry: it gets the same limits as the relay.
|
|
4115
4116
|
return self.run_local_command(command, payload, remote=bool(self.bridge_origin) and command != "machine-link")
|
|
@@ -162,6 +162,8 @@ if __name__ == "__main__":
|
|
|
162
162
|
decoded = Path(directory) / "decoded.png"
|
|
163
163
|
decode_system_webp(path, decoded)
|
|
164
164
|
path = decoded
|
|
165
|
-
|
|
165
|
+
# The longest side asked for: 1440 for the preview, smaller for the file page's thumbnails.
|
|
166
|
+
side = int(sys.argv[1]) if len(sys.argv) > 1 and sys.argv[1].isdigit() else 1440
|
|
167
|
+
result = encode_preview(path, width, height, max(64, min(side, 1440)), project=True)
|
|
166
168
|
if result and len(result) < os.fstat(sys.stdin.fileno()).st_size:
|
|
167
169
|
sys.stdout.buffer.write(result)
|
package/docs/en/guide/rooms.md
CHANGED
|
@@ -47,8 +47,8 @@ When viewing a project image through the relay on another device, supported imag
|
|
|
47
47
|
“File changes” below an answer shows the number of changed files and lines added or removed. Lists of five files or fewer open by default. Select the file count to open a longer list. Read-only visitors can see the list, but only the room owner can view patches.
|
|
48
48
|
|
|
49
49
|
- **Add or remove directories.** A room supports one primary directory and up to eight additional directories. After creating a room, open the “Room” tab at the top of the room and find “Project folder”. Add or remove additional directories there. Changes apply from each member’s next run and do not interrupt a session. A primary directory cannot be changed after it is set. If the room was created without one, you can set it once in the same section. Members can access all room directories subject to their individual project permissions.
|
|
50
|
-
- **Open Files.** In the tabs at the top of the room, select “Files” to browse directories, file sizes, and modification times. Switch between the primary and additional directories at the top. A project directory is required.
|
|
51
|
-
- **Preview files.** Select a file to open its floating preview. Supported previews include plain text, code, rendered Markdown, static HTML with a source view, zoomable and rotatable images, audio and video with speed and full-screen controls, CSV tables, subtitle timelines (SRT, VTT, ASS, LRC), read-only Word, Excel, PowerPoint and PDF, Premiere project XML, and zip archives listed like a folder, where selecting a file inside opens it in a new tab.
|
|
50
|
+
- **Open Files.** In the tabs at the top of the room, select “Files” to browse directories, file sizes, and modification times. Switch between the primary and additional directories at the top. A project directory is required. The “Icon view” button at the top right lays the folder out as tiles, with thumbnails for PNG, JPG, and WebP images; “List view” switches back. Thumbnails are made by the computer and currently only on Windows; other images and files show their icons.
|
|
51
|
+
- **Preview files.** Select a file to open its floating preview. Supported previews include plain text, code, rendered Markdown, static HTML with a source view, zoomable and rotatable images, audio and video with speed and full-screen controls, CSV tables, subtitle timelines (SRT, VTT, ASS, LRC), read-only Word, Excel, PowerPoint and PDF, Premiere project XML, and zip archives listed like a folder, where selecting a file inside opens it in a new tab. Images in Markdown display inline the way message images do; select one to zoom. Paths are accepted as common editors accept them: relative paths, project paths starting with `/`, absolute paths inside the room's project directories (such as `D:\Project\art\a.png` or `file:///D:/Project/art/a.png`), and web addresses. Files outside the room's project directories are not read. Images load as you scroll near them; landscape images fill the width and portrait images fit the window height. Other devices get a copy the computer compressed. Opening a ZIP attachment or project file loads the directory first. Select an entry to read it (up to 64 MiB), or choose “Download” to save the archive.
|
|
52
52
|
- **Tabs, split view, and collapse.** Open multiple files and switch between tabs. Use the preview controls to split the view on the right or use “File location” to return to the containing folder. HTML previews also offer “Open in new tab”. Select “Collapse” in the title bar to keep the preview as a floating button in the corner. It restores the same file and scroll position when you return to the room. Close it to clear the preview.
|
|
53
53
|
- **Quote and annotate.** Select text in a Markdown preview or a member’s answer and choose “Add to conversation”. Enter a note and press Enter. The source is marked with a number and the composer shows the number of notes. On a computer, open the notes list, choose “Edit annotation”, and drag the bottom-right corner of the editor to resize it. Sending the message adds a file path and line number, the member and message ID, or for a message attachment its message ID and attachment ID. An `@` inside a quote does not wake a member.
|
|
54
54
|
- **Manage project files.** Select “Project” at the start of the path bar to open your projects and drafts. Use the top controls to create folders and upload files (up to 20 MB each). File menus offer “Download” (“Download folder” for a folder, packed as a ZIP), “Rename”, “Copy”, “Cut”, and “Delete”. Paste into the destination folder. Deleted files and replaced versions go to “Recycle bin” for 30 days, where they can be restored. In source view, the pencil button edits text files up to 1 MB. Project and draft roots, and folders currently used as room project directories, cannot be renamed, moved, or deleted.
|
package/docs/guide/rooms.md
CHANGED
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
回答下方的“文件改动”显示已修改的文件数和增删行数。改动不超过 5 个文件时默认展开,超过时点击文件数查看清单。可读房间的访客也能看清单,只有房主能看补丁。
|
|
46
46
|
|
|
47
47
|
- **增删项目目录**:一个房间可有 1 个主项目目录和最多 8 个其他项目目录。建房后打开顶部“房间”页,在“项目目录”区域可增删其他目录,保存后从各成员下一次执行起生效,不中断会话。主目录设置后不能更改;建房时未设的,可在同一行补设一次。成员按各自项目权限读写全部目录。
|
|
48
|
-
-
|
|
49
|
-
- **预览文件**:点击文件打开悬浮预览,支持纯文本、代码、Markdown 渲染、HTML 静态渲染并可切换源码;图片可缩放、旋转;音视频带倍速与全屏直接播放;CSV 显示为表格,字幕(SRT、VTT、ASS、LRC)显示为时间轴;Word、Excel、PowerPoint 与 PDF 只读预览;Premiere 工程显示其 XML;zip 压缩包像文件夹一样列出其中的文件夹与文件,点击其中的文件在新标签中预览。Markdown
|
|
48
|
+
- **打开“文件”页**:房间顶部的标签栏点“文件”,浏览目录、文件大小与修改时间,上方可切换主目录与其他项目目录。浏览文件需要已设置项目目录。右上角的“图标视图”按钮把列表换成图标排列,PNG、JPG、WebP 图片显示缩略图,再点“列表视图”换回;缩略图由这台电脑生成,目前只在 Windows 电脑上有,其他图片和文件显示图标。
|
|
49
|
+
- **预览文件**:点击文件打开悬浮预览,支持纯文本、代码、Markdown 渲染、HTML 静态渲染并可切换源码;图片可缩放、旋转;音视频带倍速与全屏直接播放;CSV 显示为表格,字幕(SRT、VTT、ASS、LRC)显示为时间轴;Word、Excel、PowerPoint 与 PDF 只读预览;Premiere 工程显示其 XML;zip 压缩包像文件夹一样列出其中的文件夹与文件,点击其中的文件在新标签中预览。Markdown 中的图片与消息里的图片显示方式相同,在正文中直接显示,点击可放大查看。支持常见编辑器的写法:相对路径、以 `/` 开头的项目内路径、房间项目目录内的绝对路径(如 `D:\项目\插图\a.png`、`file:///D:/项目/插图/a.png`)与网络地址;房间项目目录之外的文件不会读取。滚动到附近才载入,横图铺满宽度、竖图按窗口高度显示;在其他设备上看到的是电脑压缩过的版本。打开房间附件或项目中的 ZIP 时先显示目录,点包内文件才读取内容。单个文件最多预览 64 MiB,也可以点“下载”保存整个压缩包。
|
|
50
50
|
- **多标签、分屏与收起**:可同时打开多个文件以标签切换,在预览栏切换为右侧分屏、或点“文件位置”回到所在文件夹。HTML 预览还可以“在新标签页打开”。点标题栏“收起”缩成内容区角落的悬浮按钮,切到其他房间后点它即可回到原文件与滚动位置,关闭才清空。
|
|
51
51
|
- **摘录批注**:在 Markdown 预览或成员回答正文中选中文字点“添加到对话”,可输入批注并回车,原文标出编号,输入框上方显示“N 条注释”。在电脑上,打开注释列表,点“修改批注”,可拖动编辑框右下角调整宽高。发送时自动附带文件路径+行号、成员+消息编号,或消息附件所属的消息编号与附件 ID,引用中的 `@` 不会唤醒成员。
|
|
52
52
|
- **整理文件**:点路径栏最前面的“项目”,可以打开你所有的项目和草稿。上方按钮用于新建文件夹和上传文件(单个不超过 20 MB);每行的菜单里有“下载”(文件夹为“下载文件夹”,打包成 ZIP)、“重命名”、“复制”、“剪切”、“删除”,复制或剪切后到目标文件夹点“粘贴”。删除的文件和被替换掉的旧版放进“回收区”,保留 30 天,可以还原。在源码视图点铅笔按钮可以编辑文本文件(不超过 1 MB)。项目、草稿文件夹本身,以及房间正在用作项目目录的文件夹,都不能改名、移动或删除。
|
|
@@ -480,6 +480,8 @@
|
|
|
480
480
|
"正在读取项目目录": "Loading project folder",
|
|
481
481
|
"重新读取目录": "Reload folder",
|
|
482
482
|
"此文件夹为空": "This folder is empty",
|
|
483
|
+
"列表视图": "List view",
|
|
484
|
+
"图标视图": "Icon view",
|
|
483
485
|
"{value1} 项": "{value1} items",
|
|
484
486
|
",已显示 {value1} 项": "; {value1} shown",
|
|
485
487
|
"正在排版 Word 文档…": "Laying out Word document…",
|
package/package.json
CHANGED
|
@@ -742,9 +742,12 @@ export const REMOTE_MEDIA_MAX_BYTES = 64 * 1024 * 1024;
|
|
|
742
742
|
const PROJECT_PREVIEW_SLOTS = 12;
|
|
743
743
|
const PROJECT_PREVIEW_CONCURRENCY = 2;
|
|
744
744
|
const PROJECT_PREVIEW_MAX = 8 * 1024 * 1024;
|
|
745
|
+
// The file page's icon view: the longest side of an image's thumbnail, and how many of them the computer keeps.
|
|
746
|
+
const PROJECT_THUMBNAIL_SIDE = 256;
|
|
747
|
+
const PROJECT_THUMBNAIL_SLOTS = 400;
|
|
745
748
|
|
|
746
749
|
/** Keep completed previews in an LRU; queued and running versions share a promise until encoding finishes. */
|
|
747
|
-
export function project_preview_reader(probe) {
|
|
750
|
+
export function project_preview_reader(probe, slots = PROJECT_PREVIEW_SLOTS) {
|
|
748
751
|
const cached = new Map(), pending = new Map(), waiting = [];
|
|
749
752
|
let python, running = 0;
|
|
750
753
|
async function generate(home, key, encode) {
|
|
@@ -755,7 +758,7 @@ export function project_preview_reader(probe) {
|
|
|
755
758
|
const bytes = await encode(await python);
|
|
756
759
|
if (bytes) {
|
|
757
760
|
cached.set(key, bytes);
|
|
758
|
-
if (cached.size >
|
|
761
|
+
if (cached.size > slots) cached.delete(cached.keys().next().value);
|
|
759
762
|
}
|
|
760
763
|
return bytes;
|
|
761
764
|
} catch { return null; }
|
|
@@ -778,13 +781,14 @@ export function project_preview_reader(probe) {
|
|
|
778
781
|
}
|
|
779
782
|
|
|
780
783
|
const project_preview_bytes = project_preview_reader(home => detect_python(local_settings(home).python));
|
|
784
|
+
const project_thumbnail_bytes = project_preview_reader(home => detect_python(local_settings(home).python), PROJECT_THUMBNAIL_SLOTS);
|
|
781
785
|
|
|
782
|
-
async function encode_project_preview(preview_python, file) {
|
|
786
|
+
async function encode_project_preview(preview_python, file, side = 1440) {
|
|
783
787
|
const script = join(import.meta.dirname, '..', 'backend', 'windows_thumbnail.py');
|
|
784
788
|
const fd = openSync(file, 'r');
|
|
785
789
|
let child;
|
|
786
790
|
try {
|
|
787
|
-
child = spawn(preview_python, ['-I', '-B', script], {
|
|
791
|
+
child = spawn(preview_python, ['-I', '-B', script, String(side)], {
|
|
788
792
|
windowsHide: true, timeout: 15000, stdio: [fd, 'pipe', 'ignore'], cwd: dirname(script),
|
|
789
793
|
});
|
|
790
794
|
} finally { closeSync(fd); }
|
|
@@ -809,12 +813,18 @@ async function encode_project_preview(preview_python, file) {
|
|
|
809
813
|
*/
|
|
810
814
|
export async function room_media(home, raw, { trust = false, parts = false } = {}) {
|
|
811
815
|
const { input, config } = await member_room_context(home, raw, { trust });
|
|
816
|
+
// A Markdown file may name an image by its absolute path on this computer: it is read from the room directory holding
|
|
817
|
+
// it. `/…` is such a path where one exists (macOS, Linux), otherwise a path from the project folder, as editors take it.
|
|
818
|
+
const named = String(input.path || '');
|
|
819
|
+
if (/^([a-zA-Z]:[\\/]|\\\\)/.test(named)) Object.assign(input, absolute_room_path(config, named, win32));
|
|
820
|
+
else if (named.startsWith('/')) Object.assign(input, (process.platform !== 'win32' && absolute_room_path(config, named, posix, false)) || { path: named.replace(/^\/+/, '') });
|
|
812
821
|
const root = input.root ?? 0;
|
|
813
822
|
const offset = input.offset ?? 0;
|
|
814
823
|
const directory = files_root(home, config, root);
|
|
815
824
|
if (!Number.isSafeInteger(offset) || offset < 0) throw new Error('文件读取位置无效');
|
|
816
825
|
// `download` reads any regular file for saving, not only the kinds the preview shows.
|
|
817
826
|
const { file, ...media } = project_media(directory, input.path, { download: input.download === true });
|
|
827
|
+
if (input.thumbnail === true) return { room_id: input.room_id, root, ...media, ...await project_thumbnail(home, directory, input.path, file, media) };
|
|
818
828
|
// The folder goes to the computer's own website alone, for a page opened in a tab (it never reaches a page).
|
|
819
829
|
if (!parts) return { room_id: input.room_id, root, ...media, file, directory };
|
|
820
830
|
if (media.size > REMOTE_MEDIA_MAX_BYTES) {
|
|
@@ -844,6 +854,37 @@ export async function room_media(home, raw, { trust = false, parts = false } = {
|
|
|
844
854
|
return { room_id: input.room_id, root, ...media, total: media.size, offset, data: part.toString('base64') };
|
|
845
855
|
}
|
|
846
856
|
|
|
857
|
+
/**
|
|
858
|
+
* `{ root, path }` of an absolute path (`paths`: node's win32 or posix) inside one of the room's directories; elsewhere
|
|
859
|
+
* refused, or null when not `required`.
|
|
860
|
+
*/
|
|
861
|
+
function absolute_room_path(config, path, paths, required = true) {
|
|
862
|
+
const target = paths.resolve(path);
|
|
863
|
+
for (const [root, directory] of room_directories(config).entries()) {
|
|
864
|
+
const inside = paths.relative(paths.resolve(directory), target);
|
|
865
|
+
if (inside && !inside.startsWith('..') && !paths.isAbsolute(inside)) return { root, path: inside.replaceAll('\\', '/') };
|
|
866
|
+
}
|
|
867
|
+
if (!required) return null;
|
|
868
|
+
throw new Error('图片不在房间的项目目录内,无法读取');
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* The small copy of one project image the file page's icon view shows, made on this computer for both its own page and
|
|
873
|
+
* another device: `{ data, content_type }` (base64, whole), or `{ data: null }` where none can be made (not a PNG, JPEG
|
|
874
|
+
* or WebP, not Windows, an image too large to decode), and the page keeps the file's icon.
|
|
875
|
+
*/
|
|
876
|
+
async function project_thumbnail(home, directory, path, file, media) {
|
|
877
|
+
if (process.platform !== 'win32' || !/^image\/(png|jpeg|webp)$/.test(media.content_type)) return { data: null };
|
|
878
|
+
const key = createHash('sha256').update(JSON.stringify([file, media.version, `${PROJECT_THUMBNAIL_SIDE}-v1`])).digest('hex');
|
|
879
|
+
const bytes = await project_thumbnail_bytes(home, key, python => {
|
|
880
|
+
const ready = project_media(directory, path);
|
|
881
|
+
if (ready.file !== file || ready.version !== media.version) return null;
|
|
882
|
+
return encode_project_preview(python, file, PROJECT_THUMBNAIL_SIDE);
|
|
883
|
+
});
|
|
884
|
+
if (!bytes || bytes.length > PAGE_PART_BYTES) return { data: null };
|
|
885
|
+
return { content_type: bytes[0] === 0xff ? 'image/jpeg' : 'image/png', data: bytes.toString('base64') };
|
|
886
|
+
}
|
|
887
|
+
|
|
847
888
|
/** `room-media` asked for by another device, answered inside the relay's own process in parts. */
|
|
848
889
|
export async function remote_room_media(home, input) {
|
|
849
890
|
assert_shared_home(home);
|