feat: 新增多项功能并添加新工具
- 私人剪贴板新增限时直通URL生成功能 - doc_cloud_keeper新增标题复制按钮 - 新增贪蛇出动游戏工具 - 新增OSS中转直链工具 - 添加批量抽帧测试脚本
This commit is contained in:
@@ -171,6 +171,37 @@ const copyImageToClipboard = async (url) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 限时直通URL:生成 3 天有效的无鉴权直链并复制(按钮带 loading 防重复点击)
|
||||
const copyShareLink = async (itemId, btn) => {
|
||||
if (!itemId) return
|
||||
const originText = btn ? btn.textContent : ''
|
||||
try {
|
||||
if (btn) {
|
||||
btn.disabled = true
|
||||
btn.textContent = '生成中…'
|
||||
}
|
||||
const data = await apiJson(`${apiBase}/share/create`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ id: itemId })
|
||||
})
|
||||
if (!data || !data.url) throw new Error('empty_share_url')
|
||||
try {
|
||||
await navigator.clipboard.writeText(data.url)
|
||||
} catch (e) {
|
||||
window.prompt('自动复制失败,请手动复制以下直链:', data.url)
|
||||
}
|
||||
setStatus(`已复制限时直通URL(有效期至 ${data.expires_at_text || '3天后'},过期后重新点击按钮生成)`, 'ok')
|
||||
} catch (e) {
|
||||
setStatus(`生成限时直通URL失败: ${String(e.message || e)}`, 'error')
|
||||
} finally {
|
||||
if (btn) {
|
||||
btn.disabled = false
|
||||
btn.textContent = originText
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const detectMobile = () => {
|
||||
if (window.matchMedia) {
|
||||
return window.matchMedia('(max-width: 900px), (pointer: coarse)').matches
|
||||
@@ -580,7 +611,7 @@ const buildItemCard = (item) => {
|
||||
if (images.length) {
|
||||
const grid = document.createElement('div')
|
||||
grid.className = 'pc-image-grid'
|
||||
const viewImages = images.map(i => ({ url: i.file_url, name: i.file_name || '图片' }))
|
||||
const viewImages = images.map(i => ({ url: i.file_url, name: i.file_name || '图片', id: i.id }))
|
||||
images.forEach((imgItem, idx) => {
|
||||
const wrap = document.createElement('div')
|
||||
wrap.className = 'pc-image-thumb'
|
||||
@@ -588,6 +619,19 @@ const buildItemCard = (item) => {
|
||||
img.src = imgItem.file_url
|
||||
img.alt = imgItem.file_name || 'image'
|
||||
wrap.appendChild(img)
|
||||
const thumbActions = document.createElement('div')
|
||||
thumbActions.className = 'pc-image-thumb-actions'
|
||||
const shareBtn = document.createElement('button')
|
||||
shareBtn.className = 'btn'
|
||||
shareBtn.type = 'button'
|
||||
shareBtn.textContent = '限时直通URL'
|
||||
shareBtn.title = '生成3天有效的无鉴权直链,可在第三方浏览器/程序直接打开'
|
||||
shareBtn.addEventListener('click', (e) => {
|
||||
e.stopPropagation()
|
||||
copyShareLink(imgItem.id, shareBtn)
|
||||
})
|
||||
thumbActions.appendChild(shareBtn)
|
||||
wrap.appendChild(thumbActions)
|
||||
wrap.addEventListener('click', () => openViewerAt(viewImages, idx))
|
||||
grid.appendChild(wrap)
|
||||
})
|
||||
@@ -630,10 +674,16 @@ const buildItemCard = (item) => {
|
||||
setStatus(`下载失败: ${String(e.message || e)}`, 'error')
|
||||
}
|
||||
})
|
||||
const shareFileBtn = document.createElement('button')
|
||||
shareFileBtn.className = 'btn'
|
||||
shareFileBtn.textContent = '限时直通URL'
|
||||
shareFileBtn.title = '生成3天有效的无鉴权直链,可在第三方浏览器/程序直接打开'
|
||||
shareFileBtn.addEventListener('click', () => copyShareLink(fileItem.id, shareFileBtn))
|
||||
row.appendChild(name)
|
||||
row.appendChild(metaText)
|
||||
row.appendChild(copyUrlBtn)
|
||||
row.appendChild(downloadBtn)
|
||||
row.appendChild(shareFileBtn)
|
||||
card.appendChild(row)
|
||||
})
|
||||
}
|
||||
@@ -1366,6 +1416,14 @@ const initApp = async () => {
|
||||
})
|
||||
}
|
||||
|
||||
const viewerShareUrl = $('pc-viewer-share-url')
|
||||
if (viewerShareUrl) {
|
||||
viewerShareUrl.addEventListener('click', () => {
|
||||
const current = state.viewer.images[state.viewer.index]
|
||||
if (current && current.id) copyShareLink(current.id, viewerShareUrl)
|
||||
})
|
||||
}
|
||||
|
||||
const viewerCopyImg = $('pc-viewer-copy-img')
|
||||
if (viewerCopyImg) {
|
||||
viewerCopyImg.addEventListener('click', () => {
|
||||
|
||||
Reference in New Issue
Block a user