Skip to content

Commit

Permalink
fix: do not reload a same resource
Browse files Browse the repository at this point in the history
  • Loading branch information
vcheckzen committed Sep 20, 2024
1 parent 262f14a commit 38b51d3
Showing 1 changed file with 36 additions and 33 deletions.
69 changes: 36 additions & 33 deletions front-end/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,14 @@
}
},
loadResource: (resource, callback) => {
const rid = btoa(resource);
if (document.getElementById(rid)) {
if (typeof callback === 'function') {
callback();
}
return;
}

let type;
switch (resource.split('.').pop()) {
case 'css':
Expand All @@ -1136,7 +1144,9 @@
type = 'script';
break;
}
let element = document.createElement(type);
const element = document.createElement(type);
element.id = rid;

let loaded = false;
if (typeof callback === 'function') {
element.onload = element.onreadystatechange = () => {
Expand All @@ -1163,16 +1173,15 @@
createDplayer: (video, type, elem) => {
const host = '//lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M';
const resources = [
// '//cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js',
host + '/hls.js/1.1.5/hls.light.min.js',
host + '/flv.js/1.6.2/flv.min.js',
host + '/dplayer/1.25.0/DPlayer.min.css',
host + '/dplayer/1.25.0/DPlayer.min.js',
'/hls.js/1.1.5/hls.light.min.js',
'/flv.js/1.6.2/flv.min.js',
'/dplayer/1.25.0/DPlayer.min.css',
'/dplayer/1.25.0/DPlayer.min.js',
];

let unloadedResourceCount = resources.length;
resources.forEach((resource) => {
previewHandler.loadResource(resource, () => {
previewHandler.loadResource(host + resource, () => {
if (!--unloadedResourceCount) {
let option = {
url: video,
Expand Down Expand Up @@ -1304,36 +1313,30 @@
fetch(url)
.then((resp) => resp.text())
.then((magnetUrl) => {
// let video = document.createElement('div');
// previewHandler.createDplayer(url, suffix, video);
// content.innerHTML = '';
// content.append(video);
console.log(magnetUrl);
let torrentscr = document.createElement('script');
torrentscr.src =
'//cdn.jsdelivr.net/npm/@webtor/embed-sdk-js/dist/index.min.js';
torrentscr.charset = 'utf-8';
torrentscr.async = true;
document.head.appendChild(torrentscr);
let torrent = document.createElement('div');
torrent.id = 'player';
torrent.className = 'webtor';
torrent.style.textAlign = 'center';
torrent.style.aspectRatio = '16 / 9';
torrent.style.backgroundColor = '#101417';
content.innerHTML = '';
content.appendChild(torrent);
window.webtor = window.webtor || [];
window.webtor.push({
id: 'player',
width: '100%',
magnet: magnetUrl.trim(),
});
previewHandler.loadResource(
'//cdn.jsdelivr.net/npm/@webtor/embed-sdk-js/dist/index.min.js',
() => {
const torrent = document.createElement('div');
torrent.id = 'player';
torrent.className = 'webtor';
torrent.style.textAlign = 'center';
torrent.style.aspectRatio = '16 / 9';
torrent.style.backgroundColor = '#101417';
content.innerHTML = '';
content.appendChild(torrent);
window.webtor = window.webtor || [];
window.webtor.push({
id: 'player',
width: '100%',
magnet: magnetUrl.trim(),
});
}
);
})
.catch((e) => {
let textWrapper = document.createElement('div');
textWrapper.style.textAlign = 'center';
textWrapper.innerHTML = '该文件不支持预览';
textWrapper.innerHTML = '预览失败';
content.innerHTML = '';
content.appendChild(textWrapper);
});
Expand Down

5 comments on commit 38b51d3

@alan16742
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input 多了个 type="file",选择多个文件上传显示 共 undefined 个文件

@vcheckzen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修复了。还有个问题,那个大文件上传api不支持上传空文件,目前大小为0的文件会跳过上传,你看需不需要支持这种情况

@alan16742
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Onedrive 的官方网站也是不允许上传,有跳过提示就行
另外后端里的 abnormalWay 条件看了下没什么用可以删了;前端里挺多没用的注释比如下面也可以删了,是我这边改还是你改

      // if (window.GLOBAL_CONFIG.SCF_GATEWAY.indexOf("workers") === -1) {
      //   window.GLOBAL_CONFIG.SCF_GATEWAY += "/fodi/";
      //   window.GLOBAL_CONFIG.IS_CF = false;
      // }
      // if (location.protocol === 'http:') {
      //     location.href = location.href.replace(/http/, 'https');
      // }

@vcheckzen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

小文件api是支持空文件的
https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content?view=odsp-graph-online#example-upload-a-new-file

我把后端获取上传会话的函数改成批处理了,剩下的你改吧

@vcheckzen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

torrent 文件预览我测试加载不成功删掉了,磁力链接测试可以加载,现在是如果想预览必须把磁力链接放到后缀是 .videomagnet 的文件里。这里有预览效果 https://logi.im/fodi.html?path=/Media

Please sign in to comment.