mirror of
https://github.com/MarSeventh/CloudFlare-ImgBed.git
synced 2026-01-31 09:03:19 +08:00
2 lines
32 KiB
JavaScript
2 lines
32 KiB
JavaScript
"use strict";(self["webpackChunksanyue_imghub"]=self["webpackChunksanyue_imghub"]||[]).push([[102],{102:function(e,t,i){i.r(t),i.d(t,{default:function(){return me}});var s=i(6768),o=i(5130),r=i(4232);const n=["src"],a=["src"],l={key:2,class:"video-placeholder"},h={class:"audio-cover"},d=["src"],c={key:1,class:"audio-icon-large",viewBox:"0 0 24 24",fill:"currentColor"},u={class:"audio-info"},p={class:"audio-title"},g={key:0,class:"audio-artist"},m={class:"audio-controls"},v={key:0,viewBox:"0 0 24 24",fill:"currentColor"},w={key:1,viewBox:"0 0 24 24",fill:"currentColor"},f={class:"progress-bar"},k={class:"time-display"},y=["src"],C={key:4,class:"audio-placeholder"},L={class:"audio-name"};function b(e,t,i,b,x,T){return(0,s.uX)(),(0,s.CE)("div",{class:"tm-viewport",ref:"viewport",onPointerdown:t[8]||(t[8]=(...e)=>T.onPointerDown&&T.onPointerDown(...e)),onPointermove:t[9]||(t[9]=(...e)=>T.onPointerMove&&T.onPointerMove(...e)),onPointerup:t[10]||(t[10]=(...e)=>T.onPointerUp&&T.onPointerUp(...e)),onPointercancel:t[11]||(t[11]=(...e)=>T.onPointerUp&&T.onPointerUp(...e)),onDblclick:t[12]||(t[12]=(0,o.D$)((...e)=>T.onDblClick&&T.onDblClick(...e),["prevent"]))},[i.isImage?((0,s.uX)(),(0,s.CE)("img",{key:0,class:"tm-media",src:i.src,draggable:"false",style:(0,r.Tr)(T.mediaStyle),onLoad:t[0]||(t[0]=(...e)=>T.onLoad&&T.onLoad(...e))},null,44,n)):i.isVideo&&i.isActive?((0,s.uX)(),(0,s.CE)("video",{key:1,ref:"mediaEl",class:"tm-media",src:i.src,controls:"",playsinline:"",style:(0,r.Tr)(T.mediaStyle)},null,12,a)):i.isVideo?((0,s.uX)(),(0,s.CE)("div",l,[...t[13]||(t[13]=[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M8 5v14l11-7z"})],-1)])])):i.isAudio&&i.isActive?((0,s.uX)(),(0,s.CE)("div",{key:3,class:"tm-audio",onPointerdown:t[6]||(t[6]=(0,o.D$)(()=>{},["stop"])),onPointermove:t[7]||(t[7]=(0,o.D$)(()=>{},["stop"]))},[(0,s.Lk)("div",h,[x.audioCover?((0,s.uX)(),(0,s.CE)("img",{key:0,src:x.audioCover,class:"cover-img"},null,8,d)):((0,s.uX)(),(0,s.CE)("svg",c,[...t[14]||(t[14]=[(0,s.Lk)("path",{d:"M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"},null,-1)])]))]),(0,s.Lk)("div",u,[(0,s.Lk)("div",p,(0,r.v_)(x.audioTitle),1),x.audioArtist?((0,s.uX)(),(0,s.CE)("div",g,(0,r.v_)(x.audioArtist),1)):(0,s.Q3)("",!0)]),(0,s.Lk)("div",m,[(0,s.Lk)("button",{class:"ctrl-btn",onClick:t[1]||(t[1]=(...e)=>T.togglePlay&&T.togglePlay(...e))},[x.audioPlaying?((0,s.uX)(),(0,s.CE)("svg",w,[...t[16]||(t[16]=[(0,s.Lk)("path",{d:"M6 19h4V5H6v14zm8-14v14h4V5h-4z"},null,-1)])])):((0,s.uX)(),(0,s.CE)("svg",v,[...t[15]||(t[15]=[(0,s.Lk)("path",{d:"M8 5v14l11-7z"},null,-1)])]))]),(0,s.Lk)("div",{class:"progress-wrap",onClick:t[2]||(t[2]=(...e)=>T.seekAudio&&T.seekAudio(...e))},[(0,s.Lk)("div",f,[(0,s.Lk)("div",{class:"progress-fill",style:(0,r.Tr)({width:x.audioProgress+"%"})},null,4)]),(0,s.Lk)("div",k,[(0,s.Lk)("span",null,(0,r.v_)(T.formatTime(x.audioCurrentTime)),1),(0,s.Lk)("span",null,(0,r.v_)(T.formatTime(x.audioDuration)),1)])])]),(0,s.Lk)("audio",{ref:"mediaEl",src:i.src,onLoadedmetadata:t[3]||(t[3]=(...e)=>T.onAudioLoaded&&T.onAudioLoaded(...e)),onTimeupdate:t[4]||(t[4]=(...e)=>T.onTimeUpdate&&T.onTimeUpdate(...e)),onEnded:t[5]||(t[5]=e=>x.audioPlaying=!1)},null,40,y)],32)):i.isAudio?((0,s.uX)(),(0,s.CE)("div",C,[t[17]||(t[17]=(0,s.Lk)("svg",{class:"audio-icon-large",viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"})],-1)),(0,s.Lk)("span",L,(0,r.v_)(x.audioTitle),1)])):(0,s.Q3)("",!0)],544)}i(6573),i(8100),i(7936),i(9577),i(1549),i(9797),i(9631),i(5623),i(4603),i(7566),i(8721);var x={name:"TransformMedia",props:{file:{type:Object,required:!0},src:{type:String,required:!0},isImage:{type:Boolean,default:!0},isVideo:{type:Boolean,default:!1},isAudio:{type:Boolean,default:!1},isActive:{type:Boolean,default:!1}},data(){return{pointers:new Map,scale:1,rotation:0,rotatePreview:0,tx:0,ty:0,naturalWidth:0,naturalHeight:0,startScale:1,startRotation:0,startTx:0,startTy:0,startCenter:null,startDist:0,startAngle:0,audioPlaying:!1,audioCurrentTime:0,audioDuration:0,audioProgress:0,audioCover:null,audioTitle:"",audioArtist:"",dragging:!1,dragStart:null,viewportRect:null,minScale:1,maxScale:4,gestureMode:null,edgeOverflow:0,edgeDir:0}},computed:{isActiveTransform(){return this.scale>1.001||this.pointers.size>=2||this.dragging},displayRotation(){return this.rotation+this.rotatePreview},rotateShrink(){const e=Math.min(1,Math.abs(this.rotatePreview)/90),t=Math.sin(Math.PI*e);return 1-.12*t},mediaStyle(){const e=this.scale*this.rotateShrink,t=this.pointers.size>0;return{transform:`translate3d(${this.tx}px, ${this.ty}px, 0) scale(${e}) rotate(${this.displayRotation}deg)`,transition:t?"none":"transform 0.25s ease",transformOrigin:"center center"}}},watch:{isActiveTransform(e){this.$emit(e?"lock":"unlock")}},mounted(){this.isAudio&&this.initAudioInfo()},beforeUnmount(){const e=this.$refs.mediaEl;if(e)try{e.pause()}catch(t){}this.audioCover&&URL.revokeObjectURL(this.audioCover)},methods:{initAudioInfo(){const e=this.file?.name||this.src,t=e.split("/").pop().replace(/\.[^.]+$/,"");this.audioTitle=t,this.audioArtist="",this.audioCover=null,this.isActive&&this.tryReadMetadata()},async tryReadMetadata(){try{const e=await fetch(this.src),t=await e.blob(),i=await t.slice(0,131072).arrayBuffer(),s=new DataView(i);73===s.getUint8(0)&&68===s.getUint8(1)&&51===s.getUint8(2)&&this.parseID3v2(s,i)}catch(e){}},parseID3v2(e,t){const i=(127&e.getUint8(6))<<21|(127&e.getUint8(7))<<14|(127&e.getUint8(8))<<7|127&e.getUint8(9);let s=10;while(s<Math.min(i+10,t.byteLength-10)){const i=String.fromCharCode(e.getUint8(s),e.getUint8(s+1),e.getUint8(s+2),e.getUint8(s+3));if("\0\0\0\0"===i)break;const o=e.getUint8(s+4)<<24|e.getUint8(s+5)<<16|e.getUint8(s+6)<<8|e.getUint8(s+7);if(o<=0||o>t.byteLength)break;const r=new Uint8Array(t,s+10,Math.min(o,t.byteLength-s-10));"TIT2"===i?this.audioTitle=this.decodeText(r)||this.audioTitle:"TPE1"===i?this.audioArtist=this.decodeText(r):"APIC"===i&&this.extractCover(r),s+=10+o}},decodeText(e){if(e.length<2)return"";const t=e[0],i=e.slice(1);try{if(0===t)return new TextDecoder("iso-8859-1").decode(i).replace(/\0/g,"");if(1===t)return new TextDecoder("utf-16").decode(i).replace(/\0/g,"");if(3===t)return new TextDecoder("utf-8").decode(i).replace(/\0/g,"")}catch(s){}return""},extractCover(e){try{let t=1;while(t<e.length&&0!==e[t])t++;t++,t++;while(t<e.length&&0!==e[t])t++;if(t++,t<e.length){const i=e.slice(t),s=new Blob([i],{type:"image/jpeg"});this.audioCover=URL.createObjectURL(s)}}catch(t){}},onAudioLoaded(){this.$refs.mediaEl&&(this.audioDuration=this.$refs.mediaEl.duration)},onTimeUpdate(){this.$refs.mediaEl&&(this.audioCurrentTime=this.$refs.mediaEl.currentTime,this.audioProgress=this.audioCurrentTime/this.audioDuration*100||0)},togglePlay(){this.$refs.mediaEl&&(this.audioPlaying?this.$refs.mediaEl.pause():this.$refs.mediaEl.play(),this.audioPlaying=!this.audioPlaying)},seekAudio(e){if(!this.$refs.mediaEl||!this.audioDuration)return;const t=e.currentTarget.getBoundingClientRect(),i=e.clientX-t.left,s=i/t.width;this.$refs.mediaEl.currentTime=s*this.audioDuration},formatTime(e){if(!e||isNaN(e))return"0:00";const t=Math.floor(e/60),i=Math.floor(e%60);return`${t}:${i.toString().padStart(2,"0")}`},onLoad(e){const t=e.target;this.naturalWidth=t.naturalWidth,this.naturalHeight=t.naturalHeight},reset(){this.scale=1,this.rotation=0,this.rotatePreview=0,this.tx=0,this.ty=0,this.pointers.clear(),this.dragging=!1,this.edgeOverflow=0,this.edgeDir=0,this.$emit("unlock")},clamp(e,t,i){return Math.max(t,Math.min(i,e))},rubberBand(e,t,i=.55){return e*t*i/(t+i*e)},getViewportRect(){return this.$refs.viewport?.getBoundingClientRect()},getPanBounds(){const e=this.$refs.viewport?.getBoundingClientRect();if(!e)return{maxX:0,maxY:0,vw:0,vh:0};const t=e.width,i=e.height,s=this.$el.querySelector("img, video");let o=s?.clientWidth||t,r=s?.clientHeight||i;const n=this.rotation%360;90!==n&&270!==n||([o,r]=[r,o]);const a=o*this.scale,l=r*this.scale,h=Math.max(0,(a-t)/2),d=Math.max(0,(l-i)/2);return{maxX:h,maxY:d,vw:t,vh:i}},applyBoundWithRubber(e,t,i){return e>t?t+this.rubberBand(e-t,i,.55):e<-t?-t-this.rubberBand(-t-e,i,.55):e},calcTwoPointer(){const e=Array.from(this.pointers.entries()).sort((e,t)=>e[0]-t[0]),t=e[0][1],i=e[1][1],s=i.x-t.x,o=i.y-t.y,r=Math.hypot(s,o),n=Math.atan2(o,s)*(180/Math.PI),a={x:(t.x+i.x)/2,y:(t.y+i.y)/2};return{dist:r,angle:n,center:a}},normalizeAngle(e){return e=(e%360+360)%360,e>180?e-360:e},onPointerDown(e){if(e.currentTarget.setPointerCapture?.(e.pointerId),this.viewportRect=this.getViewportRect(),this.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),2===this.pointers.size){const{dist:e,angle:t,center:i}=this.calcTwoPointer();return this.startDist=e,this.startAngle=t,this.startCenter=i,this.startScale=this.scale,this.startRotation=this.rotation,this.startTx=this.tx,this.startTy=this.ty,this.dragging=!1,this.gestureMode=null,void(this.rotatePreview=0)}this.scale>1.001&&(this.dragging=!0,this.dragStart={x:e.clientX,y:e.clientY},this.startTx=this.tx,this.startTy=this.ty)},onPointerMove(e){if(this.pointers.has(e.pointerId)){if(this.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),2===this.pointers.size){e.preventDefault();const{dist:t,angle:i,center:s}=this.calcTwoPointer(),o=t/(this.startDist||t),r=Math.abs(o-1),n=this.normalizeAngle(i-this.startAngle),a=Math.abs(n),l=8,h=.08;if(!this.gestureMode)if(a>=l)this.gestureMode="rotate";else{if(!(r>=h))return;this.gestureMode="pinch"}if("rotate"===this.gestureMode)return this.scale=this.startScale,void(this.rotatePreview=this.clamp(n,-90,90));if("pinch"===this.gestureMode&&(this.scale=this.clamp(this.startScale*o,this.minScale,this.maxScale),this.rotatePreview=0),this.startCenter&&this.viewportRect){const e=this.startCenter.x-this.viewportRect.left-this.viewportRect.width/2,t=this.startCenter.y-this.viewportRect.top-this.viewportRect.height/2,i=s.x-this.viewportRect.left-this.viewportRect.width/2,o=s.y-this.viewportRect.top-this.viewportRect.height/2;this.tx=this.startTx+(i-e),this.ty=this.startTy+(o-t)}return}if(this.dragging&&this.scale>1.001){e.preventDefault();const t=e.clientX-this.dragStart.x,i=e.clientY-this.dragStart.y,s=this.startTx+t,o=this.startTy+i,{maxX:r,maxY:n,vw:a,vh:l}=this.getPanBounds();let h=0,d=0;s>r?(h=s-r,d=-1):s<-r&&(h=-r-s,d=1),this.edgeOverflow=h,this.edgeDir=d,this.tx=this.applyBoundWithRubber(s,r,a),this.ty=this.applyBoundWithRubber(o,n,l)}}},onPointerUp(e){if(this.pointers.has(e.pointerId)&&this.pointers.delete(e.pointerId),this.pointers.size<2&&"rotate"===this.gestureMode&&(this.finishRotate(),this.gestureMode=null),this.pointers.size<2&&(this.startCenter=null,this.startDist=0,this.startAngle=0,this.gestureMode=null),0===this.pointers.size){if(this.dragging=!1,this.edgeOverflow>60&&0!==this.edgeDir){const e=this.edgeDir;return this.reset(),void this.$emit("edge-swipe",e)}if(this.edgeOverflow=0,this.edgeDir=0,this.scale<=1.001)this.scale=1,this.tx=0,this.ty=0;else{const{maxX:e,maxY:t}=this.getPanBounds();this.tx=Math.max(-e,Math.min(e,this.tx)),this.ty=Math.max(-t,Math.min(t,this.ty))}}},finishRotate(){const e=this.rotatePreview,t=30;let i=0;Math.abs(e)>=t&&(i=e>0?90:-90);const s=((this.rotation+i)%360+360)%360;this.rotation=s,this.rotatePreview=0,this.updateFillScale()},updateFillScale(){const e=this.rotation%360,t=90===e||270===e;t?(this.scale=2,this.tx=0,this.ty=0):(this.scale=1,this.tx=0,this.ty=0)},onDblClick(){this.scale>1.001?(this.scale=1,this.tx=0,this.ty=0):this.scale=2}}},T=i(1241);const S=(0,T.A)(x,[["render",b],["__scopeId","data-v-3bcbacbb"]]);var P=S;const F={class:"header"},M={class:"header-left"},I={class:"header-center"},E={class:"breadcrumb"},X=["onClick"],A={class:"header-right"},D={class:"file-count"},$={key:0,class:"loading-container"},R={key:1,class:"error-container"},B={key:2,class:"gallery-container",ref:"galleryContainer"},U={key:0,class:"folders-section"},z={class:"folders-grid"},V=["onClick"],H={class:"folder-name"},W={class:"waterfall",ref:"waterfall"},_=["onClick"],N=["src","alt","onLoad"],Y=["src","onLoadedmetadata"],O={key:2,class:"audio-placeholder"},Q={class:"audio-name"},j={key:3,class:"file-placeholder"},K={class:"file-name"},q={class:"overlay"},G={class:"overlay-actions"},J=["onClick"],Z=["onClick"],ee={ref:"loadTrigger",class:"load-trigger"},te={key:0,class:"loading-more"},ie={key:1,class:"no-more"},se={key:2,class:"credit-link",href:"https://github.com/axibayuit-a11y",target:"_blank",rel:"noopener"},oe=["src"],re=["src"],ne=["src"],ae={key:2,class:"other-file-preview"},le={class:"file-name"},he={class:"page-indicator"};function de(e,t,i,n,a,l){const h=P;return(0,s.uX)(),(0,s.CE)("div",{class:(0,r.C4)(["public-browse",{"light-mode":a.isLightMode}])},[(0,s.Lk)("header",F,[(0,s.Lk)("div",M,[(0,s.Lk)("span",{class:"logo",onClick:t[0]||(t[0]=(...e)=>l.toggleTheme&&l.toggleTheme(...e)),title:"切换日夜模式"},(0,r.v_)(l.siteName),1)]),(0,s.Lk)("div",I,[(0,s.Lk)("div",E,[(0,s.Lk)("span",{class:"breadcrumb-item",onClick:t[1]||(t[1]=(...e)=>l.goToRoot&&l.goToRoot(...e))},(0,r.v_)(l.rootDirName),1),((0,s.uX)(!0),(0,s.CE)(s.FK,null,(0,s.pI)(l.pathParts,(e,i)=>((0,s.uX)(),(0,s.CE)(s.FK,{key:i},[t[22]||(t[22]=(0,s.Lk)("span",{class:"breadcrumb-sep"},"/",-1)),(0,s.Lk)("span",{class:"breadcrumb-item",onClick:e=>l.goToPath(i)},(0,r.v_)(e),9,X)],64))),128))])]),(0,s.Lk)("div",A,[(0,s.Lk)("span",D,(0,r.v_)(a.totalCount)+" 个文件",1)])]),a.loading&&0===a.files.length?((0,s.uX)(),(0,s.CE)("div",$,[...t[23]||(t[23]=[(0,s.Lk)("div",{class:"loading-spinner"},null,-1),(0,s.Lk)("p",null,"加载中...",-1)])])):a.error?((0,s.uX)(),(0,s.CE)("div",R,[(0,s.Lk)("p",null,(0,r.v_)(a.error),1),a.canRetry?((0,s.uX)(),(0,s.CE)("button",{key:0,onClick:t[2]||(t[2]=(...e)=>l.loadFiles&&l.loadFiles(...e)),class:"retry-btn"},"重试")):(0,s.Q3)("",!0)])):((0,s.uX)(),(0,s.CE)("div",B,[l.folders.length>0?((0,s.uX)(),(0,s.CE)("div",U,[(0,s.Lk)("div",z,[((0,s.uX)(!0),(0,s.CE)(s.FK,null,(0,s.pI)(l.folders,e=>((0,s.uX)(),(0,s.CE)("div",{key:e.name,class:"folder-card",onClick:t=>l.enterFolder(e.name)},[t[24]||(t[24]=(0,s.Lk)("div",{class:"folder-icon"},[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"})])],-1)),(0,s.Lk)("span",H,(0,r.v_)(l.getFolderName(e.name)),1)],8,V))),128))])])):(0,s.Q3)("",!0),(0,s.Lk)("div",W,[((0,s.uX)(!0),(0,s.CE)(s.FK,null,(0,s.pI)(l.columns,(e,i)=>((0,s.uX)(),(0,s.CE)("div",{key:i,class:"waterfall-column"},[((0,s.uX)(!0),(0,s.CE)(s.FK,null,(0,s.pI)(e,e=>((0,s.uX)(),(0,s.CE)("div",{key:e.name,class:"waterfall-item",onClick:t=>l.openPreview(e)},[(0,s.Lk)("div",{class:(0,r.C4)(["image-wrapper",{loaded:e.loaded}])},[l.isImage(e)?((0,s.uX)(),(0,s.CE)("img",{key:0,src:l.getFileUrl(e.name),alt:e.name,loading:"lazy",onLoad:t=>l.onImageLoad(t,e),onError:t[3]||(t[3]=(...e)=>l.handleImageError&&l.handleImageError(...e))},null,40,N)):l.isVideo(e)?((0,s.uX)(),(0,s.CE)("video",{key:1,src:l.getFileUrl(e.name),muted:"",loop:"",preload:"metadata",onLoadedmetadata:t=>l.onVideoLoad(t,e),onPointerenter:t[4]||(t[4]=e=>"mouse"===e.pointerType&&e.target.play()),onPointerleave:t[5]||(t[5]=e=>"mouse"===e.pointerType&&e.target.pause())},null,40,Y)):l.isAudio(e)?((0,s.uX)(),(0,s.CE)("div",O,[t[25]||(t[25]=(0,s.Lk)("svg",{class:"audio-icon",viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"})],-1)),(0,s.Lk)("span",Q,(0,r.v_)(l.getFileName(e.name)),1)])):((0,s.uX)(),(0,s.CE)("div",j,[t[26]||(t[26]=(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zm-1 7V3.5L18.5 9H13z"})],-1)),(0,s.Lk)("span",K,(0,r.v_)(l.getFileName(e.name)),1)])),(0,s.Lk)("div",q,[(0,s.Lk)("div",G,[(0,s.Lk)("button",{class:"action-btn",onClick:(0,o.D$)(t=>l.copyLink(e.name),["stop"]),title:"复制链接"},[...t[27]||(t[27]=[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"})],-1)])],8,J),(0,s.Lk)("button",{class:"action-btn",onClick:(0,o.D$)(t=>l.downloadFile(e.name),["stop"]),title:"下载"},[...t[28]||(t[28]=[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"})],-1)])],8,Z)])])],2)],8,_))),128))]))),128))],512),(0,s.Lk)("div",ee,[a.loading&&a.files.length>0?((0,s.uX)(),(0,s.CE)("div",te,[...t[29]||(t[29]=[(0,s.Lk)("div",{class:"loading-spinner-small"},null,-1),(0,s.Lk)("span",null,"加载中...",-1)])])):!a.hasMore&&l.mediaFiles.length>0?((0,s.uX)(),(0,s.CE)("div",ie," 已加载全部 ")):(0,s.Q3)("",!0),!a.hasMore&&l.mediaFiles.length>0?((0,s.uX)(),(0,s.CE)("a",se," 林酱贡献 ")):(0,s.Q3)("",!0)],512)],512)),a.previewVisible?((0,s.uX)(),(0,s.CE)("div",{key:3,class:"preview-modal",onClick:t[21]||(t[21]=(0,o.D$)((...e)=>l.closePreview&&l.closePreview(...e),["self"]))},[(0,s.Lk)("button",{class:"preview-close",onClick:t[6]||(t[6]=(0,o.D$)((...e)=>l.closePreview&&l.closePreview(...e),["stop"]))},[...t[30]||(t[30]=[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"})],-1)])]),(0,s.Lk)("div",{class:"preview-content desktop-only",onClick:t[7]||(t[7]=(0,o.D$)(()=>{},["stop"]))},[l.currentPreviewFile&&l.isImage(l.currentPreviewFile)?((0,s.uX)(),(0,s.CE)("img",{key:0,src:l.getFileUrl(l.currentPreviewFile.name),class:"preview-image",style:(0,r.Tr)(l.desktopImageStyle),draggable:"false"},null,12,oe)):l.currentPreviewFile&&l.isVideo(l.currentPreviewFile)?((0,s.uX)(),(0,s.CE)("video",{key:1,src:l.getFileUrl(l.currentPreviewFile.name),controls:"",autoplay:"",class:"preview-video",style:(0,r.Tr)(l.desktopImageStyle)},null,12,re)):l.currentPreviewFile&&l.isAudio(l.currentPreviewFile)?((0,s.uX)(),(0,s.Wv)(h,{key:2,file:l.currentPreviewFile,src:l.getFileUrl(l.currentPreviewFile.name),"is-image":!1,"is-video":!1,"is-audio":!0,"is-active":!0},null,8,["file","src"])):(0,s.Q3)("",!0)]),(0,s.Lk)("div",{class:"preview-content mobile-only",onClick:t[17]||(t[17]=(0,o.D$)(()=>{},["stop"]))},[l.currentPreviewFile&&l.isVideo(l.currentPreviewFile)?((0,s.uX)(),(0,s.CE)("video",{key:l.currentPreviewFile.name,src:l.getFileUrl(l.currentPreviewFile.name),controls:"",autoplay:"",playsinline:"",class:"mobile-video"},null,8,ne)):l.currentPreviewFile&&l.isAudio(l.currentPreviewFile)?((0,s.uX)(),(0,s.CE)("div",{key:1,class:"mobile-audio-wrap",onTouchstart:t[8]||(t[8]=(...e)=>l.onAudioSwipeStart&&l.onAudioSwipeStart(...e)),onTouchmove:t[9]||(t[9]=(...e)=>l.onAudioSwipeMove&&l.onAudioSwipeMove(...e)),onTouchend:t[10]||(t[10]=(...e)=>l.onAudioSwipeEnd&&l.onAudioSwipeEnd(...e))},[((0,s.uX)(),(0,s.Wv)(h,{key:l.currentPreviewFile.name,file:l.currentPreviewFile,src:l.getFileUrl(l.currentPreviewFile.name),"is-image":!1,"is-video":!1,"is-audio":!0,"is-active":!0},null,8,["file","src"]))],32)):l.currentPreviewFile&&!l.isImage(l.currentPreviewFile)?((0,s.uX)(),(0,s.CE)("div",ae,[t[31]||(t[31]=(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zm-1 7V3.5L18.5 9H13z"})],-1)),(0,s.Lk)("span",le,(0,r.v_)(l.getFileName(l.currentPreviewFile.name)),1)])):((0,s.uX)(),(0,s.CE)("div",{key:3,class:"swipe-viewport",ref:"mobileViewport",onTouchstart:t[14]||(t[14]=(...e)=>l.onSwipeStart&&l.onSwipeStart(...e)),onTouchmove:t[15]||(t[15]=(...e)=>l.onSwipeMove&&l.onSwipeMove(...e)),onTouchend:t[16]||(t[16]=(...e)=>l.onSwipeEnd&&l.onSwipeEnd(...e))},[(0,s.Lk)("div",{class:"swipe-track",style:(0,r.Tr)(l.swipeTrackStyle),onTransitionend:t[13]||(t[13]=(...e)=>l.onSwipeTransitionEnd&&l.onSwipeTransitionEnd(...e))},[((0,s.uX)(!0),(0,s.CE)(s.FK,null,(0,s.pI)(l.swipeWindow,(e,i)=>((0,s.uX)(),(0,s.CE)("div",{class:"swipe-slide",key:l.getSlideKey(e,i)},[e?((0,s.uX)(),(0,s.Wv)(h,{key:0,file:e,src:l.getFileUrl(e.name),"is-image":l.isImage(e),"is-video":!1,"is-audio":!1,"is-active":1===i,onLock:t[11]||(t[11]=e=>a.gestureLocked=!0),onUnlock:t[12]||(t[12]=e=>a.gestureLocked=!1),onEdgeSwipe:l.onEdgeSwipe},null,8,["file","src","is-image","is-active","onEdgeSwipe"])):(0,s.Q3)("",!0)]))),128))],36)],544))]),a.previewIndex>0?((0,s.uX)(),(0,s.CE)("button",{key:0,class:"preview-prev desktop-only",onClick:t[18]||(t[18]=(0,o.D$)((...e)=>l.prevImage&&l.prevImage(...e),["stop"]))},[...t[32]||(t[32]=[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})],-1)])])):(0,s.Q3)("",!0),a.previewIndex<l.mediaFiles.length-1?((0,s.uX)(),(0,s.CE)("button",{key:1,class:"preview-next desktop-only",onClick:t[19]||(t[19]=(0,o.D$)((...e)=>l.nextImage&&l.nextImage(...e),["stop"]))},[...t[33]||(t[33]=[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"})],-1)])])):(0,s.Q3)("",!0),(0,s.Lk)("button",{class:"rotate-btn desktop-only",onClick:t[20]||(t[20]=(0,o.D$)((...e)=>l.rotateImage&&l.rotateImage(...e),["stop"])),title:"旋转90°"},[...t[34]||(t[34]=[(0,s.Lk)("svg",{viewBox:"0 0 24 24",fill:"currentColor"},[(0,s.Lk)("path",{d:"M7.11 8.53L5.7 7.11C4.8 8.27 4.24 9.61 4.07 11h2.02c.14-.87.49-1.72 1.02-2.47zM6.09 13H4.07c.17 1.39.72 2.73 1.62 3.89l1.41-1.42c-.52-.75-.87-1.59-1.01-2.47zm1.01 5.32c1.16.9 2.51 1.44 3.9 1.61V17.9c-.87-.15-1.71-.49-2.46-1.03L7.1 18.32zM13 4.07V1L8.45 5.55 13 10V6.09c2.84.48 5 2.94 5 5.91s-2.16 5.43-5 5.91v2.02c3.95-.49 7-3.85 7-7.93s-3.05-7.44-7-7.93z"})],-1)])]),(0,s.Lk)("div",he,(0,r.v_)(a.previewIndex+1)+" / "+(0,r.v_)(l.mediaFiles.length),1)])):(0,s.Q3)("",!0)],2)}i(4114),i(8111),i(2489),i(7588),i(1701);var ce=i(4373),ue=i(8401),pe={name:"PublicBrowse",components:{TransformMedia:P},data(){return{files:[],allowedDirs:[],rootDir:"",currentPath:"",totalCount:0,loading:!1,error:null,canRetry:!0,hasMore:!0,previewVisible:!1,previewIndex:0,observer:null,pageSize:24,columnCount:4,columnHeights:[0,0,0,0],imageRotation:0,swipeX:0,swipeStartX:0,swipeStartY:0,swipeStartT:0,swipeActive:!1,swipeAnimating:!1,swipeDir:0,viewportW:0,gestureLocked:!1,isLightMode:!1,audioSwipeStartX:0,audioSwipeStartT:0,audioSwipeActive:!1}},computed:{...(0,ue.L8)(["userConfig"]),siteName(){return this.userConfig?.siteTitle||"公开相册"},rootDirName(){return this.rootDir.split("/").filter(Boolean).pop()||"根目录"},pathParts(){if(!this.currentPath||!this.rootDir)return[];const e=this.currentPath.replace(this.rootDir,"").replace(/^\/+/,"");return e.split("/").filter(Boolean)},folders(){return this.files.filter(e=>e.isFolder)},mediaFiles(){return this.files.filter(e=>!e.isFolder)},columns(){const e=Array.from({length:this.columnCount},()=>[]);for(const t of this.mediaFiles){const i=t.columnIndex??0;i<this.columnCount?e[i].push(t):e[0].push(t)}return e},currentPreviewFile(){return this.mediaFiles[this.previewIndex]},prevPreviewFile(){return this.previewIndex>0?this.mediaFiles[this.previewIndex-1]:null},nextPreviewFile(){return this.previewIndex<this.mediaFiles.length-1?this.mediaFiles[this.previewIndex+1]:null},desktopImageStyle(){return{transform:`rotate(${this.imageRotation}deg)`,transition:"transform 0.3s ease"}},swipeWindow(){return[this.prevPreviewFile,this.currentPreviewFile,this.nextPreviewFile]},swipeTrackStyle(){const e=-this.viewportW,t=e+this.swipeX;return{transform:`translate3d(${t}px, 0, 0)`,transition:this.swipeAnimating?"transform 0.28s ease":"none"}}},watch:{"$route.params.dir":{handler(){this.initFromRoute()}}},mounted(){this.initTheme(),this.initFromRoute(),this.setupIntersectionObserver(),this.updateColumnCount(),window.addEventListener("resize",this.updateColumnCount)},beforeUnmount(){this.observer&&this.observer.disconnect(),window.removeEventListener("resize",this.updateColumnCount)},methods:{initTheme(){const e=localStorage.getItem("publicBrowseTheme");if(null!==e)this.isLightMode="light"===e;else{const e=(new Date).getHours();this.isLightMode=e>=10&&e<18}},toggleTheme(){this.isLightMode=!this.isLightMode,localStorage.setItem("publicBrowseTheme",this.isLightMode?"light":"dark")},getSlideKey(e,t){return e?1===t?`${e.name}-${this.previewIndex}`:e.name:`empty-${t}`},updateColumnCount(){const e=window.innerWidth;let t;t=e<600?2:e<900?3:4,t!==this.columnCount&&(this.columnCount=t,this.columnHeights=new Array(this.columnCount).fill(0),this.mediaFiles.forEach(e=>{e.columnIndex=void 0,this.assignToColumn(e)}))},getShortestColumn(){let e=0,t=this.columnHeights[0];for(let i=1;i<this.columnCount;i++)this.columnHeights[i]<t&&(t=this.columnHeights[i],e=i);return e},assignToColumn(e,t=200){const i=this.getShortestColumn();e.columnIndex=i,this.columnHeights[i]+=t,(this.isAudio(e)||!this.isImage(e)&&!this.isVideo(e))&&(e.loaded=!0)},onImageLoad(e,t){const i=e.target,s=i.naturalHeight/i.naturalWidth,o=280*s;void 0===t.columnIndex&&this.assignToColumn(t,o),t.loaded=!0},onVideoLoad(e,t){const i=e.target,s=i.videoHeight/i.videoWidth,o=280*s;void 0===t.columnIndex&&this.assignToColumn(t,o),t.loaded=!0},setupIntersectionObserver(){this.observer=new IntersectionObserver(e=>{const t=e[0];t.isIntersecting&&this.hasMore&&!this.loading&&this.loadMore()},{rootMargin:"200px"})},observeLoadTrigger(){this.$nextTick(()=>{this.$refs.loadTrigger&&this.observer&&this.observer.observe(this.$refs.loadTrigger)})},async initFromRoute(){const e=this.$route.params.dir||"",t=Array.isArray(e)?e.join("/"):e;if(!t)return this.error="请指定要浏览的目录,例如: /browse/landscape",void(this.canRetry=!1);const i=t.split("/").filter(Boolean);this.rootDir=i[0],this.currentPath=t,this.files=[],this.hasMore=!0,this.columnHeights=new Array(this.columnCount).fill(0),await this.loadFiles(),this.observeLoadTrigger()},async loadFiles(){this.loading=!0,this.error=null,this.canRetry=!0;try{const e=await ce.A.get(`/api/public/list?dir=${encodeURIComponent(this.currentPath)}&count=${this.pageSize}`);e.data.allowedDirs&&(this.allowedDirs=e.data.allowedDirs);const t=(e.data.directories||[]).map(e=>({name:e,isFolder:!0})),i=(e.data.files||[]).map(e=>({name:e.name,isFolder:!1,metadata:e.metadata,columnIndex:void 0}));i.forEach(e=>this.assignToColumn(e)),this.files=[...t,...i],this.totalCount=e.data.totalCount||this.files.length,this.hasMore=this.mediaFiles.length<this.totalCount}catch(e){if(403===e.response?.status){const t=e.response?.data?.error||"";t.includes("disabled")?this.error="公开浏览功能未启用":t.includes("not allowed")||t.includes("No public")?this.error="该目录不允许公开访问":this.error="访问被拒绝",this.canRetry=!1}else this.error="加载失败,请重试"}finally{this.loading=!1}},async loadMore(){if(!this.loading&&this.hasMore){this.loading=!0;try{const e=this.mediaFiles.length,t=await ce.A.get(`/api/public/list?dir=${encodeURIComponent(this.currentPath)}&start=${e}&count=${this.pageSize}`),i=(t.data.files||[]).map(e=>({name:e.name,isFolder:!1,metadata:e.metadata,columnIndex:void 0}));i.forEach(e=>this.assignToColumn(e)),this.files.push(...i),this.hasMore=this.mediaFiles.length<this.totalCount}catch(e){console.error("加载更多失败",e)}finally{this.loading=!1}}},enterFolder(e){const t=e.replace(/\/+$/,"");this.$router.push(`/browse/${t}`)},goToRoot(){this.$router.push(`/browse/${this.rootDir}`)},goToPath(e){const t=this.pathParts.slice(0,e+1),i=this.rootDir+(t.length?"/"+t.join("/"):"");this.$router.push(`/browse/${i}`)},getFolderName(e){return e.split("/").filter(Boolean).pop()||e},getFileUrl(e){return`${window.location.origin}/file/${encodeURI(e)}`},isImage(e){const t=e.name.split(".").pop().toLowerCase();return["jpg","jpeg","png","gif","webp","bmp","svg","avif"].includes(t)},isVideo(e){const t=e.name.split(".").pop().toLowerCase();return["mp4","webm","ogg","mov"].includes(t)},isAudio(e){const t=e.name.split(".").pop().toLowerCase();return["mp3","wav","ogg","flac","aac","m4a"].includes(t)},getFileName(e){return e.split("/").pop()},handleImageError(e){e.target.style.display="none"},copyLink(e){const t=this.getFileUrl(e);navigator.clipboard?.writeText(t).then(()=>{this.showToast("已复制")}).catch(()=>{const e=document.createElement("input");e.value=t,document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e),this.showToast("已复制")})},showToast(e){const t=document.querySelector(".copy-toast");t&&t.remove();const i=document.createElement("div");i.className="copy-toast",i.textContent=e,document.body.appendChild(i),setTimeout(()=>i.classList.add("show"),10),setTimeout(()=>{i.classList.remove("show"),setTimeout(()=>i.remove(),300)},1500)},downloadFile(e){const t=document.createElement("a");t.href=this.getFileUrl(e),t.download=e.split("/").pop(),t.click()},openPreview(e){if(e.isFolder)return;const t=this.mediaFiles.findIndex(t=>t.name===e.name);t>=0&&(this.previewIndex=t,this.previewVisible=!0,this.imageRotation=0,this.gestureLocked=!1,document.body.style.overflow="hidden",this.$nextTick(()=>{this.viewportW=this.$refs.mobileViewport?.getBoundingClientRect().width||window.innerWidth}))},closePreview(){this.previewVisible=!1,this.imageRotation=0,this.gestureLocked=!1,document.body.style.overflow=""},prevImage(){this.previewIndex>0&&(this.previewIndex--,this.imageRotation=0)},nextImage(){this.previewIndex<this.mediaFiles.length-1&&(this.previewIndex++,this.imageRotation=0)},rotateImage(){this.imageRotation+=90,this.imageRotation>=360&&setTimeout(()=>{const e=this.$el.querySelector(".preview-image, .preview-video");e?(e.style.transition="none",this.imageRotation=0,e.offsetHeight,e.style.transition=""):this.imageRotation=0},300)},onSwipeStart(e){if(this.gestureLocked)return;if(this.swipeAnimating)return;const t=e.touches[0];this.swipeStartX=t.clientX,this.swipeStartY=t.clientY,this.swipeStartT=performance.now(),this.swipeX=0,this.swipeActive=!1,this.viewportW=this.$refs.mobileViewport?.getBoundingClientRect().width||window.innerWidth},onSwipeMove(e){if(this.gestureLocked)return;if(this.swipeAnimating)return;const t=e.touches[0],i=t.clientX-this.swipeStartX,s=t.clientY-this.swipeStartY;if(!this.swipeActive){if(Math.abs(i)<8)return;if(Math.abs(i)<=Math.abs(s))return;this.swipeActive=!0}e.preventDefault();let o=i;0===this.previewIndex&&o>0?o=this.rubberBand(o,this.viewportW,.55):this.previewIndex===this.mediaFiles.length-1&&o<0&&(o=-this.rubberBand(-o,this.viewportW,.55)),this.swipeX=o},onSwipeEnd(){if(this.gestureLocked)return;if(this.swipeAnimating)return;if(!this.swipeActive)return void(this.swipeX=0);const e=Math.max(1,performance.now()-this.swipeStartT),t=this.swipeX/e,i=.2*this.viewportW;let s=0;(this.swipeX<=-i||t<=-.8)&&(s=1),(this.swipeX>=i||t>=.8)&&(s=-1),(-1===s&&0===this.previewIndex||1===s&&this.previewIndex===this.mediaFiles.length-1)&&(s=0),this.swipeDir=s,this.swipeAnimating=!0,this.swipeX=1===s?-this.viewportW:-1===s?+this.viewportW:0},onSwipeTransitionEnd(){this.swipeAnimating&&(1===this.swipeDir&&this.previewIndex++,-1===this.swipeDir&&this.previewIndex--,this.swipeAnimating=!1,this.swipeDir=0,this.swipeX=0)},rubberBand(e,t,i=.55){return e*t*i/(t+i*e)},onEdgeSwipe(e){-1===e&&0===this.previewIndex||1===e&&this.previewIndex===this.mediaFiles.length-1||(this.swipeDir=e,this.swipeAnimating=!0,1===e?this.swipeX=-this.viewportW:-1===e&&(this.swipeX=+this.viewportW))},onAudioSwipeStart(e){const t=e.touches[0];this.audioSwipeStartX=t.clientX,this.audioSwipeStartT=performance.now(),this.audioSwipeActive=!1},onAudioSwipeMove(e){if(!this.audioSwipeStartX)return;const t=e.touches[0],i=t.clientX-this.audioSwipeStartX;Math.abs(i)>30&&(this.audioSwipeActive=!0)},onAudioSwipeEnd(e){if(!this.audioSwipeActive)return void(this.audioSwipeStartX=0);const t=e.changedTouches[0],i=t.clientX-this.audioSwipeStartX,s=Math.max(1,performance.now()-this.audioSwipeStartT),o=i/s,r=80;i>r||o>.5?this.prevImage():(i<-r||o<-.5)&&this.nextImage(),this.audioSwipeStartX=0,this.audioSwipeActive=!1}}};const ge=(0,T.A)(pe,[["render",de],["__scopeId","data-v-be3aaacc"]]);var me=ge}}]);
|
|
//# sourceMappingURL=102.f6511098.js.map
|