|
|
function openFolder() { |
|
|
let path = (getCurrentPath() + '/' + this.getAttribute('data-id') + '/').replaceAll('//', '/') |
|
|
|
|
|
const auth = getFolderAuthFromPath() |
|
|
if (auth) { |
|
|
path = path + '&auth=' + auth |
|
|
} |
|
|
window.location.href = `/?path=${path}` |
|
|
} |
|
|
|
|
|
function openFile() { |
|
|
const fileName = this.getAttribute('data-name').toLowerCase() |
|
|
let path = '/file?path=' + this.getAttribute('data-path') + '/' + this.getAttribute('data-id') |
|
|
|
|
|
if (fileName.endsWith('.mp4') || fileName.endsWith('.mkv') || fileName.endsWith('.webm') || fileName.endsWith('.mov') || fileName.endsWith('.avi') || fileName.endsWith('.ts') || fileName.endsWith('.ogv')) { |
|
|
path = '/stream?url=' + getRootUrl() + path |
|
|
} |
|
|
|
|
|
window.open(path, '_blank') |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function openMoreButton(div) { |
|
|
const id = div.getAttribute('data-id') |
|
|
const moreDiv = document.getElementById(`more-option-${id}`) |
|
|
|
|
|
const rect = div.getBoundingClientRect(); |
|
|
const x = rect.left + window.scrollX - 40; |
|
|
const y = rect.top + window.scrollY; |
|
|
|
|
|
moreDiv.style.zIndex = 2 |
|
|
moreDiv.style.opacity = 1 |
|
|
moreDiv.style.left = `${x}px` |
|
|
moreDiv.style.top = `${y}px` |
|
|
|
|
|
const isTrash = getCurrentPath().includes('/trash') |
|
|
|
|
|
moreDiv.querySelector('.more-options-focus').focus() |
|
|
moreDiv.querySelector('.more-options-focus').addEventListener('blur', closeMoreBtnFocus); |
|
|
moreDiv.querySelector('.more-options-focus').addEventListener('focusout', closeMoreBtnFocus); |
|
|
if (!isTrash) { |
|
|
moreDiv.querySelector(`#rename-${id}`).addEventListener('click', renameFileFolder) |
|
|
moreDiv.querySelector(`#trash-${id}`).addEventListener('click', trashFileFolder) |
|
|
try { |
|
|
moreDiv.querySelector(`#share-${id}`).addEventListener('click', shareFile) |
|
|
} |
|
|
catch { } |
|
|
try { |
|
|
moreDiv.querySelector(`#folder-share-${id}`).addEventListener('click', shareFolder) |
|
|
} |
|
|
catch { } |
|
|
} |
|
|
else { |
|
|
moreDiv.querySelector(`#restore-${id}`).addEventListener('click', restoreFileFolder) |
|
|
moreDiv.querySelector(`#delete-${id}`).addEventListener('click', deleteFileFolder) |
|
|
} |
|
|
} |
|
|
|
|
|
function closeMoreBtnFocus() { |
|
|
const moreDiv = this.parentElement |
|
|
moreDiv.style.opacity = '0' |
|
|
setTimeout(() => { |
|
|
moreDiv.style.zIndex = '-1' |
|
|
}, 300) |
|
|
} |
|
|
|
|
|
|
|
|
function renameFileFolder() { |
|
|
const id = this.getAttribute('id').split('-')[1] |
|
|
console.log(id) |
|
|
|
|
|
document.getElementById('rename-name').value = this.parentElement.getAttribute('data-name'); |
|
|
document.getElementById('bg-blur').style.zIndex = '2'; |
|
|
document.getElementById('bg-blur').style.opacity = '0.1'; |
|
|
|
|
|
document.getElementById('rename-file-folder').style.zIndex = '3'; |
|
|
document.getElementById('rename-file-folder').style.opacity = '1'; |
|
|
document.getElementById('rename-file-folder').setAttribute('data-id', id); |
|
|
setTimeout(() => { |
|
|
document.getElementById('rename-name').focus(); |
|
|
}, 300) |
|
|
} |
|
|
|
|
|
document.getElementById('rename-cancel').addEventListener('click', () => { |
|
|
document.getElementById('rename-name').value = ''; |
|
|
document.getElementById('bg-blur').style.opacity = '0'; |
|
|
setTimeout(() => { |
|
|
document.getElementById('bg-blur').style.zIndex = '-1'; |
|
|
}, 300) |
|
|
document.getElementById('rename-file-folder').style.opacity = '0'; |
|
|
setTimeout(() => { |
|
|
document.getElementById('rename-file-folder').style.zIndex = '-1'; |
|
|
}, 300) |
|
|
}); |
|
|
|
|
|
document.getElementById('rename-create').addEventListener('click', async () => { |
|
|
const name = document.getElementById('rename-name').value; |
|
|
if (name === '') { |
|
|
alert('Name cannot be empty') |
|
|
return |
|
|
} |
|
|
|
|
|
const id = document.getElementById('rename-file-folder').getAttribute('data-id') |
|
|
|
|
|
const path = document.getElementById(`more-option-${id}`).getAttribute('data-path') + '/' + id |
|
|
|
|
|
const data = { |
|
|
'name': name, |
|
|
'path': path |
|
|
} |
|
|
|
|
|
const response = await postJson('/api/renameFileFolder', data) |
|
|
if (response.status === 'ok') { |
|
|
alert('File/Folder Renamed Successfully') |
|
|
window.location.reload(); |
|
|
} else { |
|
|
alert('Failed to rename file/folder') |
|
|
window.location.reload(); |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function trashFileFolder() { |
|
|
const id = this.getAttribute('id').split('-')[1] |
|
|
console.log(id) |
|
|
const path = document.getElementById(`more-option-${id}`).getAttribute('data-path') + '/' + id |
|
|
const data = { |
|
|
'path': path, |
|
|
'trash': true |
|
|
} |
|
|
const response = await postJson('/api/trashFileFolder', data) |
|
|
|
|
|
if (response.status === 'ok') { |
|
|
alert('File/Folder Sent to Trash Successfully') |
|
|
window.location.reload(); |
|
|
} else { |
|
|
alert('Failed to Send File/Folder to Trash') |
|
|
window.location.reload(); |
|
|
} |
|
|
} |
|
|
|
|
|
async function restoreFileFolder() { |
|
|
const id = this.getAttribute('id').split('-')[1] |
|
|
const path = this.getAttribute('data-path') + '/' + id |
|
|
const data = { |
|
|
'path': path, |
|
|
'trash': false |
|
|
} |
|
|
const response = await postJson('/api/trashFileFolder', data) |
|
|
|
|
|
if (response.status === 'ok') { |
|
|
alert('File/Folder Restored Successfully') |
|
|
window.location.reload(); |
|
|
} else { |
|
|
alert('Failed to Restored File/Folder') |
|
|
window.location.reload(); |
|
|
} |
|
|
} |
|
|
|
|
|
async function deleteFileFolder() { |
|
|
const id = this.getAttribute('id').split('-')[1] |
|
|
const path = this.getAttribute('data-path') + '/' + id |
|
|
const data = { |
|
|
'path': path |
|
|
} |
|
|
const response = await postJson('/api/deleteFileFolder', data) |
|
|
|
|
|
if (response.status === 'ok') { |
|
|
alert('File/Folder Deleted Successfully') |
|
|
window.location.reload(); |
|
|
} else { |
|
|
alert('Failed to Delete File/Folder') |
|
|
window.location.reload(); |
|
|
} |
|
|
} |
|
|
|
|
|
async function shareFile() { |
|
|
const fileName = this.parentElement.getAttribute('data-name').toLowerCase() |
|
|
const id = this.getAttribute('id').split('-')[1] |
|
|
const path = document.getElementById(`more-option-${id}`).getAttribute('data-path') + '/' + id |
|
|
const root_url = getRootUrl() |
|
|
|
|
|
let link |
|
|
if (fileName.endsWith('.mp4') || fileName.endsWith('.mkv') || fileName.endsWith('.webm') || fileName.endsWith('.mov') || fileName.endsWith('.avi') || fileName.endsWith('.ts') || fileName.endsWith('.ogv')) { |
|
|
link = `${root_url}/stream?url=${root_url}/file?path=${path}` |
|
|
} else { |
|
|
link = `${root_url}/file?path=${path}` |
|
|
|
|
|
} |
|
|
|
|
|
copyTextToClipboard(link) |
|
|
} |
|
|
|
|
|
|
|
|
async function shareFolder() { |
|
|
const id = this.getAttribute('id').split('-')[2] |
|
|
console.log(id) |
|
|
let path = document.getElementById(`more-option-${id}`).getAttribute('data-path') + '/' + id |
|
|
const root_url = getRootUrl() |
|
|
|
|
|
const auth = await getFolderShareAuth(path) |
|
|
path = path.slice(1) |
|
|
|
|
|
let link = `${root_url}/?path=/share_${path}&auth=${auth}` |
|
|
console.log(link) |
|
|
|
|
|
copyTextToClipboard(link) |
|
|
} |
|
|
|
|
|
|