Skip to content

Commit e3a7f5c

Browse files
authored
Update for Thumbnails (#38)
* Update for Thumbnails * Add Copy Raw URL for Backwards Compatibility * Fix Token and Password for Copy Buttons * Add Raw URL back to fileName * Fix Password for All URLs
1 parent d7a4f71 commit e3a7f5c

File tree

2 files changed

+35
-32
lines changed

2 files changed

+35
-32
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"manifest_version": 3,
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"name": "Django Files",
55
"description": "Django Files Web Extension designed to work with github.com/django-files/django-files.",
66
"homepage_url": "https://github.com/django-files/web-extension",

src/js/popup.js

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ function updateTable(data, options) {
326326
// console.debug(`data.length: ${data.length}`)
327327
// console.debug(`tbody.rows.length: ${tbody.rows.length}`)
328328
for (let i = 0; i < length; i++) {
329-
// console.debug(`i: ${i}`)
329+
// console.debug(`i: ${i}`, data[i])
330330
let row = tbody.rows[i]
331331
if (!row) {
332332
row = tbody.insertRow()
@@ -342,31 +342,31 @@ function updateTable(data, options) {
342342
row.addEventListener('mouseover', hoverLinks)
343343
row.id = `row-${i}`
344344
row.dataset.idx = i.toString()
345-
// TODO: Backwards Compatible with Older DJ Versions
346-
let url
347-
let name
348-
let href
349-
if (typeof data[i] === 'object') {
350-
url = new URL(data[i].url)
351-
name = data[i].name
352-
href = data[i].url
345+
346+
const url = new URL(data[i].url)
347+
let rawURLCopy
348+
let rawURL
349+
if (data[i].raw) {
350+
rawURLCopy = new URL(data[i].raw)
351+
rawURL = new URL(data[i].raw)
353352
} else {
354-
url = new URL(data[i])
355-
name = url.pathname.replace(/^\/u\//, '')
356-
href = data[i]
353+
const raw = url.origin + url.pathname.replace(/^\/u\//, '/raw/')
354+
rawURLCopy = new URL(raw)
355+
rawURL = new URL(raw)
356+
rawURL.searchParams.append('token', options.authToken)
357357
}
358-
const raw = url.origin + url.pathname.replace(/^\/u\//, '/raw/')
359-
let rawURL = new URL(raw)
360-
const password = url.searchParams.get('password')
361-
if (password) {
362-
rawURL.searchParams.append('password', password)
358+
if (url.searchParams.has('password')) {
359+
const password = url.searchParams.get('password')
360+
// console.debug('adding password to rawURLCopy:', password)
361+
rawURLCopy.searchParams.append('password', password)
363362
}
363+
rawURL.searchParams.append('view', 'gallery')
364364

365365
// File Link -> 1
366366
const link = document.createElement('a')
367-
link.text = name
368-
link.title = name
369-
link.href = href
367+
link.text = data[i].name
368+
link.title = data[i].name
369+
link.href = data[i].url
370370
link.setAttribute('role', 'button')
371371
link.classList.add(
372372
'link-underline',
@@ -376,9 +376,9 @@ function updateTable(data, options) {
376376
'mouse-link'
377377
)
378378
link.target = '_blank'
379-
link.dataset.name = name
379+
link.dataset.name = data[i].name
380380
link.dataset.row = i.toString()
381-
link.dataset.raw = `${raw}?token=${options.authToken}&view=gallery`
381+
link.dataset.thumb = data[i].thumb || rawURL.href
382382

383383
// Cell: 1
384384
const cell1 = row.cells[0]
@@ -391,8 +391,8 @@ function updateTable(data, options) {
391391
const board = hoverboard.cloneNode(true)
392392
board.id = `menu-${i}`
393393

394-
board.querySelector('.copy-link').dataset.clipboardText = href
395-
board.querySelector('.copy-raw').dataset.clipboardText = rawURL.href
394+
board.querySelector('.copy-link').dataset.clipboardText = data[i].url
395+
board.querySelector('.copy-raw').dataset.clipboardText = rawURLCopy.href
396396

397397
div.appendChild(board)
398398
cell1.appendChild(div)
@@ -420,12 +420,14 @@ function updateTable(data, options) {
420420
updateContextMenu(drop, data[i]).then()
421421
}
422422
const fileName = drop.querySelector('li.mouse-link')
423-
fileName.innerText = name
424-
fileName.dataset.clipboardText = name
425-
fileName.dataset.raw = `${raw}?token=${options.authToken}&view=gallery`
426-
drop.querySelector('.copy-link').dataset.clipboardText = href
427-
drop.querySelector('.copy-raw').dataset.clipboardText = rawURL.href
428-
drop.querySelectorAll('.raw').forEach((el) => (el.href = rawURL.href))
423+
fileName.innerText = data[i].name
424+
fileName.dataset.clipboardText = data[i].name
425+
fileName.dataset.thumb = data[i].thumb || rawURL.href
426+
drop.querySelector('.copy-link').dataset.clipboardText = data[i].url
427+
drop.querySelector('.copy-raw').dataset.clipboardText = rawURLCopy.href
428+
drop.querySelectorAll('.raw').forEach(
429+
(el) => (el.href = rawURLCopy.href)
430+
)
429431
button.appendChild(drop)
430432

431433
// Cell: 0
@@ -810,7 +812,8 @@ function onMouseOver(event) {
810812
const imageExtensions = /\.(gif|ico|jpeg|jpg|png|svg|webp)$/i
811813
if (str.match(imageExtensions)) {
812814
mediaImage.src = loadingImage
813-
mediaImage.src = event.target.dataset.raw
815+
mediaImage.src = event.target.dataset.thumb
816+
// console.debug('dataset.thumb', event.target.dataset.thumb)
814817
mediaOuter.classList.remove('d-none')
815818
} else {
816819
mediaOuter.classList.add('d-none')

0 commit comments

Comments
 (0)