@lalalic/markcut 3.2.60 → 3.2.62
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/README.md +48 -5
- package/bin/markcut +15 -0
- package/docs/developer-reference.md +41 -1
- package/package.json +8 -2
- package/recipes/markcut/map-cinematic-follow.json +17 -0
- package/recipes/markcut/map-location-reveal.json +17 -0
- package/recipes/markcut/map-route-journey.json +18 -0
- package/recipes/markcut/map-streetview-explore.json +17 -0
- package/skills/markcut/SKILL.md +8 -3
- package/skills/markcut/docs/markdown-descriptive.md +68 -1
- package/skills/markcut/docs/recipes.md +45 -0
- package/skills/markcut/references/mobile-event-preview-cli.md +9 -5
- package/src/descriptive/compiler.ts +38 -2
- package/src/descriptive/markdown.ts +30 -0
- package/src/descriptive/model3d.test.ts +38 -0
- package/src/editor-decision/cli.mjs +21 -0
- package/src/editor-decision/editor-decision.schema.json +41 -0
- package/src/editor-decision/index.mjs +115 -0
- package/src/editor-decision/index.test.mjs +63 -0
- package/src/mcp/bridge.mjs +92 -12
- package/src/mcp/compile-worker.mjs +2 -2
- package/src/mcp/design-cli.mjs +126 -0
- package/src/mcp/mobile-review-cli.mjs +40 -33
- package/src/mcp/preview-mobile.css +21 -8
- package/src/mcp/preview.mjs +97 -57
- package/src/mcp/remote-assets.mjs +85 -7
- package/src/mcp/remotion-app.bundle.js +5013 -1117
- package/src/mcp/remotion-app.tsx +132 -10
- package/src/mcp/server.mjs +4 -2
- package/src/player/browser.tsx +1 -3
- package/src/player/bundle/player.js +73054 -17357
- package/src/player/components/HeaderBar.tsx +3 -1
- package/src/player/components/VariantBar.tsx +20 -21
- package/src/player/pipeline.mjs +133 -77
- package/src/player/server.mjs +43 -23
- package/src/recipes/catalog.mjs +115 -0
- package/src/recipes/cli.mjs +87 -0
- package/src/render/cli.mjs +40 -1
- package/src/schema/index.ts +21 -0
- package/src/types/Folder.tsx +2 -0
- package/src/types/Model3D.tsx +91 -0
- package/src/vision/cli.mjs +63 -50
- package/tests/mcp-design-mode.test.ts +100 -0
- package/tests/mcp-editor-decisions-mobile.test.ts +35 -0
- package/tests/mcp-preview-bridge.test.ts +44 -3
- package/tests/mcp-preview-proxy-version.test.mjs +80 -0
- package/tests/mcp-preview.test.ts +43 -8
- package/tests/mcp-remote-assets.test.ts +17 -0
- package/tests/mcp-static-preview.test.ts +1 -1
- package/tests/mcp-video-selector.test.ts +55 -0
- package/tests/mobile-preview-cli.test.ts +10 -15
- package/tests/recipes-catalog.test.ts +141 -0
- package/tests/vision-generic-vtt-hooks.test.ts +7 -7
- package/tests/vision-normalized-metadata.test.ts +23 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Standalone NeoY design view: the source video.md, not a review or browser
|
|
3
|
+
// Session, is the stable identity. Compilation remains Markcut's concern.
|
|
4
|
+
import {createHash} from 'node:crypto';
|
|
5
|
+
import {execFileSync} from 'node:child_process';
|
|
6
|
+
import {readFileSync,writeFileSync,mkdirSync,renameSync,statSync} from 'node:fs';
|
|
7
|
+
import {resolve,dirname,join,basename} from 'node:path';
|
|
8
|
+
import {pathToFileURL} from 'node:url';
|
|
9
|
+
import {EXPORT_ROOT,publicOrigin,resolveMountedFile} from './remote-assets.mjs';
|
|
10
|
+
import {buildPreviewHtml} from './preview.mjs';
|
|
11
|
+
import {startCompileOperation} from './compile-operation.mjs';
|
|
12
|
+
|
|
13
|
+
const delay=ms=>new Promise(ok=>setTimeout(ok,ms));
|
|
14
|
+
|
|
15
|
+
export function parseDesignArgs(argv){
|
|
16
|
+
if(argv[0]!=='preview'||typeof argv[1]!=='string'||!argv[1].endsWith('.md'))
|
|
17
|
+
throw Error('Usage: markcut preview <video.md> --design [--no-split]');
|
|
18
|
+
const flags=argv.slice(2);
|
|
19
|
+
if(!flags.includes('--design')||flags.some(f=>!['--design','--no-split'].includes(f))||
|
|
20
|
+
new Set(flags).size!==flags.length)
|
|
21
|
+
throw Error('Design preview supports only --design and --no-split');
|
|
22
|
+
return {file:resolve(argv[1]),split:!flags.includes('--no-split')};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function designSourceUrl(file,origin=publicOrigin(),resolveSource=resolveMountedFile){
|
|
26
|
+
const mounted=resolveSource(file,origin);
|
|
27
|
+
if(!mounted)throw Error('Design video.md must be inside an existing NeoY file mount');
|
|
28
|
+
const url=new URL(mounted);
|
|
29
|
+
if(url.origin!==origin||!/^\/files\/(?!_neoy\/)[A-Za-z0-9_-]+\/.+\.md$/i.test(url.pathname))
|
|
30
|
+
throw Error('Design source must be a mounted Markdown file');
|
|
31
|
+
return url.pathname;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function designViewerUrl(sourcePath,origin=publicOrigin()){
|
|
35
|
+
if(!/^\/files\/(?!_neoy\/)[A-Za-z0-9_-]+\/.+\.md$/i.test(sourcePath))
|
|
36
|
+
throw Error('Invalid design source URL');
|
|
37
|
+
return origin+'/files/_neoy/markcut/design.html?path='+encodeURIComponent(sourcePath);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// The shared MCP player is published *unchanged* as the standalone page.
|
|
41
|
+
export function publishDesignViewer({root=EXPORT_ROOT,html=buildPreviewHtml()}={}){
|
|
42
|
+
mkdirSync(root,{recursive:true});
|
|
43
|
+
const target=join(root,'design.html');
|
|
44
|
+
try{if(readFileSync(target,'utf8')===html)return target;}catch{}
|
|
45
|
+
const temp=target+'.'+process.pid+'.tmp';
|
|
46
|
+
writeFileSync(temp,html,{mode:0o644});renameSync(temp,target);
|
|
47
|
+
return target;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Cheap watcher stamp: avoid hashing large videos every few seconds. The actual
|
|
51
|
+
// compiler fingerprints media content when this metadata stamp changes.
|
|
52
|
+
export function designInputStamp(file){
|
|
53
|
+
const source=readFileSync(file,'utf8');
|
|
54
|
+
const base=dirname(file),candidates=new Set([file,join(base,basename(file,'.md')+'.wav')]);
|
|
55
|
+
for(const match of source.matchAll(/\b(?:src|audio|edl)\s*:\s*["']?([^"'\s;]+\.(?:png|jpe?g|webp|svg|gif|mp4|mov|webm|wav|mp3|m4a|ogg|vtt|srt|json))/gi)){
|
|
56
|
+
if(match[1].includes('://')||match[1].startsWith('/'))continue;
|
|
57
|
+
candidates.add(resolve(base,match[1]));
|
|
58
|
+
}
|
|
59
|
+
const stamp=[createHash('sha256').update(source).digest('hex')];
|
|
60
|
+
for(const path of [...candidates].sort())try{
|
|
61
|
+
const s=statSync(path);stamp.push(path,s.size,s.mtimeMs,s.ctimeMs);
|
|
62
|
+
}catch{}
|
|
63
|
+
return JSON.stringify(stamp);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function compileDesign(file,source,{start=startCompileOperation,root=EXPORT_ROOT,limitMs=300000}={}){
|
|
67
|
+
const op=start(source,{delivery:'text'});
|
|
68
|
+
const statusFile=join(root,'operations',op.operationId+'.json');
|
|
69
|
+
const until=Date.now()+limitMs;
|
|
70
|
+
while(Date.now()<until){
|
|
71
|
+
let state;try{state=JSON.parse(readFileSync(statusFile,'utf8'));}catch{}
|
|
72
|
+
if(state?.state==='ready')return state.result;
|
|
73
|
+
if(state?.state==='failed')throw Error('Design compilation failed: '+state.error);
|
|
74
|
+
await delay(300);
|
|
75
|
+
}
|
|
76
|
+
throw Error('Design compilation timed out');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function runDesignPreview(argv,{run=execFileSync,compile=compileDesign,
|
|
80
|
+
publish=publishDesignViewer,stamp=designInputStamp,onReady=()=>{}}={}){
|
|
81
|
+
const {file,split}=parseDesignArgs(argv);
|
|
82
|
+
const source=designSourceUrl(file),url=designViewerUrl(source);
|
|
83
|
+
const initialStamp=stamp(file);
|
|
84
|
+
publish();
|
|
85
|
+
await compile(file,source);
|
|
86
|
+
let sessionId=null;
|
|
87
|
+
if(split){
|
|
88
|
+
const receipt=JSON.parse(run('webhelm',['design','start','--url',url],
|
|
89
|
+
{encoding:'utf8',timeout:60000,stdio:['ignore','pipe','pipe']}));
|
|
90
|
+
if(receipt.design_mode!==true||!receipt.session_id)throw Error('WebHelm Design Mode did not start');
|
|
91
|
+
sessionId=receipt.session_id;
|
|
92
|
+
}
|
|
93
|
+
console.log(JSON.stringify({status:'design_ready',file,url,watching:true,split}));
|
|
94
|
+
onReady({file,url,source});
|
|
95
|
+
let running=true,stopping=false,previous=initialStamp,compileBusy=false;
|
|
96
|
+
async function stop(){
|
|
97
|
+
if(stopping)return;stopping=true;running=false;
|
|
98
|
+
if(sessionId){
|
|
99
|
+
try{run('webhelm',['design','stop',sessionId],{encoding:'utf8',timeout:90000,stdio:['ignore','pipe','pipe']});}
|
|
100
|
+
catch(error){console.error('WebHelm Design Mode cleanup failed: '+String(error.message||error));}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const sigint=()=>void stop(),sigterm=()=>void stop();
|
|
104
|
+
process.once('SIGINT',sigint);process.once('SIGTERM',sigterm);
|
|
105
|
+
try{
|
|
106
|
+
while(running){
|
|
107
|
+
await delay(1800);
|
|
108
|
+
if(!running||compileBusy)continue;
|
|
109
|
+
let next;try{next=stamp(file);}catch(error){console.error('Design source unavailable: '+error.message);continue;}
|
|
110
|
+
if(next===previous)continue;
|
|
111
|
+
previous=next;compileBusy=true;
|
|
112
|
+
try{await compile(file,source);console.log(JSON.stringify({status:'design_refreshed',file,url}));}
|
|
113
|
+
catch(error){console.error('Design recompile failed: '+String(error.message||error));}
|
|
114
|
+
finally{compileBusy=false;}
|
|
115
|
+
}
|
|
116
|
+
}finally{
|
|
117
|
+
process.removeListener('SIGINT',sigint);process.removeListener('SIGTERM',sigterm);
|
|
118
|
+
await stop();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if(process.argv[1]&&import.meta.url===pathToFileURL(resolve(process.argv[1])).href){
|
|
123
|
+
runDesignPreview(process.argv.slice(2)).catch(error=>{
|
|
124
|
+
console.error('Markcut Design Mode failed: '+String(error.message||error));process.exitCode=1;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/** Standalone terminal preview compiler. Notification is owned by the Neo MCP wrapper. */
|
|
3
3
|
import {readFileSync,existsSync} from 'node:fs';
|
|
4
|
-
import {
|
|
4
|
+
import {spawn,execFileSync} from 'node:child_process';
|
|
5
|
+
import {join,resolve,basename,dirname} from 'node:path';
|
|
5
6
|
import {homedir} from 'node:os';
|
|
6
7
|
import {pathToFileURL} from 'node:url';
|
|
7
8
|
import {normalizeReviewConfig} from './review-delivery.mjs';
|
|
@@ -27,25 +28,39 @@ export function parseEventPreviewOptions(argv) {
|
|
|
27
28
|
return options;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
// The
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
export function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
// The explicit Neo Mobile delivery CLI resolves the installed Neo wrapper.
|
|
32
|
+
// No application-specific queue, APNs key or direct Review REST dependency
|
|
33
|
+
// is embedded in Markcut's compiler/server.
|
|
34
|
+
export function neoReviewWrapper(override=process.env.NEO_REVIEW_WRAPPER,
|
|
35
|
+
discover=execFileSync){
|
|
36
|
+
if(override){
|
|
37
|
+
const path=resolve(override);
|
|
38
|
+
if(!existsSync(path))throw Error('Neo preview wrapper is unavailable');
|
|
39
|
+
return path;
|
|
40
|
+
}
|
|
41
|
+
const catalog=JSON.parse(String(discover('neo',['skill','list'],
|
|
42
|
+
{encoding:'utf8',timeout:10000,maxBuffer:1024*1024})));
|
|
43
|
+
const entry=catalog.find(x=>x.name==='mcp-wrapper'&&typeof x.path==='string');
|
|
44
|
+
if(!entry)throw Error('Neo mcp-wrapper skill is unavailable');
|
|
45
|
+
const path=join(dirname(entry.path),'markcut.mjs');
|
|
46
|
+
if(!existsSync(path))throw Error('Neo preview wrapper is unavailable');
|
|
47
|
+
return path;
|
|
48
|
+
}
|
|
49
|
+
export async function deliverThroughNeoWrapper(request,{wrapper=neoReviewWrapper()}={}){
|
|
50
|
+
const child=spawn(process.execPath,[wrapper,'deliver'],{stdio:['pipe','pipe','pipe']});
|
|
51
|
+
return await new Promise((resolve,reject)=>{
|
|
52
|
+
let out='',err='';
|
|
53
|
+
const timer=setTimeout(()=>{child.kill();reject(Error('Neo review delivery timed out'))},20000);
|
|
54
|
+
child.stdout.on('data',bytes=>{out+=String(bytes);if(out.length>65536)child.kill();});
|
|
55
|
+
child.stderr.on('data',bytes=>{err+=String(bytes);if(err.length>2000)err=err.slice(0,2000);});
|
|
56
|
+
child.on('error',error=>{clearTimeout(timer);reject(error)});
|
|
57
|
+
child.on('close',code=>{
|
|
58
|
+
clearTimeout(timer);
|
|
59
|
+
if(code!==0){reject(Error('Neo review wrapper delivery failed: '+err.slice(0,300)));return;}
|
|
60
|
+
try{resolve(JSON.parse(out))}catch{reject(Error('Invalid Neo review receipt'))}
|
|
61
|
+
});
|
|
62
|
+
child.stdin.end(JSON.stringify(request));
|
|
63
|
+
});
|
|
49
64
|
}
|
|
50
65
|
export function buildReviewRequest(options,config,state,operationId){
|
|
51
66
|
const data=state?.result;
|
|
@@ -60,19 +75,11 @@ export function buildReviewRequest(options,config,state,operationId){
|
|
|
60
75
|
}else {request.contentHash=data.contentHash;request.revisionId=data.revisionId;request.groupId=options.file;}
|
|
61
76
|
return request;
|
|
62
77
|
}
|
|
63
|
-
export async function submitNeoReview(request,{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const response=await fetchImpl(destination.href,{method:'POST',
|
|
69
|
-
headers:{'Content-Type':'application/json','Accept':'application/json'},
|
|
70
|
-
body:JSON.stringify(request),signal:AbortSignal.timeout(55000),redirect:'error'});
|
|
71
|
-
if(!response.ok)throw Error('Neo Review REST rejected delivery: HTTP '+response.status);
|
|
72
|
-
const receipt=await response.json();
|
|
73
|
-
if(receipt?.stored!==true||receipt.requestId!==request.id)
|
|
74
|
-
throw Error('Neo Review Core did not acknowledge durable Inbox storage');
|
|
75
|
-
return receipt;
|
|
78
|
+
export async function submitNeoReview(request,{deliver=deliverThroughNeoWrapper}={}){
|
|
79
|
+
const receipt=await deliver(request);
|
|
80
|
+
if(receipt?.stored!==true||receipt.requestId!==request.id)
|
|
81
|
+
throw Error('Neo preview wrapper did not acknowledge durable delivery');
|
|
82
|
+
return receipt;
|
|
76
83
|
}
|
|
77
84
|
|
|
78
85
|
export async function runMobilePreview(argv){
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
+
#markcut-questions{background:#fff;color:#17202a}
|
|
2
|
+
#markcut-questions textarea{background:#fff;color:#17202a}
|
|
3
|
+
@media(prefers-color-scheme:dark){#markcut-questions{background:#161b22;color:#f2f5fb}#markcut-questions textarea{background:#242b36;color:#f2f5fb}}
|
|
4
|
+
/* The MCP iframe can be very short even when its card is wide on desktop.
|
|
5
|
+
* Never derive DESKTOP canvas width from iframe viewport height: it reduces a
|
|
6
|
+
* 1:1 model to ~300px in a wide review card. Limit the longest video dimension
|
|
7
|
+
* to 760px, with CSS aspect-ratio maintaining the source video proportions. */
|
|
8
|
+
#remotion-preview { display:flex; flex-direction:column; min-width:0; }
|
|
9
|
+
#remotion-canvas {
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
width: min(100%, calc(760px * var(--markcut-player-ratio, 0.5625)));
|
|
12
|
+
max-width: 760px;
|
|
13
|
+
flex: 0 0 auto;
|
|
14
|
+
}
|
|
15
|
+
|
|
1
16
|
/* ChatGPT MCP iframe on phones: keep scenes, video controls and review actions
|
|
2
17
|
* in separate normal-flow rows. Never position the footer over the player. */
|
|
3
|
-
@media (max-width: 640px), (max-height: 520px) {
|
|
18
|
+
@media (max-width: 640px), (max-width: 900px) and (max-height: 520px) {
|
|
4
19
|
html, body { min-width: 0; width: 100%; overflow-x: hidden; }
|
|
5
20
|
main { box-sizing: border-box; width: 100%; padding: 8px 10px 12px; }
|
|
6
21
|
main > header { flex-wrap: wrap; gap: 4px 8px; min-width: 0; padding-bottom: 4px; }
|
|
@@ -10,14 +25,12 @@
|
|
|
10
25
|
flex-wrap: wrap; justify-content: flex-end; }
|
|
11
26
|
#review-delivery-mode, #player-version { font-size: 11px !important; }
|
|
12
27
|
#remotion-preview { display: flex; flex-direction: column; min-width: 0; }
|
|
13
|
-
/*
|
|
14
|
-
|
|
15
|
-
|
|
28
|
+
/* Narrow phones and short, narrow landscape embeds limit height through
|
|
29
|
+
proportional WIDTH, not max-height (which clips native Remotion controls).
|
|
30
|
+
Square videos still use almost the whole available phone width. */
|
|
16
31
|
#remotion-canvas {
|
|
17
|
-
|
|
18
|
-
width:
|
|
19
|
-
max-height: min(58dvh, 440px) !important;
|
|
20
|
-
flex: 0 0 auto;
|
|
32
|
+
width: min(100%, calc(min(76dvh, 520px) * var(--markcut-player-ratio, 0.5625)));
|
|
33
|
+
max-width: 100%;
|
|
21
34
|
overflow: visible;
|
|
22
35
|
}
|
|
23
36
|
#scene-thumbnails { order: 0; min-width: 0; max-width: 100%; gap: 6px;
|
package/src/mcp/preview.mjs
CHANGED
|
@@ -1,63 +1,26 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { mkdir, writeFile, readdir, rename, rm, stat, utimes } from "node:fs/promises";
|
|
3
3
|
import { access, readFile } from "node:fs/promises";
|
|
4
|
-
import { constants as fsConstants, readFileSync } from "node:fs";
|
|
4
|
+
import { constants as fsConstants, readFileSync, existsSync } from "node:fs";
|
|
5
5
|
import { isAbsolute, extname, dirname, resolve, basename } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { buildPreviewBridgeScript } from "./bridge.mjs";
|
|
8
|
-
import { externalizePreviewMedia, publicOrigin, resolveMountedFile, resolvePreviewPath, publishPlayerBundle, publishCompiledCache, prunePublishedCache, EXPORT_ROOT } from "./remote-assets.mjs";
|
|
8
|
+
import { externalizePreviewMedia, publicOrigin, resolveMountedFile, resolvePreviewPath, publishPlayerBundle, publishCompiledCache, prunePublishedCache, versionPreviewMedia, EXPORT_ROOT } from "./remote-assets.mjs";
|
|
9
9
|
import {fingerprintInputs} from "./source-fingerprint.mjs";
|
|
10
|
+
import {loadEditorDecision,editorDecisionToMarkdown} from "../editor-decision/index.mjs";
|
|
10
11
|
|
|
11
12
|
export const TOOL_NAME = "markcut.preview";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
//
|
|
13
|
+
// One source of truth for preview resources. Every historical version (and
|
|
14
|
+
// the versionless alias) serves the same current UI and player bundle.
|
|
15
|
+
// Increment the version only to bypass clients that cache an already-open UI.
|
|
16
|
+
export const PREVIEW_VERSION_NUMBER = 56;
|
|
17
|
+
export const RESOURCE_URI = `ui://markcut/video-preview-v${PREVIEW_VERSION_NUMBER}.html`;
|
|
18
|
+
export const STABLE_RESOURCE_URI = "ui://markcut/video-preview.html";
|
|
19
|
+
const PREVIEW_VERSION = `v${PREVIEW_VERSION_NUMBER}`;
|
|
15
20
|
export const LEGACY_RESOURCE_URIS = [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"ui://markcut/video-preview-v44.html",
|
|
20
|
-
"ui://markcut/video-preview-v3.html",
|
|
21
|
-
"ui://markcut/video-preview-v4.html",
|
|
22
|
-
"ui://markcut/video-preview-v5.html",
|
|
23
|
-
"ui://markcut/video-preview-v6.html",
|
|
24
|
-
"ui://markcut/video-preview-v7.html",
|
|
25
|
-
"ui://markcut/video-preview-v8.html",
|
|
26
|
-
"ui://markcut/video-preview-v9.html",
|
|
27
|
-
"ui://markcut/video-preview-v10.html",
|
|
28
|
-
"ui://markcut/video-preview-v11.html",
|
|
29
|
-
"ui://markcut/video-preview-v12.html",
|
|
30
|
-
"ui://markcut/video-preview-v13.html",
|
|
31
|
-
"ui://markcut/video-preview-v14.html",
|
|
32
|
-
"ui://markcut/video-preview-v15.html",
|
|
33
|
-
"ui://markcut/video-preview-v16.html",
|
|
34
|
-
"ui://markcut/video-preview-v17.html",
|
|
35
|
-
"ui://markcut/video-preview-v18.html",
|
|
36
|
-
"ui://markcut/video-preview-v19.html",
|
|
37
|
-
"ui://markcut/video-preview-v20.html",
|
|
38
|
-
"ui://markcut/video-preview-v21.html",
|
|
39
|
-
"ui://markcut/video-preview-v22.html",
|
|
40
|
-
"ui://markcut/video-preview-v23.html",
|
|
41
|
-
"ui://markcut/video-preview-v24.html",
|
|
42
|
-
"ui://markcut/video-preview-v25.html",
|
|
43
|
-
"ui://markcut/video-preview-v26.html",
|
|
44
|
-
"ui://markcut/video-preview-v27.html",
|
|
45
|
-
"ui://markcut/video-preview-v28.html",
|
|
46
|
-
"ui://markcut/video-preview-v29.html",
|
|
47
|
-
"ui://markcut/video-preview-v30.html",
|
|
48
|
-
"ui://markcut/video-preview-v31.html",
|
|
49
|
-
"ui://markcut/video-preview-v32.html",
|
|
50
|
-
"ui://markcut/video-preview-v33.html",
|
|
51
|
-
"ui://markcut/video-preview-v34.html",
|
|
52
|
-
"ui://markcut/video-preview-v35.html",
|
|
53
|
-
"ui://markcut/video-preview-v36.html",
|
|
54
|
-
"ui://markcut/video-preview-v37.html",
|
|
55
|
-
"ui://markcut/video-preview-v40.html",
|
|
56
|
-
"ui://markcut/video-preview-v41.html",
|
|
57
|
-
"ui://markcut/video-preview-v42.html",
|
|
58
|
-
"ui://markcut/video-preview-v43.html",
|
|
59
|
-
"ui://markcut/video-preview-v39.html",
|
|
60
|
-
"ui://markcut/video-preview-v38.html",
|
|
21
|
+
STABLE_RESOURCE_URI,
|
|
22
|
+
...Array.from({length: PREVIEW_VERSION_NUMBER - 1}, (_, index) =>
|
|
23
|
+
`ui://markcut/video-preview-v${index + 1}.html`),
|
|
61
24
|
];
|
|
62
25
|
export const RESOURCE_MIME_TYPE = "text/html;profile=mcp-app";
|
|
63
26
|
// Google Maps JS loads libraries, tiles and Routes RPCs from these HTTPS origins.
|
|
@@ -84,7 +47,17 @@ const KEEP = 10;
|
|
|
84
47
|
export function getPreviewMedia(contentHash) {
|
|
85
48
|
if (!/^[a-f0-9]{64}$/.test(contentHash)) throw new Error("Invalid Markcut content hash");
|
|
86
49
|
try {
|
|
87
|
-
|
|
50
|
+
const compiled=versionPreviewMedia(JSON.parse(readFileSync(resolve(EXPORT_ROOT,"cache",contentHash+".json"),"utf8")));
|
|
51
|
+
// A preview may include its independent, playable editorial-decision tree.
|
|
52
|
+
// The existing app-only media tool returns both trees; no extra MCP tool.
|
|
53
|
+
const sidecar=resolve(EXPORT_ROOT,"cache",contentHash+".editor-decisions.json");
|
|
54
|
+
const editorDecisions=existsSync(sidecar)
|
|
55
|
+
? versionPreviewMedia(JSON.parse(readFileSync(sidecar,"utf8"))) : null;
|
|
56
|
+
const variantsFile=resolve(EXPORT_ROOT,"cache",contentHash+".variants.json");
|
|
57
|
+
const variants=existsSync(variantsFile)
|
|
58
|
+
? Object.fromEntries(Object.entries(JSON.parse(readFileSync(variantsFile,"utf8")))
|
|
59
|
+
.map(([name,tree])=>[name,versionPreviewMedia(tree)])) : null;
|
|
60
|
+
return {compiled,...(variants?{variants}:{}),...(editorDecisions?{editorDecisions}:{})};
|
|
88
61
|
} catch {throw new Error("Unknown or expired Markcut compiled scenes");}
|
|
89
62
|
}
|
|
90
63
|
|
|
@@ -191,7 +164,7 @@ export async function ensureVideoPreview(path, options = {}) {
|
|
|
191
164
|
if(pendingCompiles.has(key))return pendingCompiles.get(key);
|
|
192
165
|
const prior=activeCompilesByPath.get(validatedPath)||Promise.resolve();
|
|
193
166
|
const task=prior.catch(()=>{}).then(async()=>{
|
|
194
|
-
const {parseMarkdownDescriptive,resolveAll,compileDescriptiveRoot}=await import("../player/pipeline.mjs");
|
|
167
|
+
const {parseMarkdownDescriptive,parseMarkdownVariants,resolveVariantOverrides,resolveAll,compileDescriptiveRoot}=await import("../player/pipeline.mjs");
|
|
195
168
|
const report=typeof options.onProgress==="function" ? options.onProgress : ()=>{};
|
|
196
169
|
report("checking-cache");
|
|
197
170
|
const baseDir=dirname(validatedPath);
|
|
@@ -201,6 +174,7 @@ export async function ensureVideoPreview(path, options = {}) {
|
|
|
201
174
|
const cacheDir=resolve(outputRoot,"cache");
|
|
202
175
|
const indexFile=resolve(dir,"cache-index.json");
|
|
203
176
|
const audio=await readPreviewAudio(validatedPath);
|
|
177
|
+
const sidecar=loadEditorDecision(validatedPath,source);
|
|
204
178
|
const referencedAssets=input.assets;
|
|
205
179
|
referencedAssets.sort((a,b)=>String(a[0]).localeCompare(String(b[0])));
|
|
206
180
|
// Compilation generates random scene ids. Identity must be based on inputs,
|
|
@@ -242,16 +216,80 @@ export async function ensureVideoPreview(path, options = {}) {
|
|
|
242
216
|
});
|
|
243
217
|
report("freezing-preview-assets");
|
|
244
218
|
const external=externalizePreviewMedia(footage.compiled,id,publicOrigin(),baseDir);
|
|
245
|
-
finalCompiled=external.compiled;
|
|
219
|
+
finalCompiled=versionPreviewMedia(external.compiled);
|
|
246
220
|
await mkdir(cacheDir,{recursive:true});
|
|
247
221
|
try {await writeFile(cached,JSON.stringify(finalCompiled,null,2),{flag:"wx"});}
|
|
248
222
|
catch(error){if(error.code!=="EEXIST")throw error;}
|
|
249
223
|
}
|
|
224
|
+
// Source identities are immutable, but transport routes can improve (for
|
|
225
|
+
// example, a later version adds preview proxies to old /files/ URLs).
|
|
226
|
+
// Publish a new immutable transport variant when the scene tree changes.
|
|
227
|
+
finalCompiled=versionPreviewMedia(finalCompiled);
|
|
250
228
|
const currentSource=await readFile(validatedPath,"utf8");
|
|
251
229
|
const current=fingerprintInputs(validatedPath,Buffer.from(currentSource));
|
|
252
230
|
const currentHash=createHash("sha256").update(current.source).update("\0").update(JSON.stringify(current.assets)).digest("hex");
|
|
253
231
|
if(currentHash!==sourceHash)
|
|
254
232
|
throw new Error("Source changed during compilation; retry preview");
|
|
233
|
+
// Publish every named Markdown variant alongside Original. These use the
|
|
234
|
+
// same native override semantics as the local Previewer's --variant path.
|
|
235
|
+
// They are ordinary playable videos, not separate markdown documents.
|
|
236
|
+
const parsedVariants=parseMarkdownVariants(source);
|
|
237
|
+
const variantTrees=Object.create(null);
|
|
238
|
+
for(const [name,rootConfig] of parsedVariants.variants){
|
|
239
|
+
// Only genuine named headings are variants; reject accidentally parsed
|
|
240
|
+
// source text such as a literal backslash-n embedded in an H1.
|
|
241
|
+
if(!/^[\p{L}\p{N}][\p{L}\p{N}_-]{0,63}$/u.test(name))continue;
|
|
242
|
+
if(["default","editor-decisions","__proto__","constructor","prototype"].includes(name))
|
|
243
|
+
throw new Error("Reserved Markcut video variant name: "+name);
|
|
244
|
+
const {children:_unused,...overrides}=rootConfig;
|
|
245
|
+
const authored={...parsedVariants.base,...overrides};
|
|
246
|
+
const descriptive=resolveVariantOverrides(authored,[name]);
|
|
247
|
+
report("compiling-variant:"+name);
|
|
248
|
+
const resolved=await resolveAll(descriptive,{
|
|
249
|
+
sourcePath:validatedPath,baseDir,
|
|
250
|
+
seed:parseInt(sourceHash.slice(0,8),16),
|
|
251
|
+
scriptOutputDir:resolve(generated,"tts"),
|
|
252
|
+
mediaOutputDir:resolve(generated,"media"),
|
|
253
|
+
includeOutputDir:resolve(generated,"includes"),
|
|
254
|
+
variants:[name],
|
|
255
|
+
});
|
|
256
|
+
const built=compileDescriptiveRoot(resolved,{googleMapsApiKey:process.env.GOOGLE_MAPS_API_KEY});
|
|
257
|
+
const mixed=withPreviewAudio(built,audio.audioSrc);
|
|
258
|
+
const {renderMapFootage}=await import("./map-footage.mjs");
|
|
259
|
+
const footage=await renderMapFootage(mixed,{
|
|
260
|
+
generatedDir:resolve(generated,"map-footage",id+"-"+createHash("sha256").update(name).digest("hex").slice(0,12)),
|
|
261
|
+
key:process.env.GOOGLE_MAPS_API_KEY,onProgress:report,
|
|
262
|
+
});
|
|
263
|
+
const published=externalizePreviewMedia(footage.compiled,id,publicOrigin(),baseDir);
|
|
264
|
+
variantTrees[name]=versionPreviewMedia(published.compiled);
|
|
265
|
+
}
|
|
266
|
+
if(Object.keys(variantTrees).length){
|
|
267
|
+
await mkdir(resolve(EXPORT_ROOT,"cache"),{recursive:true});
|
|
268
|
+
await atomicJson(resolve(EXPORT_ROOT,"cache",hash+".variants.json"),variantTrees);
|
|
269
|
+
}
|
|
270
|
+
// The Editor Decision view is a separate real Markcut compilation, sharing
|
|
271
|
+
// the same source footage but never replacing the authoritative video tree.
|
|
272
|
+
let edlCompiledUrl;
|
|
273
|
+
if(sidecar){
|
|
274
|
+
report("compiling-editor-decisions");
|
|
275
|
+
const edlMd=editorDecisionToMarkdown(validatedPath,sidecar.edl,source);
|
|
276
|
+
const edlInput=parseMarkdownDescriptive(edlMd);
|
|
277
|
+
const edlResolved=await resolveAll(edlInput,{
|
|
278
|
+
sourcePath:validatedPath,baseDir,seed:parseInt(sourceHash.slice(0,8),16),
|
|
279
|
+
scriptOutputDir:resolve(generated,"tts"),
|
|
280
|
+
mediaOutputDir:resolve(generated,"media"),
|
|
281
|
+
includeOutputDir:resolve(generated,"includes"),
|
|
282
|
+
});
|
|
283
|
+
const edlTree=compileDescriptiveRoot(edlResolved,{googleMapsApiKey:process.env.GOOGLE_MAPS_API_KEY});
|
|
284
|
+
const edlPublished=externalizePreviewMedia(edlTree,id,publicOrigin(),baseDir);
|
|
285
|
+
const edlFrozen=versionPreviewMedia(edlPublished.compiled);
|
|
286
|
+
// Content-addressed output is for immutable preview storage only.
|
|
287
|
+
// No EDL/video version-fingerprint comparison or synchronization gate.
|
|
288
|
+
const edlHash=createHash("sha256").update(hash).update(JSON.stringify(sidecar.edl)).digest("hex");
|
|
289
|
+
edlCompiledUrl=publishCompiledCache(edlHash,edlFrozen);
|
|
290
|
+
await mkdir(cacheDir,{recursive:true});
|
|
291
|
+
await atomicJson(resolve(EXPORT_ROOT,"cache",hash+".editor-decisions.json"),edlFrozen);
|
|
292
|
+
}
|
|
255
293
|
await mkdir(dir,{recursive:true});
|
|
256
294
|
report("publishing-static-preview");
|
|
257
295
|
// Static publication is completed before updating the latest pointer.
|
|
@@ -261,7 +299,7 @@ export async function ensureVideoPreview(path, options = {}) {
|
|
|
261
299
|
await pruneCache(cacheDir,indexFile,index.entries||[],hash);
|
|
262
300
|
const preview={
|
|
263
301
|
id,revisionId:id,contentHash:hash,sourceHash,path:validatedPath,
|
|
264
|
-
compiledUrl, resourceUri:RESOURCE_URI,
|
|
302
|
+
compiledUrl, ...(edlCompiledUrl ? {edlCompiledUrl} : {}), resourceUri:RESOURCE_URI,
|
|
265
303
|
assetBaseUrl:publicOrigin()+"/files/_neoy/markcut/generated/"+id+"/",
|
|
266
304
|
};
|
|
267
305
|
return preview;
|
|
@@ -286,10 +324,12 @@ export function buildPreviewHtml() {
|
|
|
286
324
|
<style>body{font:14px system-ui;margin:0;background:#fff;color:#17202a}main{padding:12px;max-width:960px;margin:auto}h1{font-size:17px}.path{font-size:12px;overflow-wrap:anywhere}.transport{display:flex;align-items:center;gap:10px;padding:12px 0}.transport input{flex:1;min-width:50px}button{cursor:pointer;padding:8px;border-radius:6px;border:1px solid #a8a8a8}#approve{background:#198038;color:white}#changes{background:#c72b29;color:white}#comment-entry{display:flex;align-items:center;gap:6px;margin:5px 0}#feedback{flex:1;min-width:0;box-sizing:border-box;height:34px;padding:6px 9px;border:1px solid #b5bdc8;border-radius:6px}#comment-mode{max-width:102px;height:34px;border:1px solid #b5bdc8;border-radius:6px;background:white}#save-spot,#remove-spot{width:34px;height:34px;padding:0;font-size:19px}#comment-entry button:disabled{opacity:.4;cursor:default}.review-actions{display:flex;justify-content:space-between;align-items:center;width:100%;gap:16px}.review-actions button{min-width:110px}#remotion-canvas{background:#090b12}#status{flex:1;min-width:0;font-size:12px;color:#526071;text-align:center;overflow-wrap:anywhere}#status:empty{display:none}#scene-thumbnails{display:flex;gap:7px;overflow-x:auto;padding:12px 2px;scrollbar-width:thin} .scene-pill{flex-shrink:0;padding:7px 11px;border:1px solid #d4dbe4;border-radius:9px;cursor:pointer;background:#f5f7fa;color:#475569;font-size:12px;white-space:nowrap} .scene-pill.active{background:#e7f0ff;color:#125ea2;border-color:#408bd7} .scene-pill.commented{border-color:#cc8b12;background:#fff4d6;color:#764900;font-weight:650} .scene-pill.commented::after{content:' •';color:#ad5b00} #comment-list{display:grid;gap:4px;margin:8px 0} #comment-list>div{display:flex;gap:8px} #comment-list button:first-child{flex:1;text-align:left;overflow:hidden;text-overflow:ellipsis} #comment-target{font-size:12px;color:#526071;margin:8px 0}</style>
|
|
287
325
|
<style>.comment-marker{position:absolute;top:50%;transform:translate(-50%,-50%);width:20px;height:20px;min-width:20px;padding:0;border:0;border-radius:50%;background:transparent;z-index:10;cursor:pointer;touch-action:none}.comment-marker::after{content:'';display:block;width:14px;height:14px;border-radius:50%;margin:auto;background:#f59e0b;border:2px solid white;box-sizing:border-box}.comment-marker.scope-scene::after{background:#3b82f6}.comment-marker.scope-overall{left:-28px!important}.comment-marker.scope-overall::after{background:#8b5cf6}.comment-marker.scope-overall.placeholder::after{background:transparent;border-color:#8b5cf6}.comment-marker.selected::after,.comment-marker:focus-visible::after{outline:2px solid #2563eb;outline-offset:2px}.comment-marker:hover::after{transform:scale(1.2)}</style>
|
|
288
326
|
<style>#comment-entry{position:relative;display:block}#feedback{display:block;width:100%;height:auto;min-height:76px;max-height:240px;field-sizing:content;resize:none;padding:9px 112px 32px 9px;font:inherit}#comment-tools{position:absolute;bottom:6px;right:8px;display:flex;align-items:center;gap:2px;background:white}#comment-tools>*{width:30px;height:28px;padding:0;border:0;background:transparent;color:#526071;font:inherit;text-align:center}#comment-tools button{font-size:20px}#comment-tools>*:focus-visible{outline:2px solid #408bd7;outline-offset:-2px}#comment-mode{width:70px;max-width:none;font-size:12px;font-weight:650;text-align:center;text-align-last:center;line-height:28px}#comment-mode:has(option[value=spot]:checked){color:#b45309}#comment-mode:has(option[value=scene]:checked){color:#2563eb}#overall-mode{width:70px;height:28px;line-height:28px;text-align:center;font-size:12px;font-weight:650;color:#7c3aed}</style>
|
|
289
|
-
<style>${readFileSync(resolve(moduleDir,'preview-mobile.css'),'utf8')}</style>
|
|
290
|
-
|
|
327
|
+
<style>${readFileSync(resolve(moduleDir,'preview-mobile.css'),'utf8').replace(/\/\*[\s\S]*?\*\//g,'')}</style>
|
|
328
|
+
<style>body.markcut-design-mode #approve,body.markcut-design-mode #changes,body.markcut-design-mode #questions-submit{display:none!important}
|
|
329
|
+
body.markcut-design-mode .review-actions{justify-content:center}body.markcut-design-mode #status{font-weight:500}</style>
|
|
330
|
+
</head><body><main><header style="display:flex;justify-content:space-between;align-items:center"><h1>Markcut · <span id="video-md-version">video</span></h1><div style="display:flex;align-items:center;gap:14px;margin-left:auto"><span id="header-tts"></span><span id="markcut-video-selector-slot"></span><span id="player-version" style="font-size:12px;color:#667">${PREVIEW_VERSION}</span></div></header><div class="path" id="path-label" hidden></div><div id="interactive-ui" hidden><div id="remotion-root"></div>
|
|
291
331
|
<div id="comment-entry"><textarea id="feedback" rows="3" aria-label="Feedback" placeholder="Add a comment…"></textarea><div id="comment-tools"><select id="comment-mode" aria-label="Comment scope" title="Comment scope"><option value="spot" style="color:#b45309">Spot</option><option value="scene" style="color:#2563eb">Scene</option></select><span id="overall-mode" hidden>Overall</span><button id="save-spot" type="button" title="Add or update comment" aria-label="Add or update comment">+</button><button id="remove-spot" type="button" title="Remove selected comment" aria-label="Remove selected comment" disabled>−</button></div></div>
|
|
292
|
-
<div class="review-actions"><button id="changes">Submit feedback</button><span id="status" role="status">Starting preview…</span><button id="approve">Approve</button></div></div></main>
|
|
332
|
+
<div class="review-actions"><button id="questions-submit" type="button" hidden>Submit</button><button id="changes">Submit feedback</button><span id="status" role="status">Starting preview…</span><button id="approve">Approve</button></div></div></main>
|
|
293
333
|
<script src="${playerScriptUrl}"></script>
|
|
294
334
|
<script>${buildPreviewBridgeScript().replaceAll("__MARKCUT_ORIGIN__",JSON.stringify(publicOrigin()))}</script></body></html>`;
|
|
295
335
|
}
|
|
@@ -72,6 +72,75 @@ export function publishPlayerBundle(bundlePath, origin=publicOrigin()) {
|
|
|
72
72
|
return origin+"/files/_neoy/markcut/player/"+filename;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
// Preview media URLs are a transport view, not the authored Markdown source.
|
|
76
|
+
// Include a stable revision of the source file in their cache key. A CDN may
|
|
77
|
+
// otherwise keep serving an old large original after the Master activates a
|
|
78
|
+
// smaller preview proxy under the same mounted source path.
|
|
79
|
+
export function versionPreviewMedia(compiled, origin=publicOrigin(), mountedRoots=null, exportRoot=EXPORT_ROOT) {
|
|
80
|
+
const prefix=origin+"/preview-files/";
|
|
81
|
+
const originalPrefix=origin+"/files/";
|
|
82
|
+
let mounts=mountedRoots;
|
|
83
|
+
if(!mounts)try{mounts=JSON.parse(readFileSync(join(supportDir,"file-mounts.json"),"utf8"));}catch{mounts={};}
|
|
84
|
+
const versioned=(value)=>{
|
|
85
|
+
if(typeof value!=="string"||(!value.startsWith(prefix)&&!value.startsWith(originalPrefix)))return value;
|
|
86
|
+
let url;
|
|
87
|
+
try {url=new URL(value);}catch{return value;}
|
|
88
|
+
if(url.origin!==origin)return value;
|
|
89
|
+
// Old previews and generated snapshots used regular /files/ URLs, which
|
|
90
|
+
// bypassed the proxy entirely. Redirect only real video source URLs;
|
|
91
|
+
// /files/ still returns the original outside the Markcut preview tree.
|
|
92
|
+
if(url.pathname.startsWith("/files/")){
|
|
93
|
+
if(!/\.(?:mp4|mov|m4v|webm|png|jpe?g|heic|webp)$/i.test(url.pathname))return value;
|
|
94
|
+
const mount=url.pathname.slice("/files/".length).split("/")[0];
|
|
95
|
+
const generated=url.pathname.startsWith("/files/_neoy/markcut/generated/");
|
|
96
|
+
if(!generated && (mount==="_neoy" || typeof mounts[mount]!=="string"))return value;
|
|
97
|
+
url.pathname="/preview-files/"+url.pathname.slice("/files/".length);
|
|
98
|
+
}
|
|
99
|
+
if(!url.pathname.startsWith("/preview-files/"))return value;
|
|
100
|
+
const parts=url.pathname.slice("/preview-files/".length).split("/");
|
|
101
|
+
let mount,relative;
|
|
102
|
+
try {[mount,...relative]=parts.map(decodeURIComponent);}catch{return value;}
|
|
103
|
+
let fingerprint="unmounted";
|
|
104
|
+
if(/^[A-Za-z0-9_-]{1,64}$/.test(mount) && relative.length &&
|
|
105
|
+
relative.every(s=>s&&!s.startsWith(".")&&s!==".."&&!s.includes("/")&&!s.includes("\\"))){
|
|
106
|
+
try{
|
|
107
|
+
let root, pathParts;
|
|
108
|
+
if(mount==="_neoy" && relative[0]==="markcut" && relative[1]==="generated" && relative.length>=4){
|
|
109
|
+
root=realpathSync(join(exportRoot,"generated"));
|
|
110
|
+
pathParts=relative.slice(2);
|
|
111
|
+
} else if(mount!=="_neoy" && typeof mounts[mount]==="string"){
|
|
112
|
+
root=realpathSync(mounts[mount]);
|
|
113
|
+
pathParts=relative;
|
|
114
|
+
}
|
|
115
|
+
if(root && pathParts){
|
|
116
|
+
const source=realpathSync(resolve(root,...pathParts));
|
|
117
|
+
if(source.startsWith(root+sep)){
|
|
118
|
+
const stats=statSync(source);
|
|
119
|
+
fingerprint=`${stats.size}:${stats.mtimeMs}`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}catch{}
|
|
123
|
+
}
|
|
124
|
+
const version=createHash("sha256").update("markcut-preview-proxy-v2\0")
|
|
125
|
+
.update(url.pathname).update("\0").update(fingerprint).digest("hex").slice(0,16);
|
|
126
|
+
url.searchParams.set("pv",version);
|
|
127
|
+
return url.href;
|
|
128
|
+
};
|
|
129
|
+
const walk=(value)=>{
|
|
130
|
+
if(typeof value==="string"){
|
|
131
|
+
if(value.includes("<video") && value.includes("src=")){
|
|
132
|
+
return value.replace(/(\bsrc\s*=\s*)(['"])(https:\/\/[^'"\n]+)\2/g,
|
|
133
|
+
(all,prefix,quote,uri)=>prefix+quote+versioned(uri)+quote);
|
|
134
|
+
}
|
|
135
|
+
return versioned(value);
|
|
136
|
+
}
|
|
137
|
+
if(Array.isArray(value))return value.map(walk);
|
|
138
|
+
if(value&&typeof value==="object")return Object.fromEntries(Object.entries(value).map(([k,v])=>[k,walk(v)]));
|
|
139
|
+
return value;
|
|
140
|
+
};
|
|
141
|
+
return walk(compiled);
|
|
142
|
+
}
|
|
143
|
+
|
|
75
144
|
export function resolvePreviewSource(src,sourceDir,origin=publicOrigin(),mounts=null) {
|
|
76
145
|
if(src.startsWith("data:"))return src;
|
|
77
146
|
if(src.startsWith("https://"))return src;
|
|
@@ -91,9 +160,9 @@ export function externalizePreviewMedia(compiled,revisionId,origin=publicOrigin(
|
|
|
91
160
|
let bytes=0;
|
|
92
161
|
const frozenPaths=new Map();
|
|
93
162
|
function snapshotSource(src){
|
|
94
|
-
if(!sourceDir||src.startsWith("https://")||src.startsWith("data:"))return src;
|
|
95
163
|
if(src.startsWith("http://")||src.startsWith("blob:"))
|
|
96
164
|
throw new Error("Preview media must use HTTPS or local source files");
|
|
165
|
+
if(!sourceDir||src.startsWith("https://")||src.startsWith("data:"))return src;
|
|
97
166
|
const full=src.startsWith("file://")?fileURLToPath(src):isAbsolute(src)?src:resolve(sourceDir,src);
|
|
98
167
|
const root=realpathSync(sourceDir);
|
|
99
168
|
let real;
|
|
@@ -102,7 +171,7 @@ export function externalizePreviewMedia(compiled,revisionId,origin=publicOrigin(
|
|
|
102
171
|
if(frozenPaths.has(real))return frozenPaths.get(real);
|
|
103
172
|
// Dedicated preview route lets NeoY reuse Visioner proxies without changing video.md.
|
|
104
173
|
// If no proxy exists, NeoY serves the original media at the same preview URL.
|
|
105
|
-
if(/\.(mov|mp4|webm)$/i.test(real)) {
|
|
174
|
+
if(/\.(mov|mp4|m4v|webm|png|jpe?g|heic|webp)$/i.test(real)) {
|
|
106
175
|
const mounted=resolveMountedFile(real,origin);
|
|
107
176
|
if(mounted) {
|
|
108
177
|
const previewUrl=mounted.replace(origin+"/files/",origin+"/preview-files/");
|
|
@@ -113,7 +182,7 @@ export function externalizePreviewMedia(compiled,revisionId,origin=publicOrigin(
|
|
|
113
182
|
const stats=statSync(real);
|
|
114
183
|
if(!stats.isFile()||stats.size>512*1024*1024)throw new Error("Preview local media must be a file of at most 512 MB");
|
|
115
184
|
const ext=extname(real).toLowerCase();
|
|
116
|
-
if(!/^[.](png|jpg|jpeg|webp|svg|gif|mp4|mov|webm|wav|mp3|m4a|ogg|vtt|srt)$/.test(ext))
|
|
185
|
+
if(!/^[.](png|jpg|jpeg|webp|svg|gif|mp4|mov|webm|wav|mp3|m4a|ogg|vtt|srt|glb)$/.test(ext))
|
|
117
186
|
throw new Error("Unsupported local preview media extension: "+ext);
|
|
118
187
|
mkdirSync(directory,{recursive:true});
|
|
119
188
|
const filename="file-"+frozenPaths.size+ext;
|
|
@@ -179,17 +248,26 @@ export function publishCompiledCache(hash, compiled, origin=publicOrigin()) {
|
|
|
179
248
|
if(!/^[a-f0-9]{64}$/.test(hash))throw new Error("Invalid compiled hash");
|
|
180
249
|
const dir=join(EXPORT_ROOT,"cache");
|
|
181
250
|
mkdirSync(dir,{recursive:true});
|
|
182
|
-
const file=join(dir,hash+".json");
|
|
183
251
|
const bytes=JSON.stringify(compiled);
|
|
252
|
+
const canonical=join(dir,hash+".json");
|
|
253
|
+
// An old immutable revision may reference the pre-proxy scene tree. Never
|
|
254
|
+
// overwrite it: publish a content-addressed transport variant instead.
|
|
255
|
+
const suffix=existsSync(canonical) && readFileSync(canonical,"utf8")!==bytes
|
|
256
|
+
? "-"+createHash("sha256").update(bytes).digest("hex").slice(0,16) : "";
|
|
257
|
+
const filename=hash+suffix+".json";
|
|
258
|
+
const file=join(dir,filename);
|
|
184
259
|
if(existsSync(file)){
|
|
185
260
|
if(readFileSync(file,"utf8")!==bytes)throw new Error("Immutable compiled cache collision");
|
|
186
261
|
}else writeFileSync(file,bytes,{flag:"wx",mode:0o644});
|
|
187
|
-
return origin+"/files/_neoy/markcut/cache/"+
|
|
262
|
+
return origin+"/files/_neoy/markcut/cache/"+filename;
|
|
188
263
|
}
|
|
189
264
|
|
|
190
265
|
export async function prunePublishedCache(hash) {
|
|
191
266
|
if(!/^[a-f0-9]{64}$/.test(hash))throw new Error("Invalid compiled hash");
|
|
192
|
-
const {rm}=await import("node:fs/promises");
|
|
193
|
-
|
|
267
|
+
const {rm,readdir}=await import("node:fs/promises");
|
|
268
|
+
const cache=join(EXPORT_ROOT,"cache");
|
|
269
|
+
const variants=(await readdir(cache).catch(()=>[])).filter(name=>
|
|
270
|
+
name===hash+".json" || new RegExp("^"+hash+"-[a-f0-9]{16}\\.json$").test(name));
|
|
271
|
+
await Promise.all(variants.map(name=>rm(join(cache,name),{force:true})));
|
|
194
272
|
await rm(join(EXPORT_ROOT,"generated",hash),{recursive:true,force:true});
|
|
195
273
|
}
|