PageSourceSearch

https://uniai.ai/assets/ImageUpscalePage-8eA5q8dE.js

js uniai.ai collected 2026-10-05 13:11:45 UTC 11,155 bytes, 1 lines download raw bytes

1import{b as ge,aZ as pe,aI as xe,r as l,c0 as he,c1 as fe,z as C,j as e,bc as be,X as ye,ak as ve,c3 as Y,aT as je,D as we,L as Ne,I as Se,aO as ke,c4 as Ce,c5 as Z,c6 as Q,bf as Ie}from"./index-BawMCgu8.js";import{u as Ue}from"./useFeatureCreditEstimate-CKYhAOwQ.js";import"./locale-en-B8Z5F_o1.js";import"./locale-zh-CN-CFdD1mPv.js";import"./locale-fr-j4CMJpfE.js";import"./locale-de-DuE2gagy.js";import"./locale-it-C6yb6RzN.js";import"./locale-ja-VjZBy5eF.js";import"./locale-ko-Cl0W-Az5.js";import"./locale-es-DwboUZze.js";import"./locale-zh-Hant-uT5aTnfX.js";import"./locale-ru-DEr1xfTZ.js";import"./locale-id-Buh3Uolz.js";import"./locale-pt-BR-CqD5J4_0.js";const V="upscale-state",ee=[{label:"2K",target:2048},{label:"4K",target:4096},{label:"8K",target:8192}];function Ee(r,I){const y=Math.max(r,I);return ee.map(g=>{const b=g.target/y,A=Math.round(r*b),L=Math.round(I*b),U=b<=2?2:b<=4?4:8,F=g.target<=y*1.2;return{label:g.label,width:A,height:L,scale:U,disabled:F}})}function Pe(){try{const r=localStorage.getItem(V);return r?JSON.parse(r):{sourceUrl:null,resultImage:null,selectedTier:"2K",resultInfo:null}}catch{return{sourceUrl:null,resultImage:null,selectedTier:"2K",resultInfo:null}}}function Je(){var W,q,B,G;const{t:r}=ge(),{requireAuth:I}=pe(),{estimate:y,insufficient:g}=Ue("image_upscale"),{tier:b,credits:A,thresholds:L}=xe(),U=b!=="premium",[F,$]=l.useState(!1),{openPicker:te,PickerElement:se}=he(),{showSourceChoice:re,sourceChoiceOpen:ae,pickSource:O}=fe(),E=l.useRef(null),v=l.useRef(Pe()).current,[i,j]=l.useState(v.sourceUrl),[le,P]=l.useState(null),[z,w]=l.useState(v.sourceUrl),[p,N]=l.useState(v.resultImage),[R,H]=l.useState(!1),[o,K]=l.useState(v.selectedTier),[u,M]=l.useState(null),[x,S]=l.useState(v.resultInfo);l.useEffect(()=>{try{localStorage.setItem(V,JSON.stringify({sourceUrl:z,resultImage:p,selectedTier:o,resultInfo:x}))}catch{}},[z,p,o,x]),l.useEffect(()=>{if(!i){M(null);return}const t=new Image;t.onload=()=>M({width:t.naturalWidth,height:t.naturalHeight}),t.src=i},[i]);const k=u?Ee(u.width,u.height):[];l.useEffect(()=>{const t=k.filter(s=>!s.disabled);t.length>0&&!t.find(s=>s.label===o)&&K(t[0].label)},[k,o]);const h=k.find(t=>t.label===o&&!t.disabled),ie=l.useCallback(t=>{var a;const s=(a=t.target.files)==null?void 0:a[0];if(s){if(s.size>10*1024*1024){C.error(r("image.fileTooLarge",{max:"10MB"}));return}const c=new FileReader;c.onload=d=>{var m;j((m=d.target)==null?void 0:m.result),P(s),w(null),N(null),S(null)},c.readAsDataURL(s)}},[r]),oe=l.useCallback(t=>{var a;t.preventDefault();const s=(a=t.dataTransfer.files)==null?void 0:a[0];if(s&&s.type.startsWith("image/")){if(s.size>10*1024*1024){C.error(r("image.fileTooLarge",{max:"10MB"}));return}const c=new FileReader;c.onload=d=>{var m;j((m=d.target)==null?void 0:m.result),P(s),w(null),N(null),S(null)},c.readAsDataURL(s)}},[r]),ne=async()=>{var s;const t=await re();if(t==="local")(s=E.current)==null||s.click();else if(t==="library"){const a=await te("image");if(!a)return;j(a.url),P(null),w(a.url),M(null)}},ce=()=>{j(null),P(null),w(null),N(null),S(null),E.current&&(E.current.value="")},de=async()=>{if(z)return z;let t=le;if(!t&&i){const d=await(await fetch(i)).blob();t=new File([d],"source.png",{type:d.type||"image/png"})}if(!t)throw new Error("No file selected");const a=(await Ie.uploadImage(t)).data.url;return w(a),j(a),a},ue=async()=>{var t,s,a,c,d,m,J;if(I()&&!(!i||!h)){H(!0);try{const D=await de(),{data:n}=await Z.upscale({imageUrl:D,scale:h.scale,outputFormat:"png",targetLongEdge:(t=ee.find(_=>_.label===o))==null?void 0:t.target});if(n.taskId&&n.status==="processing"){for(let X=0;X<90;X++){const f=(await Z.getProcessingTaskStatus(n.taskId)).data;if(f.status==="completed"){const T=((s=f.result)==null?void 0:s.imageUrl)||f.imageUrl;if(T){N(T),S({originalSize:((a=f.result)==null?void 0:a.originalSize)||u||void 0,outputSize:((c=f.result)==null?void 0:c.outputSize)||{width:h.width,height:h.height}}),C.success(r("image.processSuccess")),Q();return}throw new Error("No image URL in result")}if(f.status==="failed")throw new Error(f.error||"Processing failed");await new Promise(T=>setTimeout(T,2e3))}throw new Error("Processing timed out")}if(n.status==="completed"&&((d=n.result)!=null&&d.imageUrl))N(n.result.imageUrl),S({originalSize:n.result.originalSize||u||void 0,outputSize:n.result.outputSize||{width:h.width,height:h.height}}),C.success(r("image.processSuccess")),Q();else if(n.status==="failed")throw new Error(n.error||"Processing failed")}catch(D){C.error(((J=(m=D.response)==null?void 0:m.data)==null?void 0:J.message)||D.message||r("image.processError"))}finally{H(!1)}}},me=()=>{if(!p)return;const t=`/api/v1/image/download?url=${encodeURIComponent(p)}`,s=document.createElement("a");s.href=t,s.download=`upscaled-${o}-${Date.now()}.webp`,document.body.appendChild(s),s.click(),document.body.removeChild(s)};return e.jsxs("div",{className:"h-full overflow-y-auto",style:{background:"var(--bg-base)"},children:[e.jsx("div",{className:"px-6 py-4 border-b",style:{borderColor:"var(--border-default)"},children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center",style:{background:"var(--bg-tertiary)"},children:e.jsx(be,{className:"w-5 h-5",style:{color:"var(--text-secondary)"}})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold",style:{color:"var(--text-primary)"},children:r("imageHome.features.upscale")}
1),e.jsx("p",{className:"text-sm",style:{color:"var(--text-tertiary)"},children:r("imageHome.features.upscaleDesc")})]})]})}),e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"rounded-xl border overflow-hidden",style:{background:"var(--surface-primary)",borderColor:"var(--border-default)"},children:[e.jsxs("div",{className:"px-4 py-3 border-b flex items-center justify-between",style:{borderColor:"var(--border-default)"},children:[e.jsx("span",{className:"font-medium",style:{color:"var(--text-primary)"},children:r("image.sourceImage")}),i&&e.jsx("button",{onClick:ce,className:"p-1.5 rounded-lg hover:bg-[var(--bg-hover)] transition-colors",children:e.jsx(ye,{className:"w-4 h-4",style:{color:"var(--text-tertiary)"}})})]}),e.jsx("div",{className:"p-4",children:i?e.jsxs("div",{children:[e.jsx(Y,{url:i,alt:"Source",className:"w-full rounded-lg",style:{maxHeight:"400px",objectFit:"contain"}}),u&&e.jsxs("p",{className:"text-xs mt-2 text-center",style:{color:"var(--text-tertiary)"},children:[u.width," x ",u.height]})]}):e.jsxs("div",{className:"border-2 border-dashed rounded-xl p-8 text-center cursor-pointer hover:border-[var(--text-tertiary)] transition-colors",style:{borderColor:"var(--border-default)"},onClick:ne,onDrop:oe,onDragOver:t=>t.preventDefault(),children:[e.jsx("input",{ref:E,type:"file",accept:"image/jpeg,image/png,image/webp,image/svg+xml",onChange:ie,onClick:t=>t.stopPropagation(),hidden:!0}),e.jsx(ve,{className:"w-12 h-12 mx-auto mb-4",style:{color:"var(--text-tertiary)"}}),e.jsx("p",{className:"font-medium mb-2",style:{color:"var(--text-primary)"},children:r("image.dropOrClick")}),e.jsx("p",{className:"text-sm",style:{color:"var(--text-tertiary)"},children:"JPG, PNG, WebP (Max 10MB)"})]})}),e.jsxs("div",{className:"px-4 pb-4 space-y-4",children:[k.length>0&&e.jsx("div",{className:"grid grid-cols-3 gap-2",children:k.map(t=>e.jsxs("button",{onClick:()=>!t.disabled&&K(t.label),disabled:t.disabled,className:`px-3 py-3 rounded-lg border text-center transition-all ${t.disabled?"opacity-40 cursor-not-allowed":o===t.label?"border-[var(--text-secondary)] bg-[var(--bg-tertiary)]":"hover:border-gray-300"}`,style:{borderColor:!t.disabled&&o===t.label?"var(--text-primary)":"var(--border-default)",fontWeight:!t.disabled&&o===t.label?600:400},children:[e.jsx("span",{className:"text-sm font-semibold",children:t.label}),e.jsxs("span",{className:"block text-xs mt-1",style:{color:"var(--text-tertiary)"},children:[t.width," x ",t.height]})]},t.label))}),e.jsxs("button",{onClick:()=>{if(U){$(!0);return}ue()},disabled:!i||R||!h||g,className:`w-full flex items-center justify-center gap-2 px-4 py-3 rounded-xl font-medium text-white transition-all disabled:opacity-50 disabled:cursor-not-allowed hover:opacity-90 ${g?"!bg-destructive/20 !text-destructive":""} ${U?"opacity-50":""}`,style:g?void 0:{background:"var(--theme)"},children:[r(R?"image.processing":"image.startUpscale"),y!=null&&!R&&e.jsxs("span",{className:"flex items-center gap-0.5 text-xs opacity-60 ml-1",children:[e.jsx(je,{className:"w-3 h-3"}),"~",y]})]})]})]}),e.jsxs("div",{className:"rounded-xl border overflow-hidden",style:{background:"var(--surface-primary)",borderColor:"var(--border-default)"},children:[e.jsxs("div",{className:"px-4 py-3 border-b flex items-center justify-between",style:{borderColor:"var(--border-default)"},children:[e.jsx("span",{className:"font-medium",style:{color:"var(--text-primary)"},children:r("image.result")}),p&&e.jsxs("button",{onClick:me,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm font-medium transition-colors",style:{background:"var(--theme)",color:"white"},children:[e.jsx(we,{className:"w-4 h-4"}),r("common.download")]})]}),e.jsx("div",{className:"p-4",children:R?e.jsxs("div",{className:"relative rounded-xl overflow-hidden",style:{minHeight:"300px"},children:[e.jsx("div",{className:"absolute inset-0 video-loading-mesh"}),e.jsx("div",{className:"absolute inset-0 video-loading-blobs"}),e.jsx("div",{className:"absolute inset-0 video-loading-streak"}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx(Ne,{className:"w-8 h-8 animate-spin mb
1-3 text-white/80"}),e.jsxs("p",{className:"text-sm font-medium text-white/90",children:[r("image.processing"),"..."]})]})]}):p?e.jsxs("div",{children:[e.jsx(Y,{url:p,alt:"Result",className:"w-full rounded-lg",style:{maxHeight:"400px",objectFit:"contain"}}),x&&e.jsxs("div",{className:"mt-3 p-3 rounded-lg text-sm",style:{background:"var(--surface-secondary)"},children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("span",{style:{color:"var(--text-tertiary)"},children:[r("image.originalSize"),":"]}),e.jsxs("span",{style:{color:"var(--text-primary)"},children:[(W=x.originalSize)==null?void 0:W.width," x ",(q=x.originalSize)==null?void 0:q.height]})]}),e.jsxs("div",{className:"flex justify-between mt-1",children:[e.jsxs("span",{style:{color:"var(--text-tertiary)"},children:[r("image.outputSize"),":"]}),e.jsxs("span",{style:{color:"var(--text-secondary)"},children:[(B=x.outputSize)==null?void 0:B.width," x ",(G=x.outputSize)==null?void 0:G.height]})]})]})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[e.jsx(Se,{className:"w-12 h-12 mb-4",style:{color:"var(--text-tertiary)"}}),e.jsx("p",{style:{color:"var(--text-tertiary)"},children:r("image.resultWillAppear")})]})})]})]})}),e.jsx(ke,{open:F,onClose:()=>$(!1),requiredCredits:L.premium,currentCredits:A}),se,e.jsx(Ce,{open:ae,onLocal:()=>O("local"),onLibrary:()=>O("library"),onClose:()=>O(null)})]})}export{Je as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.