@yuandc/aica 0.1.70 → 0.1.72
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{managementActivity as f}from"./management/activity.js";import{managedClaim as y}from"./management/claims.js";import c from"node:fs";import x from"node:os";import
|
|
1
|
+
import{managementActivity as f}from"./management/activity.js";import{managedClaim as y}from"./management/claims.js";import c from"node:fs";import x from"node:os";import o from"node:path";import{Readable as l}from"node:stream";import{acaServerRequest as u,acaServerStreamRequest as g}from"./aca-server-client.js";import{loadAcaConfig as b}from"./aca-config.js";import{expandWorkerRuntimePath as S}from"./worker-runtime-paths.js";import{startLongPollWorker as I}from"./long-poll-worker.js";import{openImageFile as j}from"./image-file-access.js";const d=25e3,v=d+1e4;function G(e){return I({run:async()=>{const t=b();if(!t.token)throw new Error("Worker 尚未配置认证令牌");const a=await y("file",()=>u("GET",`/api/client/file-requests/claim?machineId=${encodeURIComponent(t.machineId)}&waitMs=${d}`,void 0,{timeoutMs:v}));if(!a.item)return;const n=f.track("file");try{await E(a.item,t,e)}catch(i){const r=i instanceof Error?i.message:String(i);e.warn(`file request failed request=${a.item.requestId}: ${r}`);try{await R(a.item.requestId,r)}catch(s){f.uncertain.add("file-finalize"),e.warn(`file request fail callback failed request=${a.item.requestId}: ${s instanceof Error?s.message:String(s)}`)}}finally{n()}},onError:(t,a)=>e.warn(`file transfer worker failed, retry in ${a}ms: ${t instanceof Error?t.message:String(t)}`)})}async function R(e,t){await u("POST",`/api/client/file-requests/${encodeURIComponent(e)}/fail`,{message:t})}async function E(e,t,a){const n=t.projects.find(m=>m.projectId===e.projectId),i=h(e.projectRoot||n?.rootPath||"");if(e.purpose==="image-file"){const m=j(i,e.path,e.maxBytes);try{a.info(`streaming image request=${e.requestId} path=${m.path}`),await g("POST",`/api/client/file-requests/${encodeURIComponent(e.requestId)}/stream`,l.toWeb(m.stream),{"content-type":"application/octet-stream","x-aca-file-name":encodeURIComponent(o.basename(m.path)),"x-aca-file-size":String(m.sizeBytes),"x-aca-file-mime":m.mimeType})}finally{m.stream.destroy()}return}if(!i)throw new Error(`file request ${e.requestId} project root is unknown`);const r=e.purpose==="temp-image"?"temp-image":e.purpose==="project-preview"?"project-preview":"project-file",s=r==="temp-image"?F(e.path):$(i,e.path),p=c.statSync(s);if(!p.isFile())throw new Error(`file request ${e.requestId} target is not a file`);if(p.size>e.maxBytes)throw new Error(`file request ${e.requestId} target is too large (${p.size} bytes)`);const w=r==="temp-image"?k(s):L(s);a.info(`streaming file request=${e.requestId} path=${s}`),await g("POST",`/api/client/file-requests/${encodeURIComponent(e.requestId)}/stream`,l.toWeb(c.createReadStream(s)),{"content-type":"application/octet-stream","x-aca-file-name":encodeURIComponent(o.basename(s)),"x-aca-file-size":String(p.size),"x-aca-file-mime":w})}function $(e,t){const a=c.realpathSync(h(e)),n=o.isAbsolute(t)?t:o.join(a,t),i=c.realpathSync(n),r=o.relative(a,i);if(r===""||r.startsWith("..")||o.isAbsolute(r))throw new Error("requested file is outside project root");return i}function F(e){const t=T(e);if(!o.isAbsolute(t))throw new Error("temporary image path must be absolute");const a=c.lstatSync(t);if(a.isSymbolicLink())throw new Error("temporary image cannot be a symbolic link");if(!a.isFile())throw new Error("temporary image target is not a regular file");const n=c.realpathSync(x.tmpdir()),i=c.realpathSync(t),r=o.relative(n,i);if(r===""||r.startsWith("..")||o.isAbsolute(r))throw new Error("temporary image is outside the system temp directory");return i}function k(e){const t=o.extname(e).toLowerCase(),a=Buffer.alloc(16),n=c.openSync(e,"r");let i=0;try{i=c.readSync(n,a,0,a.length,0)}finally{c.closeSync(n)}const r=a.subarray(0,i);if(t===".png"&&r.length>=8&&r.subarray(0,8).equals(Buffer.from([137,80,78,71,13,10,26,10])))return"image/png";if([".jpg",".jpeg"].includes(t)&&r.length>=3&&r[0]===255&&r[1]===216&&r[2]===255)return"image/jpeg";if(t===".gif"&&r.length>=6&&["GIF87a","GIF89a"].includes(r.subarray(0,6).toString("ascii")))return"image/gif";if(t===".webp"&&r.length>=12&&r.subarray(0,4).toString("ascii")==="RIFF"&&r.subarray(8,12).toString("ascii")==="WEBP")return"image/webp";throw new Error("temporary file is not a supported raster image")}function T(e){const t=String(e||"").trim();if(!t.startsWith("file://"))return t;try{return decodeURIComponent(new URL(t).pathname)}catch{throw new Error("temporary image path is invalid")}}function h(e){return S(e)}function L(e){switch(o.extname(e).toLowerCase()){case".pdf":return"application/pdf";case".md":case".markdown":return"text/markdown; charset=utf-8";case".txt":case".log":return"text/plain; charset=utf-8";case".html":case".htm":return"text/html; charset=utf-8";case".css":return"text/css; charset=utf-8";case".js":case".mjs":return"text/javascript; charset=utf-8";case".json":case".map":return"application/json; charset=utf-8";case".xml":return"application/xml; charset=utf-8";case".svg":return"image/svg+xml; charset=utf-8";case".png":return"image/png";case".jpg":case".jpeg":return"image/jpeg";case".gif":return"image/gif";case".webp":return"image/webp";case".avif":return"image/avif";case".ico":return"image/x-icon";case".ppm":return"image/x-portable-pixmap";case".bmp":return"image/bmp";case".woff":return"font/woff";case".woff2":return"font/woff2";case".ttf":return"font/ttf";case".otf":return"font/otf";case".eot":return"application/vnd.ms-fontobject";case".mp4":return"video/mp4";case".webm":return"video/webm";case".mp3":return"audio/mpeg";case".wav":return"audio/wav";case".ogg":return"audio/ogg";case".webmanifest":return"application/manifest+json; charset=utf-8";case".zip":return"application/zip";case".docx":return"application/vnd.openxmlformats-officedocument.wordprocessingml.document";case".xlsx":return"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";default:return"application/octet-stream"}}export{k as detectSafeTempImageMime,L as mimeForPath,$ as resolveProjectFile,F as resolveTempImageFile,G as startFileTransferWorkerLoop};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"node:fs";import
|
|
1
|
+
import{isValidPpmHeader as h}from"./ppm-header.js";import t from"node:fs";import g from"node:path";import{fileURLToPath as u}from"node:url";function U(c,i,o){let e=i.trim();if(/^file:/i.test(e)){const r=new URL(e);if(r.hostname&&r.hostname!=="localhost")throw new Error("image URL must reference a local file");e=u(r)}if(!e||e.includes("\0"))throw new Error("image path is invalid");if(!g.isAbsolute(e)&&!c)throw new Error("relative image path requires a project root");const a=g.resolve(c,e),n=t.lstatSync(a);if(n.isSymbolicLink())throw new Error("image cannot be a symbolic link");if(!n.isFile())throw new Error("image target is not a regular file");const l=t.realpathSync(a),f=t.openSync(l,t.constants.O_RDONLY|(t.constants.O_NOFOLLOW||0)|(t.constants.O_NONBLOCK||0));try{const r=t.fstatSync(f);if(!r.isFile()||n.dev!==r.dev||n.ino!==r.ino)throw new Error("image file changed while opening");if(!Number.isFinite(o)||o<=0||r.size>o)throw new Error("image file is too large");const m=Buffer.alloc(g.extname(l).toLowerCase()===".ppm"?64*1024:512),s=t.readSync(f,m,0,m.length,0),d=w(l,m.subarray(0,s),r.size),p=t.createReadStream(l,{fd:f,autoClose:!0,start:0,end:r.size-1});return{path:l,sizeBytes:r.size,mimeType:d,stream:p}}catch(r){throw t.closeSync(f),r}}function w(c,i,o){const e=g.extname(c).toLowerCase();if(e===".ppm"&&h(i,o))return"image/x-portable-pixmap";if(e===".png"&&i.length>=24&&i.subarray(0,8).equals(Buffer.from([137,80,78,71,13,10,26,10]))&&i.toString("ascii",12,16)==="IHDR"&&i.readUInt32BE(16)>0&&i.readUInt32BE(20)>0)return"image/png";if([".jpg",".jpeg"].includes(e)&&i.length>=4&&i[0]===255&&i[1]===216&&i[2]===255)return"image/jpeg";if(e===".gif"&&i.length>=10&&["GIF87a","GIF89a"].includes(i.toString("ascii",0,6))&&i.readUInt16LE(6)>0&&i.readUInt16LE(8)>0)return"image/gif";if(e===".webp"&&i.length>=16&&i.toString("ascii",0,4)==="RIFF"&&i.toString("ascii",8,12)==="WEBP"&&["VP8 ","VP8L","VP8X"].includes(i.toString("ascii",12,16)))return"image/webp";if(e===".bmp"&&i.length>=26&&i.toString("ascii",0,2)==="BM"&&i.readUInt32LE(10)>=26&&[12,40,52,56,64,108,124].includes(i.readUInt32LE(14)))return"image/bmp";if(e===".ico"&&i.length>=22&&i.readUInt16LE(0)===0&&i.readUInt16LE(2)===1&&i.readUInt16LE(4)>0&&i.readUInt32LE(14)>0&&i.readUInt32LE(18)>=22)return"image/x-icon";if(e===".avif"&&i.length>=16&&i.toString("ascii",4,8)==="ftyp"){const a=i.readUInt32BE(0);if(a>=16&&a<=i.length&&a%4===0){for(let n=8;n<a;n+=4)if(n!==12&&["avif","avis"].includes(i.toString("ascii",n,n+4)))return"image/avif"}}throw new Error("file is not a supported raster image")}export{U as openImageFile};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function o(n,h){if(n[0]!==80||![51,54].includes(n[1])||!(n[2]===32||n[2]>=9&&n[2]<=13))return!1;let r=2;const c=l=>l===32||l>=9&&l<=13,e=()=>{for(;r<n.length;){if(c(n[r])){r++;continue}if(n[r]!==35)break;for(;r<n.length&&n[r]!==10&&n[r]!==13;)r++}const l=r;let a=0;for(;r<n.length&&n[r]>=48&&n[r]<=57;)a=a*10+n[r++]-48;return r>l&&Number.isSafeInteger(a)&&(c(n[r])||n[r]===35)?a:-1},i=e(),f=e(),u=e();return i<1||f<1||i*f>4e7||u<1||u>65535||r>=64*1024?!1:n[1]===51?h-r>=i*f*6-1:c(n[r])?(n[r++]===13&&n[r]===10&&h-r===i*f*3*(u>255?2:1)+1&&r++,h-r===i*f*3*(u>255?2:1)):!1}export{o as isValidPpmHeader};
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="0.1.
|
|
1
|
+
const o="0.1.72";export{o as AICA_VERSION};
|