PageSourceSearch

https://lingyuzhao.top/js/diskMirror.min.js

js lingyuzhao.top collected 2026-10-06 13:16:08 UTC 19,666 bytes, 324 lines download raw bytes

1class DiskMirror{constructor(url){this.diskMirrorUrl=url;this.setSk();this.setController('/FsCrud')}xorEncrypt(value){let encrypted=value;const sk_str=this.sk.toString();for(let i=0;i<sk_str.length;i++){encrypted-=sk_str.charCodeAt(i)<<1}return encrypted}setController(controllerName){this.controller=controllerName}getController(){return this.controller}setSk(key=0,domain=undefined){this.sk=key;if(key!==0){this.setDiskMirrorXorSecureKey(domain)}}getSk(){return this.sk}upload(params,file,okFun=undefined,errorFun=(e)=>'res'in e?alert(e['res']):alert(e),checkFun=undefined){if(checkFun!==undefined&&!checkFun(params,file)){return}const formData=new FormData();params["secure.key"]=this.getSk();const blob=new Blob([JSON.stringify(params)],{type:'application/json'});formData.append('params',blob,"params");formData.append('file',file,"file");axios.defaults.withCredentials=true;axios({method:'post',url:this.diskMirrorUrl+this.getController()+'/add',data:formData,headers:{'Content-Type':'multipart/form-data'}}).then(function(res){if(res.data['res']!=='ok!!!!'){if(errorFun!==undefined){errorFun(res.data)}return}if(okFun!==undefined){okFun(res.data)}else{console.info(res.data)}}).catch(function(err){if(errorFun!==undefined){errorFun(err)}else{console.error(err)}})}getUrls(userId,type,okFun=undefined,errorFun=(e)=>'res'in e?alert(e['res']):alert(e),checkFun=undefined,){if(userId===undefined||type===undefined||type===''){const err="您必须要输入 userId 以及 type 参数才可以进行 url 的获取";if(errorFun!==undefined){errorFun(err)}else{console.error(err)}return}const formData=new FormData();const params={userId:userId,type:type,"secure.key":this.getSk()};if(checkFun!==undefined&&!checkFun(params)){return}const blob=new Blob([JSON.stringify(params)],{type:'application/json'});formData.append('params',blob,"params");axios.defaults.withCredentials=true;axios({method:'post',url:this.diskMirrorUrl+this.getController()+'/getUrls',data:formData,headers:{'Content-Type':'multipart/form-data'}}).then(function(res){if(res.data['res']!=='ok!!!!'){if(errorFun!==undefined){errorFun(res.data)}return}if(okFun!==undefined){okFun(res.data)}else{console.info(res.data)}}).catch(function(err){if(errorFun!==undefined){errorFun(err)}else{console.error(err)}})}remove(userId,type,fileName,okFun=undefined,errorFun=(e)=>'res'in e?alert(e['res']):alert(e),checkFun=undefined,){if(userId===undefined||type==null||type===''||fileName===undefined||fileName===''){const err="您必须要输入 userId 以及 type 和 fileName 参数才可以进行删除";if(errorFun!==undefined){errorFun(err)}else{console.error(err)}return}const formData=new FormData();const params={fileName:fileName,userId:userId,type:type,"secure.key":this.getSk()};if(checkFun!==undefined&&!checkFun(params)){return}const blob=new Blob([JSON.stringify(params)],{type:'application/json'});formData.append('params',blob,"params");axios.defaults.withCredentials=true;axios({method:'post',url:this.diskMirrorUrl+this.getController()+'/remove',data:formData,headers:{'Content-Type':'multipart/form-data'}}).then(function(res){if(res.data['res']!=='ok!!!!'){if(errorFun!==undefined){errorFun(res.data)}return}if(okFun!==undefined){okFun(res.data)}else{console.info(res.data)}}).catch(function(err){if(errorFun!==undefined){errorFun(err)}else{console.error(err)}})}reName(userId,type,fileName,newName,okFun=undefined,errorFun=(e)=>'res'in e?alert(e['res']):alert(e),checkFun=undefined){if(userId===undefined||type==null||type===''||fileName===undefined||fileName===''||newName===undefined||newName===''){const err="您必须要输入 userId 和 type 以及 fileName 和 newName 参数才可以进行重命名";if(errorFun!==undefined){errorFun(err)}else{console.error(err)}return}const formData=new FormData();const params={fileName:fileName,newName:newName,userId:userId,type:type,"secure.key":this.getSk()};if(checkFun!==undefined&&!checkFun(params)){return}const blob=new Blob([JSON.stringify(params)],{type:'application/json'});formData.append('params',blob,"params");axios.defaults.withCredentials=true;axios({method:'post',url:this.diskMirrorUrl+this.getController()+'/reName',data:formData,headers:{'Content-Type':'multipart/form-data'}}).then(function(res){if(res.data['res']!=='ok!!!!'){if(errorFun!==undefined){errorFun(res.data)}return}if(okFun!==undefined){okFun(res.data)}else{console.info(res.data)}}).catch(function(err){if(errorFun!==undefined){errorFun(err)}else{console.error(err)}})}mkdirs(userId,type,fileName,okFun=undefined,errorFun=(e)=>'res'in e?alert(e['res']):alert(e),checkFun=undefined){if(userId===undefined||t
1ype==null||type===''||fileName===undefined||fileName===''){const err="您必须要输入 userId 和 type 以及 fileName 参数才可以进行文件目录的创建";if(errorFun!==undefined){errorFun(err)}else{console.error(err)}return}const formData=new FormData();const params={fileName:fileName,userId:userId,type:type,"secure.key":this.getSk()};if(checkFun!==undefined&&!checkFun(params)){return}const blob=new Blob([JSON.stringify(params)],{type:'application/json'});formData.append('params',blob,"params");axios.defaults.withCredentials=true;axios({method:'post',url:this.diskMirrorUrl+this.getController()+'/mkdirs',data:formData,headers:{'Content-Type':'multipart/form-data'}}).then(function(res){if(res.data['res']!=='ok!!!!'){if(errorFun!==undefined){errorFun(res.data)}return}if(okFun!==undefined){okFun(res.data)}else{console.info(res.data)}}).catch(function(err){if(errorFun!==undefined){errorFun(err)}else{console.error(err)}})}downLoad(userId,type,fileName,okFun=undefined,errorFun=(e)=>'res'in e?alert(e['res']):alert(e),checkFun=undefined,version=1){if(userId===undefined||type==null||type===''||fileName===undefined||fileName===''||okFun===undefined){const err="您必须要输入 userId 和 type 以及 fileName 和 okFun 参数才可以进行文件对象的获取!";if(errorFun!==undefined){errorFun(err)}else{console.error(err)}return}if(checkFun!==undefined&&!checkFun({userId:userId,type:type,fileName:fileName})){return}okFun(version<2?this.diskMirrorUrl+this.getController()+`/downLoad/${userId}/${type}?fileName=${fileName}` : this.diskMirrorUrl + this.getController() + `/downLoad2/${userId}/${type}/${this.getSk()}/${fileName.startsWith('/') ? fileName.substring(1) : fileName}`);
2}
3
4    /**
5     * 向后端中转存一个文件
6     * @param params {{
7     *      fileName: string,
8     *      userId: int,
9     *      type: 'Binary'|'TEXT',
10     *      url: string
11     * }} 这里是请求参数对象 其中的文件名字代表上传到后端之后的文件名字,userId 代表的就是文件要上传到的指定空间的id;type就是代表的文件的类型 支持二进制和文本两种格式
12     * @param okFun {function} 操作成功之后的回调函数 输入是被上传文件的json对象
13     * @param errorFun {function} 操作失败之后的回调函数 输入是错误信息
14     * @param checkFun {function} 上传前的检查函数 输入是上传的文件对象的 json 数据 ,如果返回的是一个false 则代表不进行上传操作
15     */
16    transferDeposit(params, okFun = undefined, errorFun = (e) => 'res' in e ? alert(e['res']) : alert(e), checkFun = undefined) {
17        if (checkFun !== undefined && !checkFun(params)) {
18            return;
19        }
20        const formData = new FormData();
21        // 设置请求参数数据包
22        params["secure.key"] = this.getSk();
23        const blob = new Blob([JSON.stringify(params)], {
24            type: 'application/json'
25        });
26        formData.append('params', blob, "params");
27        // 开始进行请求发送
28        axios.defaults.withCredentials = true;
29        axios(
30            {
31                method: 'post',
32                url: this.diskMirrorUrl + this.getController() + '/transferDeposit',
33                data: formData,
34                headers: {
35                    'Content-Type': 'multipart/form-data'
36                }
37            }
38        ).then(function (res) {
39            if (res.data['res'] !== 'ok!!!!') {
40                if (errorFun !== undefined) {
41                    errorFun(res.data);
42                }
43                return;
44            }
45            // 处理成功
46            if (okFun !== undefined) {
47                okFun(res.data);
48            } else {
49                console.info(res.data);
50            }
51        }).catch(function (err) {
52            // 处理错误
53            if (errorFun !== undefined) {
54                errorFun(err);
55            } else {
56                console.error(err);
57            }
58        });
59    }
60
61    /**
62     * 向后端中查询文件转存情况
63     * @param params {{
64     *      userId: int,
65     *      type: 'Binary'|'TEXT',
66     * }} 这里是请求参数对象 其中的文件名字代表上传到后端之后的文件名字,userId 代表的就是文件要上传到的指定空间的id;type就是代表的文件的类型 支持二进制和文本两种格式
67     * @param okFun {function} 操作成功之后的回调函数 输入是被上传文件的json对象
68     * @param errorFun {function} 操作失败之后的回调函数 输入是错误信息
69     * @param checkFun {function} 上传前的检查函数 输入是上传的文件对象的 json 数据 以及 文件对象本身,如果返回的是一个false 则代表不进行上传操作
70     */
71    transferDepositStatus(params, okFun = undefined, errorFun = (e) => 'res' in e ? alert(e['res']) : alert(e), checkFun = undefined) {
72        if (checkFun !== undefined && !checkFun(params)) {
73            return;
74        }
75        const formData = new FormData();
76        // 设置请求参数数据包
77        params["secure.key"] = this.getSk();
78        const blob = new Blob([JSON.stringify(params)], {
79            type: 'application/json'
80        });
81        formData.append('params', blob, "params");        // 开始进行请求发送
82        axios.defaults.withCredentials = true;
83        axios(
84            {
85                method: 'post',
86                url: this.diskMirrorUrl + this.getController() + '/transferDepositStatus',
87                data: formData,
88                headers: {
89                    'Content-Type': 'multipart/form-data'
90                }
91            }
92        ).then(function (res) {
93            // 处理成功
94            if (okFun !== undefined) {
95                okFun(res.data);
96            } else {
97                console.info(res.data);
98            }
99        }).catch(function (err) {
100            // 处理错误
101            if (errorFun !== undefined) {
102                errorFun(err);
103            } else {
104                console.error(err);
105            }
106        });
107    }
108
109    /**
110     * 获取指定空间的最大容量 单位是 字节
111     *
112     * 需要确保远程的 diskMirror 服务器是在 2024年 2 月 17 日 以及之后发布的!!
113     *
114     * @param userId {int} 需要被检索的空间id
115     * @param okFun {function} 操作成功之后的回调函数 输入是被创建的文件目录的json对象
116     * @param errorFun {function} 操作失败之后的回调函数 输入是错误信息
117     */
118    getSpaceMaxSize(userId, okFun = undefined, errorFun = (e) => 'res' in e ? alert(e['res']) : alert(e)) {
119        // 开始进行请求发送
120        axios.defaults.withCredentials = true;
121        axios(
122            {
123                method: 'post',
124                url: this.diskMirrorUrl + this.getController() + '/getSpaceSize',
125                params: {
126                    spaceId: userId.toString()
127                }
128            }
129        ).then(function (res) {
130            const data = res.data;
131            if (isNaN(data['res'])) {
132                if (errorFun !== undefined) {
133                    errorFun(data['res'] + " is NAN!!!");
134                }
135                return;
136            }
137            if (okFun !== undefined) {
138                okFun(data['res']);
139            } else {
140                console.info(data['res']);
141            }
142        }).catch(function (err) {
143            if (errorFun !== undefined) {
144                errorFun(err);
145            } else {
146                console.error(err);
147            }
148        });
149    }
150
151    /**
152     * 获取后端中的盘镜内核的版本
153     *
154     * 需要确保远程的 diskMirror 服务器是在 2024年 2 月 17 日 以及之后发布的!!
155     *
156     * @param okFun {function} 操作成功之后的回调函数 输入是被创建的文件目录的json对象
157     * @param errorFun {function} 操作失败之后的回调函数 输入是错误信息
158     */
159    getVersion(okFun = undefined, errorFun = (e) => 'res' in e ? alert(e['res']) : alert(e)) {
160        // 开始进行请求发送
161        axios.defaults.withCredentials = true;
162        axios(
163            {
164                method: 'post',
165                url: this.diskMirrorUrl + this.getController() + '/getVersion',
166            }
167        ).then(function (res) {
168            if (okFun !== undefined) {
169                okFun(res.data);
170            } else {
171                console.info(res.data);
172            }
173        }).catch(function (err) {
174            if (errorFun !== undefined) {
175                errorFun(err);
176            } else {
177                console.error(err);
178            }
179        });
180    }
181
182    /**
183     * 获取指定空间的已使用容量 单位是 字节
184     * @param userId {int} 需要被检索的空间id
185     * @param type {'Binary'|'TEXT'} 需要被检索的文件类型
186     * @param okFun {function} 操作成功之后的回调函数 输入是计算出来的已使用容量
187     * @param errorFun {function} 操作失败之后的回调函数 输入是错误信息
188     */
189    getUseSize(userId, type, okFun = undefined, errorFun = (e) => 'res' in e ? alert(e['res']) : alert(e)) {
190        if (userId === undefined || type == null || type === '') {
191            const err = "您必须要输入 userId 和 type 参数才可以进行使用数量的获取";
192            if (errorFun !== undefined) {
193                errorFun(err);
194            } else {
195                console.error(err);
196            }
197            return;
198        }
199        const formData = new FormData();
200        // 设置请求参数
201        const params = {
202            userId: userId,
203            type: type,
204            "secure.key": this.getSk()
205        };
206        const blob = new Blob([JSON.stringify(params)], {
207            type: 'application/json'
208        });
209        formData.append('params', blob, "params");
210
211        // 开始进行请求发送
212        axios.defaults.withCredentials = true;
213        axios(
214            {
215                method: 'post',
216                url: this.diskMirrorUrl + this.getController() + '/getUseSize',
217                data: formData,
218                headers: {
219                    'Content-Type': 'multipart/form-data'
220                }
221            }
222        ).then(function (res) {
223            if (okFun !== undefined) {
224                okFun(res.data);
225            } else {
226                console.info(res.data);
227            }
228        }).catch(function (err) {
229            if (errorFun !== undefined) {
230                errorFun(err);
231            } else {
232                console.error(err);
233            }
234        });
235    }
236
237    /**
238     * 在一些操作中,我们可能需要将 sk 包含在 cookie 中,因此可能会需要使用这个函数,这个函数一般来说不需要用户手动调用!
239     *
240     * 因为在设置好 sk 的时候,它会自动被调用!请勿随意修改此函数带来的cookie,某些后端服务会使用到!
241     *
242     * @param domain {string} 需要被设置的cookie的域名 默认是当前域
243     */
244    setDiskMirrorXorSecureKey(domain) {
245        // 检查名为 diskMirror_xor_secure_key 的 cookie 是否存在
246        const cookieName = 'diskMirror_xor_secure_key';
247        // 如果存在就更新 cookie 的值
248        const encryptedValue = this.xorEncrypt(this.getSk());
249        if (this.isSetCookie && this.cookieValue === encryptedValue && this.cookieDoMain === domain) {
250            // 如果设置过 cookie 且 值 和 域 相同 则这里就不继续更新 cookie 了
251            return;
252        }
253        if (domain) {
254            document.cookie = `${cookieName}=${encryptedValue};path=/;domain=${domain}`;
255            return;
256        }
257        document.cookie = `${cookieName}=${encryptedValue};path=/`;
258        // 标记 cookie 信息
259        this.isSetCookie = true;
260        this.cookieValue = encryptedValue;
261        this.cookieDoMain = domain;
262    }
263
264    /**
265     * 获取指定空间的所有的进度条
266     * @param userId {int|string} 指定要获取到的文件进度数据对应的空间id
267     * @param okFun {function} 操作成功之后的回调函数 输入是被文件进度的json对象
268     * @param errorFun {function} 操作失败之后的回调函数 输入是错误信息
269     * @param checkFun {function} 操作前的检查函数 输入是请求参数对象,如果返回的是一个false 则代表检查失败不继续操作
270     */
271    getAllProgressBar(userId, okFun = undefined, errorFun = (e) => 'res' in e ? alert(e['res']) : alert(e), checkFun = undefined) {
272        if (userId === undefined || okFun === undefined) {
273            const err = "您必须要输入 userId 和 okFun 参数才可以进行文件对象的获取!";
274            if (errorFun !== undefined) {
275                errorFun(err);
276            } else {
277                console.error(err);
278            }
279            return;
280        }
281        if (checkFun !== undefined && !checkFun(userId)) {
282            return;
283        }
284        axios.defaults.withCredentials = true;
285        // 开始获取
286        axios(
287            {
288                method: 'post',
289                url: this.diskMirrorUrl + this.getController() + '/getAllProgressBar',
290                params: {
291                    id: userId
292                }
293            }
294        ).then(function (res) {
295            // 处理成功
296            if (okFun !== undefined) {
297                okFun(res.data);
298            } else {
299                console.info(res.data);
300            }
301        }).catch(function (err) {
302            // 处理错误
303            if (errorFun !== undefined) {
304                errorFun(err);
305            } else {
306                console.error(err);
307            }
308        });
309    }
310
311    /**
312     * 将当前客户端连接的服务器关机(如果服务器端受支持的话,则会返回关机或有效信息)
313     *
314     * @param password {string} 关机操作的校验码,如果校验码不正确,则无法处理关机请求
315     * @param okFun {function} 操作成功之后的回调函数 输入是被文件进度的json对象
316     * @param errorFun {function} 操作失败之后的回调函数 输入是错误信息
317     */
318    shutdown(password, okFun = undefined, errorFun = (e) => 'res' in e ? alert(e['res']) : alert(e)) {
319        axios.defaults.withCredentials = true;
320        // 开始获取
321        axios(
322            {
323                method: 'post',
324                url: this.diskMirrorUrl + this.getController() + '/shutdown',params:{password:password}}).then(function(res){if(okFun!==undefined){okFun(res.data)}else{console.info(res.data)}}).catch(function(err){if(errorFun!==undefined){errorFun(err)}else{console.error(err)}})}}

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.