fix: some times adding a link fails with UnboundLocalError

This commit is contained in:
arabcoders 2026-02-14 18:49:52 +03:00
parent 90e07ce71b
commit a0fef50248
3 changed files with 21 additions and 15 deletions

View file

@ -85,6 +85,7 @@ async def add(
"""
_preset: Preset | None = Presets.get_instance().get(item.preset)
logs = []
if item.has_cli():
try:

View file

@ -75,22 +75,31 @@ const sources: EmbedSource[] = [
url: "https://drive.google.com/file/d/{id}/preview",
regex: /https?:\/\/(?:www\.)?drive\.google\.com\/file\/d\/(?<id>[^/?#&]+)/,
},
{
name: "fbc_sites",
url: "{domain}/e/{id}",
regex: /(?<domain>(.+?))\/(?:api\/tokens|f)\/(?<id>fbc_[A-Za-z0-9_-]{22})\/?/,
},
]
const isEmbedable = (url: string): boolean => sources.some(source => source.regex.test(url))
const getEmbedable = (url: string): string | null => {
const source = sources.find(source => source.regex.test(url))
if (!source) {
return null
for (const source of sources) {
const match = source.regex.exec(url)
if (!match?.groups) {
continue
}
const replacements: Record<string, string> = {
...match.groups,
origin: window.location.origin,
}
return source.url.replace(/\{(\w+)\}/g, (_, key) => replacements[key] ?? `{${key}}`)
}
const match = source.regex.exec(url)
if (!match || !match.groups?.id) {
return null
}
return source.url.replace(/\{origin\}/g, window.location.origin).replace(/\{id\}/g, match.groups.id)
return null
}
export { isEmbedable, getEmbedable }

View file

@ -213,11 +213,7 @@ const encodePath = (item: string): string => {
processed = encodeURIComponent(processed)
const placeholderRegex = new RegExp(`${_PREFIX.replace(/_/g, '_')}(\\d+)${_SUFFIX.replace(/_/g, '_')}`, 'g')
processed = processed.replace(placeholderRegex, (_match, index: string) => {
return placeholders[parseInt(index)] || ''
})
return processed
return processed.replace(placeholderRegex, (_match, index: string) => placeholders[parseInt(index)] || '')
}).join('/')
}
@ -255,7 +251,7 @@ const request = (url: string, options: RequestInit & { timeout?: number } = {}):
if (typeof timeout === 'number' && timeout > 0) {
controller = new AbortController()
fetchOptions.signal = controller.signal
timer = setTimeout(() => controller!.abort(`Request timed out.`), timeout*1000)
timer = setTimeout(() => controller!.abort(`Request timed out.`), timeout * 1000)
}
return fetch(url.startsWith('/') ? uri(url) : url, fetchOptions).finally(() => {