PageSourceSearch

http://www.miaomiaoce.com/js/download.js

js miaomiaoce.com collected 2026-09-25 20:20:16 UTC 2,781 bytes, 75 lines download raw bytes

1    // 当按钮点击时获取预签名URL并下载
2    function getSignedUrlAndDownload(fileName) {
3    // const privacyUrl = "http://api.miaomiaoce.com:4301/generate_presigned_url/?file_name=" + fileName;
4    const privacyUrl = "https://api.miaomiaoce.com:4301/generate_presigned_url/?file_name=" + encodeURIComponent(fileName)
5    fetch(privacyUrl)
6    .then(response => {
7    if (!response.ok) {
8    throw new Error('Network response was not ok ' + response.statusText);
9}
10    return response.json();  // 假设返回的是 JSON 格式
11})
12    .then(data => {
13    // 假设返回的数据中有 `url` 字段
14    const downloadUrl = data.url;
15    if (downloadUrl) {
16    // 直接下载文件
17    // window.location.href = downloadUrl;
18    // downloadFile(downloadUrl, fileName);
19        window.open(downloadUrl, '_blank');
20
21} else {
22    console.error('No URL found in the response:', data);
23}
24})
25    .catch(error => {
26    console.error('Fetch error for file:', fileName, error);
27});
28}
29
30    function downloadFile(url, filename) {
31    // 使用fetch API获取文件
32    fetch(url)
33        .then(response => {
34            // 确保响应是成功的
35            if (!response.ok) {
36                throw new Error('Network response was not ok.');
37            }
38            // 将响应体转换为Blob
39            return response.blob();
40        })
41        .then(blob => {
42            // 创建一个指向Blob的URL
43            const blobUrl = window.URL.createObjectURL(blob);
44            // 创建一个<a>元素并设置href为Blob URL
45            const link = document.createElement('a');
46            link.href = blobUrl;
47            link.download = filename || 'downloaded.file'; // 设置下载的文件名
48            // 将<a>元素隐藏
49            link.style.display = 'none';
50            // 将<a>元素添加到文档中
51            document.body.appendChild(link);
52            // 触发点击事件以下载文件
53            link.click();
54            // 清理:移除<a>元素并释放Blob URL
55            document.body.removeChild(link);
56            window.URL.revokeObjectURL(blobUrl);
57        })
58        .catch(error => {
59            console.error('There was a problem with the download:', error);
60        });
61}
62
63    // 使用方法
64    // downloadFile('https://example.com/path/to/file', 'desired-filename.ext');
65
66
67    // 为所有下载按钮添加事件监听
68    document.querySelectorAll('.btn-download').forEach(button => {
69    const fileName = button.getAttribute('data-filename');
70
71    button.addEventListener('click', function(event) {
72    event.preventDefault(); // 防止默认行为
73    getSignedUrlAndDownload(fileName); // 调用函数获取预签名URL并下载
74});
75});

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.