unknown
2024-06-11 3ab32c568f8cf9bb42ab224482195dac44a85a36
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import SparkMD5 from "spark-md5";
 
export function getFileMd5(file, chunkSize) {
  return new Promise((resolve, reject) => {
    let blobSlice =
      File.prototype.slice ||
      File.prototype.mozSlice ||
      File.prototype.webkitSlice;
    let chunks = Math.ceil(file.size / chunkSize);
    let currentChunk = 0;
    let spark = new SparkMD5.ArrayBuffer();
    let fileReader = new FileReader();
    fileReader.onload = function (e) {
      spark.append(e.target.result);
      currentChunk++;
      if (currentChunk < chunks) {
        loadNext();
      } else {
        const md5 = spark.end();
        resolve(md5);
      }
    };
    fileReader.onerror = function (e) {
      reject(e);
    };
    function loadNext() {
      let start = currentChunk * chunkSize;
      let end = start + chunkSize;
      if (end > file.size) {
        end = file.size;
      }
      fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
    }
    loadNext();
  });
}
 
// 获取不受保护的图片
export function getPublicImage(md5, width, height) {
  let src = null;
  if (md5) {
    src = process.env.VUE_APP_API_URL + `/file/GetPreViewImage?md5=${md5}`;
  } else {
    return "";
  }
  if (width) src += `&width=${width}`;
  if (height) src += `&height=${height}`;
  return src;
}