Skip to content

Commit 7c4ab83

Browse files
authored
Merge pull request #387 from stevencrader/guid-search
During search, attempt to lookup query as guid
2 parents 96e33ca + 55ae48f commit 7c4ab83

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

Diff for: ui/src/pages/Search/index.tsx

+29-8
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,23 @@ export default class Results extends React.PureComponent<IProps> {
5858
searchType = "all"
5959
}
6060

61-
// check if id may have been entered
61+
// check if id or guid may have been entered
6262
const number = Number(query)
63-
let firstResult = null
64-
if (!isNaN(number) && searchType !== "person"){
65-
firstResult = await (await this.getFeedById(query))?.feed
63+
let feedIdResult = null
64+
let guidResult = null
65+
if (query && searchType !== "person"){
66+
if (!isNaN(number)) {
67+
feedIdResult = await (await this.getFeedById(query))?.feed
68+
// check if a feed object. When query isn't a valid ID, returns list instead of empty object
69+
if (feedIdResult.id === undefined) {
70+
feedIdResult = null
71+
}
72+
}
73+
// check if guid if no feed returned
74+
guidResult = await (await this.getPodcastInfoGuid(query))?.feed
6675
// check if a feed object. When query isn't a valid ID, returns list instead of empty object
67-
if (firstResult.id === undefined){
68-
firstResult = null
76+
if (guidResult.id === undefined){
77+
guidResult = null
6978
}
7079
}
7180

@@ -87,8 +96,11 @@ export default class Results extends React.PureComponent<IProps> {
8796
}
8897
}
8998

90-
if (firstResult) {
91-
results.unshift(firstResult)
99+
if (guidResult) {
100+
results.unshift(guidResult)
101+
}
102+
if (feedIdResult) {
103+
results.unshift(feedIdResult)
92104
}
93105

94106
if (this._isMounted) {
@@ -111,6 +123,15 @@ export default class Results extends React.PureComponent<IProps> {
111123
return await response.json()
112124
}
113125

126+
async getPodcastInfoGuid(guid: string) {
127+
// noinspection SpellCheckingInspection
128+
let response = await fetch(`/api/podcasts/byguid?guid=${guid}`, {
129+
// credentials: 'same-origin',
130+
method: 'GET',
131+
})
132+
return await response.json()
133+
}
134+
114135
async getTermSearchResults(query: string, similar: boolean = false) {
115136
query = encodeSearch(query)
116137
const similarParam = similar ? "&similar" : ""

0 commit comments

Comments
 (0)