PageSourceSearch

https://www.sokany.com/src/local.js

js sokany.com collected 2026-10-06 13:24:02 UTC 1,841 bytes, 73 lines download raw bytes

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.