1class Local { 2 /** 3 * æé 彿° 4 */ 5 constructor(ctx) { 6 this.ctx = ctx 7 this.localData = { 8 request_time: new Date(), 9 domain: '', 10 pathname: '', 11 log: this.ctx.query.log || 0, 12 static: this.ctx.query.static || 0, 13 apiList: [] 14 } 15 } 16 17 /** 18 * åå§å 19 */ 20 init() { 21 // 计ç®åååè·¯å¾ 22 this.calcUrl() 23 // è¿åå¤çå¥½çæ°æ® 24 return this.localData 25 } 26 27 /** 28 * 计ç®åååè·¯å¾ 29 */ 30 calcUrl() { 31 const cookieDomain = this.ctx.cookies.get('domain') 32 if (this.ctx.query.url) { 33 // 妿æä¼ urlåæ°ï¼åæå为ååå¨åå°cookieä¸ï¼ç¶åéå®åå°å½åè·¯å¾ 34 let tempUrl = this.ctx.query.url 35 tempUrl = tempUrl.replace('http://', '') 36 tempUrl = tempUrl.replace('https://', '') 37 const urlArr = tempUrl.split('/') 38 const domain = urlArr.shift() 39 const pathname = urlArr.join('/') 40 if (/[\w\.]/.test(domain)) { 41 // åå夿 42 this.setDomain(domain) 43 if (pathname) this.ctx.state.redirect(303, `${pathname}?url=${domain}`) 44 } 45 } 46 47 if (this.localData.domain === '') { 48 // ä¼ åå¹é ä¸å°ï¼åç¨host 49 if (this.ctx.query.host || !cookieDomain || cookieDomain === 'undefined') { 50 this.setDomain(this.ctx.query.host ?? this.ctx.host) 51 } else if (cookieDomain) { 52 this.localData.domain = cookieDomain 53 } 54 } 55 this.localData.pathname = this.ctx.path 56 } 57 58 /** 59 * 设置ååï¼åå°cookieä¸ 60 */ 61 setDomain(domain) { 62 const domainList = domain.split('.') 63 if (domainList.length > 0) { 64 if (domainList[0] === 'www') { 65 domain = domain.replace('www.', '') 66 } 67 } 68 this.localData.domain = domain 69 this.ctx.cookies.set('domain', domain, { httpOnly: false }) 70 } 71} 72 73export default Local
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.