flash-story-app 1.1.0 → 1.2.0
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/dist/cli.js +2 -1
- package/dist/serve.js +1 -1
- package/package.json +1 -1
- package/static/assets/index-CQc1DOJq.js +5496 -0
- package/static/index.html +1 -1
- package/static/assets/index-DeZBKepj.js +0 -5496
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{spawn as
|
|
2
|
+
import{spawn as b}from"node:child_process";import{mkdirSync as F,writeFileSync as $,readFileSync as P}from"node:fs";import{join as j}from"node:path";import{homedir as R}from"node:os";import{l as C}from"./env.js";class w extends Error{}async function E(e,t,r,o){const c=await fetch(`${e}${r}`,{method:t,headers:o!==void 0?{"content-type":"application/json"}:void 0,body:o!==void 0?JSON.stringify(o):void 0}),a=await c.json().catch(()=>null);return{status:c.status,data:a}}async function D(e,t,r){const o=await fetch(`${e}${r}`,{method:t});return{status:o.status,text:await o.text()}}async function A(e,t){const r=await fetch(`${e}${t}`);return{status:r.status,bytes:new Uint8Array(await r.arrayBuffer())}}function v(e,t){if(e.status>=200&&e.status<300)return e.data;const r=e.data?.detail??e.data?.error??`HTTP ${e.status}`;throw new w(`${t} failed: ${r}`)}const q={get:E,post:E,binary:A,text:D};function B(e){const t=[],r={};for(let o=0;o<e.length;o++){const c=e[o];if(c.startsWith("--")){const a=c.slice(2),s=e[o+1];s!==void 0&&!s.startsWith("--")?(r[a]=s,o+=1):r[a]=!0}else t.push(c)}return{positionals:t,flags:r}}function n(e,t){const r=e[t];return typeof r=="string"?r:void 0}function G(e){const t=n(e,"project");if(!t)throw new w("--project <id> is required");return t}function g(e,t){if(!e)throw new w(`--json <${t}> is required`);try{return JSON.parse(e)}catch{throw new w(`--json <${t}> is not valid JSON`)}}async function l(e,t,r,o,c=!1){const a=await e.post(t,"POST",c?"/api/tools/batch":"/api/tools/execute",{projectId:r,...c?{actions:o}:{action:o}});if(a.status===404)return{data:{error:"project not found"},exit:1};const s=a.data;return s.ok?{data:{ok:!0,rev:s.rev},exit:0}:{data:{ok:!1,error:s.error??"rejected"},exit:1}}const h=e=>e().catch(t=>({data:{error:t instanceof Error?t.message:String(t)},exit:1}));async function H(e,t,r=q){const[o,...c]=e,{positionals:a,flags:s}=B(c),p=()=>G(s);switch(o){case"health":return h(async()=>{const d=await r.get(t,"GET","/health");return{data:v(d,"health"),exit:0}});case"scene":{const d=a[0];if(d==="list")return h(async()=>{const i=await r.get(t,"GET","/api/projects");return{data:v(i,"list projects"),exit:0}});if(d==="get")return h(async()=>{const i=await r.get(t,"GET",`/api/projects/${p()}`);if(i.status===404)throw new w("project not found");return{data:i.data,exit:0}});throw f("flashstory scene list|get --project <id>")}case"entity":{const d=a[0],i=p(),u=n(s,"id"),m=n(s,"name");switch(d){case"add":return l(r,t,i,{type:"addEntity",entity:{...u?{id:u}:{},name:m??"未命名",kind:n(s,"kind")??"character",...n(s,"color")?{color:n(s,"color")}:{}}});case"remove":if(!u)throw f("--id is required");return l(r,t,i,{type:"removeEntity",id:u});case"update":{if(!u)throw f("--id is required");const x={};return m&&(x.name=m),n(s,"color")&&(x.color=n(s,"color")),n(s,"heightCm")&&(x.heightCm=Number(n(s,"heightCm"))),l(r,t,i,{type:"updateEntity",id:u,patch:x})}default:throw f("flashstory entity add|remove|update --project <id> [--id] [--name]")}}case"transform":if(a[0]!=="set"||!n(s,"id"))throw f("flashstory transform set --project --id --json <keys>");return l(r,t,p(),{type:"setTransformTrack",id:n(s,"id"),keys:g(n(s,"json"),"keys")});case"pose":{const d=a[0];if(d==="list")return h(async()=>{const i=await r.get(t,"GET",`/api/projects/${p()}`);if(i.status===404)throw new w("project not found");return{data:{customPoses:i.data.doc.customPoses??{}},exit:0}});if(d==="set-keys"){if(!n(s,"id"))throw f("--id is required");return l(r,t,p(),{type:"setPoseTrack",id:n(s,"id"),keys:g(n(s,"json"),"keys")})}throw f("flashstory pose list|set-keys --project --id --json")}case"camera":if(a[0]!=="set-keys")throw f("flashstory camera set-keys --project --json");return l(r,t,p(),{type:"setCameraTrack",keys:g(n(s,"json"),"keys")});case"settings":return l(r,t,p(),{type:"setSettings",patch:g(n(s,"json"),"patch")});case"marker":{const d=Number(n(s,"t")??NaN);if(a[0]!=="add"||!Number.isFinite(d))throw f("flashstory marker add --project --t <sec> --label <text>");return l(r,t,p(),{type:"addMarker",t:d,label:n(s,"label")??""})}case"batch":return l(r,t,p(),g(n(s,"json"),"actions"),!0);case"screenshot":return h(async()=>{const d=await r.post(t,"POST","/api/tools/screenshot",{projectId:p(),t:Number(n(s,"t")??0),camera:n(s,"camera")??"edit"}),i=v(d,"screenshot"),u=n(s,"out");if(i.kind==="image"&&u){const m=i.dataUrl?.split(",")[1];return m&&$(u,Buffer.from(m,"base64")),{data:{kind:"image",saved:u},exit:0}}return{data:i,exit:0}});case"export":{const d=a[0],i=a[1];switch(d){case"submit":return h(async()=>{const u=await r.post(t,"POST","/api/export",{projectId:p(),includeVideo:s["no-video"]!==!0,includeStills:s.stills===!0});return{data:v(u,"export submit"),exit:0}});case"status":if(!i)throw f("usage: flashstory export status <exportId>");return h(async()=>{const u=await r.get(t,"GET",`/api/export/${i}`);if(u.status===404)throw new w("export not found");return{data:u.data,exit:0}});case"result":if(!i)throw f("usage: flashstory export result <exportId> --out <dir>");return h(async()=>{const u=n(s,"out")??"exports";F(u,{recursive:!0});const x=((await r.get(t,"GET",`/api/export/${i}/files`)).data?.files??[]).filter(Boolean),S=[];for(const k of x){const T=await r.binary(t,`/api/export/${i}/files/${encodeURIComponent(k)}`);T.status===200&&($(j(u,k),T.bytes),S.push(j(u,k)))}return{data:{exportId:i,downloaded:S},exit:0}});case"cancel":if(!i)throw f("usage: flashstory export cancel <exportId>");return h(async()=>({data:(await r.post(t,"POST",`/api/export/${i}/cancel`,{})).data,exit:0}));default:throw f("flashstory export submit|status|result|cancel")}}default:throw f(`unknown command: ${o}`)}}function f(e){return new w(e)}const J="http://127.0.0.1:8787";function U(){return j(R(),".flashstory","config.json")}function L(){try{const e=P(U(),"utf8"),t=JSON.parse(e);return typeof t.server=="string"&&t.server?t.server:void 0}catch{return}}function _(e){return e??process.env.FLASHSTORY_SERVER??L()??J}function V(e){const t={},r=[];for(let o=0;o<e.length;o++){const c=e[o];switch(c){case"--server":t.server=e[o+1],o+=1;break;case"--port":t.port=Number(e[o+1]),o+=1;break;case"--host":t.host=e[o+1],o+=1;break;case"--data-dir":t.dataDir=e[o+1],o+=1;break;case"--open":t.open=!0;break;case"--no-open":t.noOpen=!0;break;default:r.push(c)}}return{flags:t,args:r}}function Y(e){return e.noOpen===!0?!1:e.open??!0}C();const{flags:y,args:N}=V(process.argv.slice(2)),O=N[0];if(!O||O==="serve"){const{startServer:e}=await import("./serve.js"),t={};y.port!==void 0&&Number.isFinite(y.port)&&(t.port=y.port),y.host&&(t.hostname=y.host),y.dataDir&&(t.dataDir=y.dataDir);const r=t.hostname??process.env.FLASHSTORY_HOST??"127.0.0.1",o=(t.port!==void 0&&Number.isFinite(t.port)?t.port:Number(process.env.FLASHSTORY_PORT??8787))||8787;let c;try{c=await e(t)}catch(a){console.error(a),process.exit(1)}c.on("error",a=>{a.code==="EADDRINUSE"?console.error(`端口 ${o} 已被占用 —— 可能旧版 FlashStory 仍在运行(旧版本不会包含新功能)。
|
|
3
|
+
请先停止旧进程,然后重新运行;或直接换端口:--port <n>`):console.error(a),process.exit(1)}),await new Promise(a=>{c.listening?a():c.once("listening",a)}),Y(y)&&W(`http://${r}:${o}/`)}else{const e=_(y.server),{data:t,exit:r}=await H(N,e);console.log(JSON.stringify(t)),process.exit(r)}function W(e){const t=process.platform,c=b(t==="darwin"?"open":t==="win32"?"cmd":"xdg-open",t==="win32"?["/c","start","",e]:[e],{stdio:"ignore",detached:!0});c.on("error",()=>{}),c.unref?.()}
|