mirror of
https://github.com/nextcloud/server.git
synced 2026-12-02 22:15:44 +01:00
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
3 lines
4.7 KiB
JavaScript
3 lines
4.7 KiB
JavaScript
import{c as O,g as f,r as $}from"./ro-DPrAiJlc.chunk.mjs";import{g as H,a as L}from"./th-U6oNDpWa.chunk.mjs";import{P as E}from"./nn-C3nLRifc.chunk.mjs";import{c as I,b as R}from"./pt-tVUE3tkk.chunk.mjs";import{b as u,g as m,c as U,r as W,p as z}from"./dav-Cynk-Zmx.chunk.mjs";import"./sr-C7Yy9gNZ.chunk.mjs";import"./hu-DWHOtuOL.chunk.mjs";import"./tr-C7EGUBvz.chunk.mjs";import"./sv-Ca8TyYKj.chunk.mjs";const D=39,N=H().setApp("viewer").detectUser().build();function c(){return{file:"",files:[],enableSidebar:!0,canLoop:!0,startSlideshow:!1,loadMore:()=>[],onPrev:()=>{},onNext:()=>{},onClose:()=>{},overrideHandlerId:null}}let r=c();function o(e,t){N.warn(`OCA.Viewer.${e} is deprecated and will be removed in Nextcloud ${D}. Use ${t} from the @nextcloud/viewer package instead.`)}async function k(e){const t=await U().stat(u()+e,{details:!0,data:R()});return W(t.data)}function T(e){const t=e.split("/").pop()??"";try{return decodeURIComponent(t)}catch{return t}}function j(e){try{const{pathname:t}=new URL(e,window.location.origin);return t.slice(0,t.lastIndexOf("/"))||"/"}catch{return"/"}}function q(e){const t=m()+"/";if(e.startsWith(t)){const[n,i]=e.slice(t.length).split("/");if(n&&i)return`/${n}/${i}`}return j(e)}function B(e){return typeof e=="string"?z(e):e??E.READ}function p(e){const t=L()?.uid??null,n=e.filename?m()+u()+e.filename:void 0,i=e.source??n;if(i===void 0)throw new Error("Viewer file info needs either a source or a filename");const a={source:i,root:e.source===void 0?u():q(e.source),displayname:e.basename??T(i),mime:e.mime??"application/octet-stream",owner:t,permissions:B(e.permissions),attributes:{etag:e.etag,hasPreview:e.hasPreview}};return e.fileid!==void 0&&(a.id=Number(e.fileid)),e.size!==void 0&&(a.size=e.size),e.mtime!==void 0&&(a.mtime=new Date(e.mtime)),new I(a)}function P(e){try{return O(new I({source:`${m()}${u()}/.viewer-mime-probe`,root:u(),mime:e,owner:L()?.uid??null,permissions:E.READ,attributes:{hasPreview:!0}}))}catch(t){return N.debug("Could not work out whether the viewer handles this type",{mime:e,error:t}),!1}}const F=new Proxy([],{get(e,t,n){return t==="includes"?i=>P(i):t==="indexOf"?i=>P(i)?0:-1:Reflect.get(e,t,n)}});async function C(e={}){o("open()","getViewer().open()");const{path:t,fileInfo:n,list:i=[],enableSidebar:a=!0,loadMore:w=()=>[],canLoop:h=!0,startSlideshow:g=!1,onPrev:v=()=>{},onNext:b=()=>{},onClose:y=()=>{}}=e;if(!t&&!n)throw new Error("Viewer needs either an URL or path to open. None given");if(t&&!t.startsWith("/"))throw new Error("Please use an absolute path");if(!Array.isArray(i))throw new Error("The files list must be an array");if(typeof w!="function")throw new Error("The loadMore method must be a function");const A=r.overrideHandlerId??void 0;r={...c(),file:t??n?.filename??"",files:i,enableSidebar:a,canLoop:h,startSlideshow:g,loadMore:w,onPrev:v,onNext:b,onClose:y};let d=t?await k(t):p(n);const l=i.map(p),V=l.find(s=>d.fileid!==void 0&&s.fileid===d.fileid||s.source===d.source);V?d=V:l.push(d);const x=await f().open(l,d,{enableSidebar:a,canLoop:h,startSlideshow:g,loadMore:async()=>{const s=(await w()).map(p);return l.push(...s),s}},A);let S=d;x.addEventListener("update:file",({detail:[s]})=>{const M=l.indexOf(S);S=s,l.indexOf(s)===(M+1)%l.length?b(s):v(s)}),x.addEventListener("close",()=>{r=c(),y()})}function G(){window.OCA??={};const e={open:C,openWith(t,n={}){return o("openWith()","the handler argument of getViewer().open()"),r.overrideHandlerId=t,C(n)},compare(t,n){return o("compare()","getViewer().compare()"),f().compare(p(t),p(n)).then(()=>{})},close(){o("close()","getViewer().close()"),r=c(),f().close()},get file(){return o("file","the node you passed to getViewer().open()"),r.file},get files(){return o("files","the nodes you passed to getViewer().open()"),r.files},get list(){return o("list","the nodes you passed to getViewer().open()"),r.files},get mimetypes(){return o("mimetypes","canView()"),F},get enableSidebar(){return o("enableSidebar","the options you passed to getViewer().open()"),r.enableSidebar},get canLoop(){return o("canLoop","the options you passed to getViewer().open()"),r.canLoop},get startSlideshow(){return o("startSlideshow","the options you passed to getViewer().open()"),r.startSlideshow},get loadMore(){return o("loadMore","the options you passed to getViewer().open()"),r.loadMore},get onPrev(){return o("onPrev","the options you passed to getViewer().open()"),r.onPrev},get onNext(){return o("onNext","the options you passed to getViewer().open()"),r.onNext},get onClose(){return o("onClose","the options you passed to getViewer().open()"),r.onClose},get overrideHandlerId(){return o("overrideHandlerId","the handler argument of getViewer().open()"),r.overrideHandlerId}};window.OCA.Viewer=e}$(),G();
|
|
//# sourceMappingURL=core-viewer-init.mjs.map
|