Skip to content

Commit

Permalink
fix "share discogs track to r4"
Browse files Browse the repository at this point in the history
  • Loading branch information
ug.rp committed May 23, 2024
1 parent 42a7afb commit 768c3c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/r4-track-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ export default class R4TrackCreate extends R4Form {
if (!this.state.title) {
const {title} = await fetchOEmbed(value)
if (title) {
/* cannot this.setAttribute('title') from here */
this.state = {...this.state, title}
const $trackTitle = this.querySelector('[name="title"]')
$trackTitle.value = title
$trackTitle.dispatchEvent(new Event('input')) // trigger value change
}
}
}
if (name === 'title' && value) {
const search = buildSearchUrl(value)
console.log('search url', search)
}
if (name === 'discogs_url') {
const $discogs = this.querySelector('r4-discogs-resource')
Expand Down
15 changes: 11 additions & 4 deletions src/libs/discogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ const buildApiUrl = ({type, id}) => {
return new URL(`${type}s/${id}`, `https://${DISCOGS_API_URL}`).href
}

/* parses a discogs release URL */
/* parses a discogs release URL;
Ex:
- https://www.discogs.com/release/13304754-%EB%B0%95%ED%98%9C%EC%A7%84-Park-Hye-Jin-If-U-Want-It (new)
- https://www.discogs.com/Diego-The-Persuasion-Channel/release/17335 (legacy)
*/
export const parseUrl = (url) => {
const discogsUrl = new URL(url)
if (discogsUrl.hostname.endsWith(DISCOGS_URL)) {
const pathes = discogsUrl.pathname.slice(1).split('/')
const type = pathes[0]
const id = pathes[1].split('-')[0]
if (DiscogsResourceTypes.includes(type)) {
const type = [pathes[0], pathes[1]].find((typeInPath) => {
return DiscogsResourceTypes.includes(typeInPath)
})
if (type) {
const typeInPathIndex = pathes.indexOf(type)
const id = pathes.slice(typeInPathIndex + 1)[0].split('-')[0]
return {id, type}
}
}
Expand Down

0 comments on commit 768c3c5

Please sign in to comment.