const{createApp}=Vue const{createVuetify,useGoTo,useDisplay}=Vuetify var data={alert:{show:false,color:'success',text:'',timeout:0,},theme:{dark:false,},nav:{showDrawer:false,showTOC:true,tocPanel:0,tab:'account',post:{discussionId:7353,currentPage:1,targetPage:1,total:14,anchor:0,goToOptions:{container:null,duration:0,easing:'easeInOutCubic',offset:-100,},worker:null,task:[],active:[],apiLock:[],originLike:new Map([]),},related:{block:1,}},search:{width:80,text:null,loading:false,},tags:[{id:21,url:'/t/182c700e6a045c756177250e2d18',name:'Nginx',color:'#66BB6A',icon:'mdi-tag-heart',},],posts:[{id:93119,num:0,uid:14668,content:'\u003Cp\u003E比如 a.com 下的图片、js 文件等等,只允许 b.com 、c.com 调用。其他域名调用的话就显示 404 或者 403 。\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-04-01 14:06:42',updatedAt:'2025-04-03 11:14:38',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:93120,num:1,uid:2533,content:'你根本不知道 CORS 是什么意思!',ipRegion:'',updatedByUid:0,createdAt:'2025-04-01 14:09:10',updatedAt:'2025-04-03 11:14:38',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:93121,num:2,uid:2533,content:'以后有问题去问 AI 就行,不要发帖。问题:Nginx 防盗链',ipRegion:'',updatedByUid:0,createdAt:'2025-04-01 14:11:18',updatedAt:'2025-04-03 11:14:38',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:93122,num:3,uid:3877,content:'Access-Control-Allow-Origin',ipRegion:'',updatedByUid:0,createdAt:'2025-04-01 14:12:37',updatedAt:'2025-04-03 11:14:38',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:93123,num:4,uid:16507,content:'img 、js 不存在跨域',ipRegion:'',updatedByUid:0,createdAt:'2025-04-01 14:21:24',updatedAt:'2025-04-03 11:14:38',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:93124,num:5,uid:4989,content:'location /images/ {\u003Cbr\u003E valid_referers none blocked www.yourdomain.com yourdomain.com;\u003Cbr\u003E if ($invalid_referer) {\u003Cbr\u003E return 403; # 返回 403 Forbidden 错误\u003Cbr\u003E # 或者可以重定向到特定的图片或页面\u003Cbr\u003E # return 302 http://www.yourdomain.com/blocked.png;\u003Cbr\u003E }\u003Cbr\u003E}',ipRegion:'',updatedByUid:0,createdAt:'2025-04-01 14:22:33',updatedAt:'2025-04-03 11:14:38',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:93125,num:6,uid:36,content:'没啥用, 想用你的东西再不行拿反代拉, 你资源真重要就得走登录控制',ipRegion:'',updatedByUid:0,createdAt:'2025-04-01 14:53:20',updatedAt:'2025-04-03 11:14:38',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:93126,num:7,uid:3681,content:'确实,就算登录控制之后日志也得存好',ipRegion:'',updatedByUid:0,createdAt:'2025-04-01 15:33:17',updatedAt:'2025-04-03 11:14:38',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:93127,num:8,uid:2513,content:'#\u003Cbr\u003E# Wide-open CORS config for nginx\u003Cbr\u003E#\u003Cbr\u003Elocation / {\u003Cbr\u003E if ($request_method \u003D \u0026#39;OPTIONS\u0026#39;) {\u003Cbr\u003E add_header \u0026#39;Access-Control-Allow-Origin\u0026#39; \u0026#39;*\u0026#39;;\u003Cbr\u003E add_header \u0026#39;Access-Control-Allow-Methods\u0026#39; \u0026#39;GET, POST, OPTIONS\u0026#39;;\u003Cbr\u003E #\u003Cbr\u003E # Custom headers and headers various browsers *should* be OK with but aren\u0026#39;t\u003Cbr\u003E #\u003Cbr\u003E add_header \u0026#39;Access-Control-Allow-Headers\u0026#39; \u0026#39;DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range\u0026#39;;\u003Cbr\u003E #\u003Cbr\u003E # Tell client that this pre-flight info is valid for 20 days\u003Cbr\u003E #\u003Cbr\u003E add_header \u0026#39;Access-Control-Max-Age\u0026#39; 1728000;\u003Cbr\u003E add_header \u0026#39;Content-Type\u0026#39; \u0026#39;text/plain; charset\u003Dutf-8\u0026#39;;\u003Cbr\u003E add_header \u0026#39;Content-Length\u0026#39; 0;\u003Cbr\u003E return 204;\u003Cbr\u003E }\u003Cbr\u003E if ($request_method \u003D \u0026#39;POST\u0026#39;) {\u003Cbr\u003E add_header \u0026#39;Access-Control-Allow-Origin\u0026#39; \u0026#39;*\u0026#39; always;\u003Cbr\u003E add_header \u0026#39;Access-Control-Allow-Methods\u0026#39; \u0026#39;GET, POST, OPTIONS\u0026#39; always;\u003Cbr\u003E add_header \u0026#39;Access-Control-Allow-Headers\u0026#39; \u0026#39;DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range\u0026#39; always;\u003Cbr\u003E add_header \u0026#39;Access-Control-Expose-Headers\u0026#39; \u0026#39;Content-Length,Content-Range\u0026#39; always;\u003Cbr\u003E }\u003Cbr\u003E if ($request_method \u003D \u0026#39;GET\u0026#39;) {\u003Cbr\u003E add_header \u0026#39;Access-Control-Allow-Origin\u0026#39; \u0026#39;*\u0026#39; always;\u003Cbr\u003E add_header \u0026#39;Access-Control-Allow-Methods\u0026#39; \u0026#39;GET, POST, OPTIONS\u0026#39; always;\u003Cbr\u003E add_header \u0026#39;Access-Control-Allow-Headers\u0026#39; \u0026#39;DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range\u0026#39; always;\u003Cbr\u003E add_header \u0026#39;Access-Control-Expose-Headers\u0026#39; \u0026#39;Content-Length,Content-Range\u0026#39; always;\u003Cbr\u003E }\u003Cbr\u003E}',ipRegion:'',updatedByUid:0,createdAt:'2025-04-01 15:35:59',updatedAt:'2025-04-03 11:14:38',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:93128,num:9,uid:5108,content:'把账号密码私钥给我,我开 ssh 上去免费给你弄',ipRegion:'',updatedByUid:0,createdAt:'2025-04-01 15:45:25',updatedAt:'2025-04-03 11:14:38',mentionNum:0,mentionedBy:[11,],mentionUsers:[],likeUsers:[],},{id:93129,num:10,uid:796,content:'跨域是指,接口没带 CORS 跨域返回头,你的浏览器认为自己不配访问。postman 调用接口是能拿到东西的。\u003Cbr\u003E防盗链是指,NGINX 觉得对方的请求头有问题不配拿到任何东西。',ipRegion:'',updatedByUid:0,createdAt:'2025-04-01 15:49:39',updatedAt:'2025-04-03 11:14:38',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:93130,num:11,uid:15441,content:'#9 127.0.0.1:22 , root/password123 。谢谢老哥',ipRegion:'',updatedByUid:0,createdAt:'2025-04-01 15:56:48',updatedAt:'2025-04-03 11:14:38',mentionNum:9,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:93131,num:12,uid:695,content:'开 ssh 我上去看看',ipRegion:'',updatedByUid:0,createdAt:'2025-04-01 23:33:26',updatedAt:'2025-04-03 11:14:38',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:93132,num:13,uid:16492,content:'跨域是针对浏览器的名词,只存在于浏览器,正如上面老哥说的,防盗链一行命令就能加,后端程序里现在也有 CORS 插件很方便就能引入。但也仅仅局限于浏览器,',ipRegion:'',updatedByUid:0,createdAt:'2025-04-02 09:08:52',updatedAt:'2025-04-03 11:14:38',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},],usersMap:new Map([[4989,{uid:4989,url:'/u/193374376a045c7369625f6f1926293d',avatar:'/a/193374376a045c7369625f6f1926293d',username:'zx9481🤖',}],[14668,{uid:14668,url:'/u/3e3b04386a045d73666c5e6f2e382512',avatar:'/a/3e3b04386a045d73666c5e6f2e382512',username:'whereFly🤖',}],[3877,{uid:3877,url:'/u/2f2d612b6a045c74686d516f2f303b34',avatar:'/a/2f2d612b6a045c74686d516f2f303b34',username:'wu00🤖',}],[2513,{uid:2513,url:'/u/033d5b226a045c75656b556f3425383f',avatar:'/a/033d5b226a045c75656b556f3425383f',username:'hackroad🤖',}],[16507,{uid:16507,url:'/u/007a62026a045d71656a516f2e313f74',avatar:'/a/007a62026a045d71656a516f2e313f74',username:'wzhaoyang🤖',}],[16492,{uid:16492,url:'/u/203d7e056a045d716463546f225f0531',avatar:'/a/203d7e056a045d716463546f225f0531',username:'yassinezhang🤖',}],[796,{uid:796,url:'/u/0f0c05056a045c776763506f0e282712',avatar:'/a/0f0c05056a045c776763506f0e282712',username:'wangtian2020🤖',}],[5108,{uid:5108,url:'/u/0a2a6a1f6a045c72616a5e6f1a186426',avatar:'/a/0a2a6a1f6a045c72616a5e6f1a186426',username:'lisongeee🤖',}],[2533,{uid:2533,url:'/u/363a71246a045c756569556f381b6703',avatar:'/a/363a71246a045c756569556f381b6703',username:'Chaidu🤖',}],[695,{uid:695,url:'/u/1d1f5d2c6a045c776663536f2f5f2770',avatar:'/a/1d1f5d2c6a045c776663536f2f5f2770',username:'daimaosix🤖',}],[3681,{uid:3681,url:'/u/1d2647376a045c746662576f03051e7f',avatar:'/a/1d2647376a045c746662576f03051e7f',username:'duzhuo🤖',}],[15441,{uid:15441,url:'/u/3b0500066a045d72646e576f4120320c',avatar:'/a/3b0500066a045d72646e576f4120320c',username:'YeatsOnce🤖',}],[36,{uid:36,url:'/u/203c022c6a045c776069506f3e250728',avatar:'/a/203c022c6a045c776069506f3e250728',username:'paopjian🤖',}],]),related:[{title:'Caddy \u0026amp;nginx 一键部署反代脚本 支持Debian/Ubuntu系统',url:'/d/3d08420f6a045c77606a5675465a636a1e392033',},{title:'使用 nginx 监听已被监听的端口, reload 不会失败, 但会导致其他配置不生效.',url:'/d/627843026a045c77606a5674455c666a012f6731',},{title:'分享一下用AdguardHome和Nginx的配置,让你可以自由DIY路径',url:'/d/6d10533f6a045c77606a5676415a626a0f273467',},{title:'adguard home的doh服务终于搭建成功了',url:'/d/69707b0c6a045c77606a567641586b6a5d361b64',},{title:'Nginx 四层反代 QUIC 如何传递客户端 IP',url:'/d/23317e046a045c77606a5671435a626a0a1a0562',},{title:'一个宝塔装两个网站怎么操作?在哪选占用端口,总不能都是80吧',url:'/d/6d0874286a045c77606a5670405c676a02273d03',},{title:'有闲置的服务器,只能用nginx,没办法开其他端口',url:'/d/177045276a045c77606a5672425d606a2f70251e',},],} const App={setup(){const goTo=useGoTo() const{mdAndUp}=useDisplay() return{goTo,mdAndUp}},data(){return data;},mounted(){const themeDark=localStorage.getItem("themeDark") if(themeDark!==null){this.theme.dark=JSON.parse(themeDark)} if(this.nav.post.total>(this.nav.post.currentPage-1)*100+20){let moreLen=100 if(this.nav.post.total({id:null,num:(this.nav.post.currentPage-1)*100+v,uid:null,content:null,ipRegion:null,updatedByUid:null,createdAt:null,updatedAt:null,mentionNum:null,mentionedBy:null,mentionUsers:null,likeUsers:null,})) this.posts.push(...morePosts.slice(20))} this.workerStart() const hash=window.location.hash const match=hash.match(/#(\d+)/) if(match){const n=parseInt(match[1],10) if(n>=(this.nav.post.currentPage-1)*100&&n{this.jumpTo(n)})}} this.$nextTick(()=>{this.addHeadingIds() tocbot.init({tocSelector:'.toc',contentSelector:'#post-content-0',headingSelector:'h2, h3, h4',headingsOffset:100,scrollSmoothOffset:-100,scrollSmooth:true,collapseDepth:6,onClick:function(e){setTimeout(()=>{history.replaceState(null,'',window.location.pathname+window.location.search)},0)},}) tocbot.refresh()});},beforeUnmount(){this.workerStop() if(this.quill){this.quill.destroy() this.quill=null}},computed:{dposts(){return this.posts.slice(20);},},created(){},methods:{successAlert(msg){this.alert={show:true,color:'success',text:msg,timeout:1500,}},failureAlert(msg){this.alert={show:true,color:'error',text:msg,timeout:5000,}},flipThemeDark(){this.theme.dark=!this.theme.dark localStorage.setItem("themeDark",JSON.stringify(this.theme.dark))},toSearch(){if(!this.search.text){this.failureAlert('搜索词不能为空') return} let keywords=this.search.text.trim() if(keywords.length<1){this.failureAlert('搜索词不能为空') return} if(keywords.length>100){this.failureAlert('搜索词过长') return} this.doSearch(keywords)},toReg(){window.location.href="/reg"},toLogin(){window.location.href="/login"},toPage(){let url=window.location.href url=url.replace(/(\/\d+)?(#[0-9]+)?$/,this.nav.post.targetPage>1?`/${this.nav.post.targetPage}`:'') window.location.href=url},toLoadRelated({done}){if(this.my&&this.my.uid){this.apiLoadRelated({done})}else{done('ok')}},workerStart(){this.nav.post.worker=setInterval(()=>{this.workerLoad()},500);},workerStop(){if(this.nav.post.worker){clearInterval(this.nav.post.worker);this.nav.post.worker=null;}},async jumpTo(num){const page=Math.floor(num/100)+1 const i=num-(page-1)*100 if(page===this.nav.post.currentPage){this.goTo("#post-"+num,this.nav.post.goToOptions) if(!this.posts[i].id){const block=Math.floor(num/20)+1 this.nav.post.apiLock[block]=true await this.apiLoadPosts(block) this.$nextTick(()=>{this.goTo("#post-"+num,this.nav.post.goToOptions)})}}else{let url=window.location.href url=url.replace(/(\/\d+)?(#[0-9]+)?$/,page>1?`/${page}`:'') url=url+"#"+num window.location.href=url}},postIntersect(num){return(isIntersecting,entries,observer)=>{if(isIntersecting){this.nav.post.task.push(num) this.nav.post.active.push(num) this.nav.post.active=this.nav.post.active.filter(item=>Math.abs(item-num)<=5) this.nav.post.active.sort((a,b)=>a-b)}else{this.nav.post.active=this.nav.post.active.filter(item=>item!==num)} if(this.nav.post.active[0]){this.nav.post.anchor=this.nav.post.active[0]}else{this.nav.post.anchor=0}}},async apiLoadPosts(block){try{const response=await axios.post('/fapi/v1/post/block/'+block,{discussionId:this.nav.post.discussionId,}) if(response.data.code===0){response.data.data.posts.forEach(post=>{const i=post.num%100 Object.assign(this.posts[i],post)}) response.data.data.users.forEach(user=>{this.usersMap.set(user.uid,user)})}else{this.failureAlert('回帖数据加载失败: '+response.data.msg)}}catch(error){this.failureAlert('回帖数据加载失败: '+error)} this.nav.post.apiLock[block]=false},workerLoad(){while(this.nav.post.task.length){const num=this.nav.post.task.pop() const i=num-(this.nav.post.currentPage-1)*100 if(!this.posts[i].id){const block=Math.floor(num/20)+1 if(!this.nav.post.apiLock[block]){this.nav.post.apiLock[block]=true this.apiLoadPosts(block)}}}},getTimeInfo(t){if(!t){return ""} const now=new Date();const then=new Date(t);const diff=now-then;const minute=60*1000;const hour=minute*60;const day=hour*24;const month=day*30;const year=month*12;if(diffpost.num===num) if(!post){return "#"+num} const uid=post.uid const username=this.usersMap.get(uid)?.username if(!username){return "#"+num} return username},getUsernameByPostId(id){const post=this.posts.find(post=>post.id===id) if(!post){return "#"+this.getPostNumByPostId(id)} const uid=post.uid const username=this.usersMap.get(uid).username if(!username){return "#"+this.getPostNumByPostId(id)} return username},getPostNumByPostId(id){const post=this.posts.find(post=>post.id===id) return post.num},getPostById(id){const post=this.posts.find(post=>post.id===id) return post},getPostByNum(num){const post=this.posts.find(post=>post.num===num) return post},getAvatarByUid(uid){const avatar=this.usersMap.get(uid)?.avatar if(!avatar){return this.getRandomAvatar()} return avatar},getAvatarByPostNum(num){const post=this.posts.find(post=>post.num===num) if(!post){return this.getRandomAvatar()} const uid=post.uid return this.getAvatarByUid(uid)},getRandomAvatar(){const num=Math.floor(Math.random()*100) return "https://randomuser.me/api/portraits/men/"+num+".jpg"},getUrlByUid(uid){const url=this.usersMap.get(uid)?.url if(!url){return ""} return url},getTextByPostNum(num){const post=this.posts.find(post=>post.num===num) if(!post||!post.content){return '点击跳转到#'+num+'查看'} const parser=new DOMParser() const doc=parser.parseFromString(post.content,'text/html') const text=doc.body.textContent||'' return text.slice(0,100)},addHeadingIds(){const content=document.getElementById('post-content-0') if(!content){this.nav.showTOC=false return} const headings=content.querySelectorAll('h2, h3, h4') headings.forEach((heading,index)=>{if(!heading.id){heading.id=`toc-nav-${index}`}}) if(headings.length==0){this.nav.showTOC=false}},async doSearch(keywords){this.search.loading=true try{const response=await axios.post('/fapi/v1/search',{keywords:keywords,}) if(response.data.code===0){if(response.data.data.hash&&response.data.data.hash.length===32){window.location.href="/s/"+response.data.data.hash}else{this.failureAlert('搜索失败: 搜索服务异常')}}else{this.failureAlert('搜索失败: '+response.data.msg)}}catch(error){this.failureAlert('搜索失败: '+error)} this.search.loading=false},debounce(fn,delay){let timer=null return function(...args){if(timer)clearTimeout(timer) timer=setTimeout(()=>{fn.apply(this,args)},delay);};},},watch:{'nav.post.targetPage':{handler:async function(newV,oldV){this.toPage()},immediate:false},},} const vuetify=createVuetify({defaults:{global:{ripple:true,},},}) const app=createApp(App) app.use(vuetify).mount("#app")