PageSourceSearch

https://nimg1.hicustom.com/static/frontend/js/customRenders.js

js hicustom.com collected 2026-09-26 08:31:54 UTC 4,119 bytes, 145 lines download raw bytes

1const defaultPath = 'https://obs-hm102.hihumbird.com/attach/default.png';
2const standby = '-clone';
3const envPrefix = 'obs.domain.'
4
5class CustomRender {
6  env_content = {}
7  constructor(EffectRenderInstance, env_content) {
8    this.EffectRenderInstance = EffectRenderInstance
9    this.env_content = env_content || {}
10  }
11
12  async customRenders (data, effectImagePathKey, cusProIdKey, size = 500) {
13    if (!Array.isArray(data)) data = [data];
14    await this.inspectEfFinished(data, effectImagePathKey, size);
15    this.setDefaultPath(data, effectImagePathKey);
16    for (const item of data) {
17      if (item.efFinished) continue;
18      await this.customRender(item, effectImagePathKey, cusProIdKey);
19    }
20  }
21  // 批量判断图片
22  async inspectEfFinished (data, effectImagePathKey, size) {
23    const promises = data.map((item) => {
24      return this.checkImagePath(item, effectImagePathKey, size);
25    });
26    await Promise.all(promises);
27  }
28  async checkImagePath (item, effectImagePathKey, size) {
29    const effectImagePath = item[effectImagePathKey];
30    const effectImagefullPath = this.getFullPathWithSize(effectImagePath, size);
31    try {
32      const ok = await this.checkImgExists(effectImagefullPath);
33      item.efFinished = ok;
34    } catch (error) {
35      item.efFinished = false;
36    }
37  }
38  getFullPath(path = '') {
39    if (path.startsWith('http') || !path) {
40      return path;
41    }
42    const key = envPrefix + path.split('/')[0];
43    const host = this.env_content[key];
44    if (path?.startsWith('/')) {
45      return host + path;
46    }
47    return host + '/' + path;
48  }
49  getFullPathWithSize(path, size) {
50    if (path.startsWith('http') || !path) {
51      return path;
52    }
53    const fullPath = this.getFullPath(path);
54    if (
55      size &&
56      fullPath &&
57      fullPath.indexOf('x-image-process=') == -1 &&
58      fullPath.indexOf('style=') == -1 &&
59      !this.isBlobURL(fullPath)
60    ) {
61      return `${fullPath}?x-image-process=style/s${size}`;
62    } else {
63      return fullPath;
64    }
65  }
66  isBlobURL(src) {
67    try {
68      const url = new URL(src);
69      return url.protocol === 'blob:';
70    } catch (e) {
71      // 如果src不是有效的URL,则不是blob类型
72      return false;
73    }
74  }
75  checkImgExists(imgurl) {
76    return new Promise(function (resolve, reject) {
77      if (!imgurl) {
78        resolve(true);
79        return;
80      }
81      const img = new Image();
82      img.onload = function () {
83        resolve(true);
84      };
85      img.onerror = function () {
86        reject();
87      };
88      img.src = imgurl;
89    });
90  }
91  async customRender (item, effectImagePathKey, cusProIdKey) {
92    const effectImagePath = item[effectImagePathKey + standby];
93    if (!effectImagePath) return;
94    const cusProId = item[cusProIdKey];
95    const { effectImageBlob } = await this.EffectRenderInstance.uploadEffectImage({
96      cusProId,
97      effectImagePath,
98      needCheckImagePath: false,
99      // isDev: true,
100    });
101    const path = this.getPath(effectImageBlob);
102    item[effectImagePathKey] = path;
103  }
104  getPath (effectImageBlob) {
105    const toString = Object.prototype.toString;
106    let path = '';
107    if (effectImageBlob) {
108      if (toString.call(effectImageBlob) === `[object String]`) {
109        path = effectImageBlob;
110      } else {
111        path = URL.createObjectURL(effectImageBlob);
112      }
113    }
114    return path;
115  }
116  setDefaultPath (data, effectImagePathKey) {
117    for (const item of data) {
118      if (item.efFinished) continue;
119      item[effectImagePathKey + standby] = item[effectImagePathKey];
120      item[effectImagePathKey] = defaultPath;
121    }
122  }
123
124  getJitImageDomain (jitToken) {
125    return new Promise((resolve, reject) => {
126      $.ajax({
127        type: 'GET',
128        url: `${getJitApiDomain()}/envs`,
129        headers: {
130          Authorization: jitToken ? `Bearer ${jitToken}` : ''
131        },
132        data: {
133          plugin_codes: 'env_content'
134        },
135        success: (res) => {
136          this.env_content = res.data?.env_content || {}
137          resolve(res)
138        },
139        error: (err) => {
140          reject(err)
141        }
142      })
143    })
144  }
145}

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.