Skip to content

Commit 14dab89

Browse files
sioaekoclaude
andcommitted
Fix EroScripts attachment filenames showing as hashes
Parse original filenames from Discourse cooked HTML link text instead of using hashed upload URLs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5668cc7 commit 14dab89

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/components/EroScriptsPanel.tsx

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,44 @@ export default function EroScriptsPanel({ currentVideoName }: EroScriptsPanelPro
122122
const links: Array<{ filename: string; url: string }> = []
123123

124124
for (const post of posts) {
125-
if (post.link_counts) {
126-
for (const link of post.link_counts) {
127-
if (link.url && isFunscriptUrl(link.url)) {
128-
const rawName = link.title || link.url.split('/').pop() || 'script.funscript'
129-
const filename = safeDecodeURI(rawName)
130-
const fullUrl = link.url.startsWith('http') ? link.url : `${BASE_URL}${link.url}`
131-
links.push({ filename, url: fullUrl })
132-
}
125+
const cooked = post.cooked || ''
126+
127+
// Parse cooked HTML: <a href="...">Original Filename.funscript</a>
128+
const linkRegex = /<a[^>]+href="([^"]*)"[^>]*>([^<]*\.(?:funscript|zip|7z|rar))<\/a>/gi
129+
let match
130+
while ((match = linkRegex.exec(cooked)) !== null) {
131+
const url = match[1]
132+
const linkText = match[2].trim()
133+
const fullUrl = url.startsWith('http') ? url : `${BASE_URL}${url}`
134+
const filename = safeDecodeURI(linkText)
135+
if (!links.some(l => l.url === fullUrl)) {
136+
links.push({ filename, url: fullUrl })
133137
}
134138
}
135-
const cooked = post.cooked || ''
139+
140+
// Fallback: href-only regex for links without visible text matching
136141
const hrefRegex = /href="([^"]*\.(?:funscript|zip|7z|rar)[^"]*)"/gi
137-
let match
138142
while ((match = hrefRegex.exec(cooked)) !== null) {
139143
const url = match[1]
140144
const fullUrl = url.startsWith('http') ? url : `${BASE_URL}${url}`
141-
const filename = safeDecodeURI(fullUrl.split('/').pop() || 'script')
142145
if (!links.some(l => l.url === fullUrl)) {
146+
const filename = safeDecodeURI(fullUrl.split('/').pop() || 'script')
143147
links.push({ filename, url: fullUrl })
144148
}
145149
}
150+
151+
// Fallback: link_counts (only if not already found via HTML)
152+
if (post.link_counts) {
153+
for (const link of post.link_counts) {
154+
if (link.url && isFunscriptUrl(link.url)) {
155+
const fullUrl = link.url.startsWith('http') ? link.url : `${BASE_URL}${link.url}`
156+
if (!links.some(l => l.url === fullUrl)) {
157+
const rawName = link.title || link.url.split('/').pop() || 'script.funscript'
158+
links.push({ filename: safeDecodeURI(rawName), url: fullUrl })
159+
}
160+
}
161+
}
162+
}
146163
}
147164
setDownloadLinks(prev => ({ ...prev, [topicId]: links }))
148165
}

0 commit comments

Comments
 (0)