@behindthemusictree/app-kit 0.0.0-stage → 26.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/dist/app-error-B8IoFBhD.d.ts +45 -0
- package/dist/app-error-codes-D5eYg7xR.d.ts +49 -0
- package/dist/auth/index.cjs +479 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.ts +83 -0
- package/dist/auth/index.js +36 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/chunk-4MEK3CNF.js +246 -0
- package/dist/chunk-4MEK3CNF.js.map +1 -0
- package/dist/chunk-5NTNMBJP.js +25 -0
- package/dist/chunk-5NTNMBJP.js.map +1 -0
- package/dist/chunk-5YLNSX34.js +211 -0
- package/dist/chunk-5YLNSX34.js.map +1 -0
- package/dist/chunk-7EOS2K24.js +267 -0
- package/dist/chunk-7EOS2K24.js.map +1 -0
- package/dist/chunk-FYOLIMWU.js +25 -0
- package/dist/chunk-FYOLIMWU.js.map +1 -0
- package/dist/chunk-JMFEWI53.js +10 -0
- package/dist/chunk-JMFEWI53.js.map +1 -0
- package/dist/chunk-OGTDTTHJ.js +244 -0
- package/dist/chunk-OGTDTTHJ.js.map +1 -0
- package/dist/chunk-OIZPAN6I.js +356 -0
- package/dist/chunk-OIZPAN6I.js.map +1 -0
- package/dist/chunk-T4IDICOJ.js +1480 -0
- package/dist/chunk-T4IDICOJ.js.map +1 -0
- package/dist/chunk-T5D5T52J.js +271 -0
- package/dist/chunk-T5D5T52J.js.map +1 -0
- package/dist/chunk-TCXWV62L.js +1 -0
- package/dist/chunk-TCXWV62L.js.map +1 -0
- package/dist/genre-tree/index.cjs +2153 -0
- package/dist/genre-tree/index.cjs.map +1 -0
- package/dist/genre-tree/index.d.ts +3109 -0
- package/dist/genre-tree/index.js +181 -0
- package/dist/genre-tree/index.js.map +1 -0
- package/dist/genre-tree/testing.cjs +55 -0
- package/dist/genre-tree/testing.cjs.map +1 -0
- package/dist/genre-tree/testing.d.ts +7 -0
- package/dist/genre-tree/testing.js +27 -0
- package/dist/genre-tree/testing.js.map +1 -0
- package/dist/ids-D8XCErUS.d.ts +8 -0
- package/dist/index.cjs +3214 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +310 -0
- package/dist/index.js.map +1 -0
- package/dist/player/index.cjs +388 -0
- package/dist/player/index.cjs.map +1 -0
- package/dist/player/index.d.ts +108 -0
- package/dist/player/index.js +20 -0
- package/dist/player/index.js.map +1 -0
- package/dist/popup/index.cjs +403 -0
- package/dist/popup/index.cjs.map +1 -0
- package/dist/popup/index.d.ts +80 -0
- package/dist/popup/index.js +16 -0
- package/dist/popup/index.js.map +1 -0
- package/dist/scope-BoMVOHmz.d.ts +4 -0
- package/dist/track-noun/index.cjs +53 -0
- package/dist/track-noun/index.cjs.map +1 -0
- package/dist/track-noun/index.d.ts +15 -0
- package/dist/track-noun/index.js +11 -0
- package/dist/track-noun/index.js.map +1 -0
- package/dist/transport/index.cjs +773 -0
- package/dist/transport/index.cjs.map +1 -0
- package/dist/transport/index.d.ts +203 -0
- package/dist/transport/index.js +69 -0
- package/dist/transport/index.js.map +1 -0
- package/package.json +97 -4
- package/README.md +0 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,3214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
ARTIST_LINK_KINDS: () => ARTIST_LINK_KINDS,
|
|
24
|
+
AUTH_POPUP_TYPE: () => AUTH_POPUP_TYPE,
|
|
25
|
+
AlbumMinimumSchema: () => AlbumMinimumSchema,
|
|
26
|
+
AppError: () => AppError,
|
|
27
|
+
ArtistDetailedSchema: () => ArtistDetailedSchema,
|
|
28
|
+
ArtistGenreCountSchema: () => ArtistGenreCountSchema,
|
|
29
|
+
ArtistImageSchema: () => ArtistImageSchema,
|
|
30
|
+
ArtistMinimumSchema: () => ArtistMinimumSchema,
|
|
31
|
+
ArtistNames: () => ArtistNames,
|
|
32
|
+
ArtistSearchResultSchema: () => ArtistSearchResultSchema,
|
|
33
|
+
ArtistSearchResultsSchema: () => ArtistSearchResultsSchema,
|
|
34
|
+
AudioMediaController: () => AudioMediaController,
|
|
35
|
+
AuthRequired: () => AuthRequired,
|
|
36
|
+
BackendError: () => BackendError,
|
|
37
|
+
BackendSpotifyUserNotAllowlistedError: () => BackendSpotifyUserNotAllowlistedError,
|
|
38
|
+
BadRequestError: () => BadRequestError,
|
|
39
|
+
ClientError: () => ClientError,
|
|
40
|
+
ConnectivityError: () => ConnectivityError,
|
|
41
|
+
ConnectivityErrorProvider: () => ConnectivityErrorProvider,
|
|
42
|
+
ConnectivityErrorType: () => ConnectivityErrorType,
|
|
43
|
+
CriteriaCreationSchema: () => CriteriaCreationSchema,
|
|
44
|
+
CriteriaDetailedSchema: () => CriteriaDetailedSchema,
|
|
45
|
+
CriteriaLineageRelWithoutAscendantSchema: () => CriteriaLineageRelWithoutAscendantSchema,
|
|
46
|
+
CriteriaLineageRelWithoutDescendantSchema: () => CriteriaLineageRelWithoutDescendantSchema,
|
|
47
|
+
CriteriaMinimumSchema: () => CriteriaMinimumSchema,
|
|
48
|
+
CriteriaOverviewSchema: () => CriteriaOverviewSchema,
|
|
49
|
+
CriteriaPlaylistDetailedSchema: () => CriteriaPlaylistDetailedSchema,
|
|
50
|
+
CriteriaPlaylistMinimumSchema: () => CriteriaPlaylistMinimumSchema,
|
|
51
|
+
CriteriaPlaylistSimpleSchema: () => CriteriaPlaylistSimpleSchema,
|
|
52
|
+
CriteriaSimpleSchema: () => CriteriaSimpleSchema,
|
|
53
|
+
CriteriaUpdateSchema: () => CriteriaUpdateSchema,
|
|
54
|
+
ErrorCode: () => ErrorCode,
|
|
55
|
+
ErrorMessages: () => ErrorMessages,
|
|
56
|
+
FORM_RATING_NULL_VALUE: () => FORM_RATING_NULL_VALUE,
|
|
57
|
+
GOOGLE_EXCHANGE_CONFIG: () => GOOGLE_EXCHANGE_CONFIG,
|
|
58
|
+
GenrePlaylistUuidSchema: () => GenrePlaylistUuidSchema,
|
|
59
|
+
GenreUuidSchema: () => GenreUuidSchema,
|
|
60
|
+
InvalidInputError: () => InvalidInputError,
|
|
61
|
+
MbArtistDetailedSchema: () => MbArtistDetailedSchema,
|
|
62
|
+
MbRecordingDetailedSchema: () => MbRecordingDetailedSchema,
|
|
63
|
+
NO_VIDEO_LABEL: () => NO_VIDEO_LABEL,
|
|
64
|
+
NetworkError: () => NetworkError,
|
|
65
|
+
PaginatedResponseSchema: () => PaginatedResponseSchema,
|
|
66
|
+
PlayStates: () => PlayStates,
|
|
67
|
+
PlayerProvider: () => PlayerProvider,
|
|
68
|
+
PlayerVideoSurface: () => PlayerVideoSurface,
|
|
69
|
+
PopupProvider: () => PopupProvider,
|
|
70
|
+
SPOTIFY_EXCHANGE_CONFIG: () => SPOTIFY_EXCHANGE_CONFIG,
|
|
71
|
+
ServiceError: () => ServiceError,
|
|
72
|
+
SessionProvider: () => SessionProvider,
|
|
73
|
+
SongDetailedSchema: () => SongDetailedSchema,
|
|
74
|
+
TrackBaseSchema: () => TrackBaseSchema,
|
|
75
|
+
TrackList: () => TrackList,
|
|
76
|
+
TrackListFromArtist: () => TrackListFromArtist,
|
|
77
|
+
TrackListFromCriteriaPlaylist: () => TrackListFromCriteriaPlaylist,
|
|
78
|
+
TrackListFromTrack: () => TrackListFromTrack,
|
|
79
|
+
TrackListOrigin: () => TrackListOrigin,
|
|
80
|
+
TrackListOriginFromArtist: () => TrackListOriginFromArtist,
|
|
81
|
+
TrackListOriginFromCriteriaPlaylist: () => TrackListOriginFromCriteriaPlaylist,
|
|
82
|
+
TrackListOriginFromTrack: () => TrackListOriginFromTrack,
|
|
83
|
+
TrackListOriginType: () => TrackListOriginType,
|
|
84
|
+
TrackListProvider: () => TrackListProvider,
|
|
85
|
+
TrackListSidebarVisibilityProvider: () => TrackListSidebarVisibilityProvider,
|
|
86
|
+
TrackMinimumSchema: () => TrackMinimumSchema,
|
|
87
|
+
TrackNounProvider: () => TrackNounProvider,
|
|
88
|
+
UuidResourceSchema: () => UuidResourceSchema,
|
|
89
|
+
YOUTUBE_UNPLAYABLE_REASON_LABELS: () => YOUTUBE_UNPLAYABLE_REASON_LABELS,
|
|
90
|
+
YoutubeMediaController: () => YoutubeMediaController,
|
|
91
|
+
artistEndpoints: () => artistEndpoints,
|
|
92
|
+
artistQueryKeys: () => artistQueryKeys,
|
|
93
|
+
buildBackendBaseUrl: () => buildBackendBaseUrl,
|
|
94
|
+
buildSubdomainBaseUrl: () => buildSubdomainBaseUrl,
|
|
95
|
+
capitalize: () => capitalize,
|
|
96
|
+
capitalizeFirstLetter: () => capitalizeFirstLetter,
|
|
97
|
+
clearSpotifyRequiredCached: () => clearSpotifyRequiredCached,
|
|
98
|
+
clearStoredRedirectUrl: () => clearStoredRedirectUrl,
|
|
99
|
+
createAppErrorFromErrorCode: () => createAppErrorFromErrorCode,
|
|
100
|
+
createAppErrorFromResult: () => createAppErrorFromResult,
|
|
101
|
+
createLogout: () => createLogout,
|
|
102
|
+
createNetworkOrBackendError: () => createNetworkOrBackendError,
|
|
103
|
+
editGenreSongPages: () => editGenreSongPages,
|
|
104
|
+
exchangeCodeWithBackend: () => exchangeCodeWithBackend,
|
|
105
|
+
fetchWrapper: () => fetchWrapper,
|
|
106
|
+
formatTime: () => formatTime,
|
|
107
|
+
genreEndpoints: () => genreEndpoints,
|
|
108
|
+
genrePlaylistEndpoints: () => genrePlaylistEndpoints,
|
|
109
|
+
genrePlaylistQueryKeys: () => genrePlaylistQueryKeys,
|
|
110
|
+
genreQueryKeys: () => genreQueryKeys,
|
|
111
|
+
genreUpdateMutationKey: () => genreUpdateMutationKey,
|
|
112
|
+
getGenrePlaylistsGroupedByRoot: () => getGenrePlaylistsGroupedByRoot,
|
|
113
|
+
getReparentCandidates: () => getReparentCandidates,
|
|
114
|
+
getSpotifyAllowlistMailtoHref: () => getSpotifyAllowlistMailtoHref,
|
|
115
|
+
getSpotifyAllowlistMessage: () => getSpotifyAllowlistMessage,
|
|
116
|
+
getSpotifyRequiredCached: () => getSpotifyRequiredCached,
|
|
117
|
+
hasMainstreamPopRoot: () => hasMainstreamPopRoot,
|
|
118
|
+
isSong: () => isSong,
|
|
119
|
+
libraryEndpoints: () => libraryEndpoints,
|
|
120
|
+
libraryQueryKeys: () => libraryQueryKeys,
|
|
121
|
+
makeTrackPlaylistRelPageSchema: () => makeTrackPlaylistRelPageSchema,
|
|
122
|
+
makeTrackPlaylistRelSchema: () => makeTrackPlaylistRelSchema,
|
|
123
|
+
musicBrainzRecordingUrl: () => musicBrainzRecordingUrl,
|
|
124
|
+
parseWithLog: () => parseWithLog,
|
|
125
|
+
pruneGenrePlaylistsForArtist: () => pruneGenrePlaylistsForArtist,
|
|
126
|
+
queryClient: () => queryClient,
|
|
127
|
+
resolveRedirectUri: () => resolveRedirectUri,
|
|
128
|
+
searchGenrePlaylistsByName: () => searchGenrePlaylistsByName,
|
|
129
|
+
setSpotifyRequiredCached: () => setSpotifyRequiredCached,
|
|
130
|
+
songUnplayableReason: () => songUnplayableReason,
|
|
131
|
+
storeRedirectUrl: () => storeRedirectUrl,
|
|
132
|
+
useArtist: () => useArtist,
|
|
133
|
+
useArtistGenreCounts: () => useArtistGenreCounts,
|
|
134
|
+
useArtistSearch: () => useArtistSearch,
|
|
135
|
+
useAuthCallback: () => useAuthCallback,
|
|
136
|
+
useConnectivityError: () => useConnectivityError,
|
|
137
|
+
useConnectivityErrorPopup: () => useConnectivityErrorPopup,
|
|
138
|
+
useCreateGenre: () => useCreateGenre,
|
|
139
|
+
useCurrentTime: () => useCurrentTime,
|
|
140
|
+
useDeleteGenre: () => useDeleteGenre,
|
|
141
|
+
useFetchGenre: () => useFetchGenre,
|
|
142
|
+
useFetchGenreDetail: () => useFetchGenreDetail,
|
|
143
|
+
useFetchGenreOverview: () => useFetchGenreOverview,
|
|
144
|
+
useFetchGenrePlaylist: () => useFetchGenrePlaylist,
|
|
145
|
+
useFetchWrapper: () => useFetchWrapper,
|
|
146
|
+
useGenreSearch: () => useGenreSearch,
|
|
147
|
+
useGenreTreeViewState: () => useGenreTreeViewState,
|
|
148
|
+
useInvalidateAllGenrePlaylistQueries: () => useInvalidateAllGenrePlaylistQueries,
|
|
149
|
+
useListFullGenrePlaylists: () => useListFullGenrePlaylists,
|
|
150
|
+
useListGenrePlaylists: () => useListGenrePlaylists,
|
|
151
|
+
useListGenres: () => useListGenres,
|
|
152
|
+
useListTracks: () => useListTracks,
|
|
153
|
+
useLogout: () => useLogout,
|
|
154
|
+
usePlayer: () => usePlayer,
|
|
155
|
+
usePopup: () => usePopup,
|
|
156
|
+
usePrefetchGenreOverview: () => usePrefetchGenreOverview,
|
|
157
|
+
useQueryWithParse: () => useQueryWithParse,
|
|
158
|
+
useSession: () => useSession,
|
|
159
|
+
useTrackList: () => useTrackList,
|
|
160
|
+
useTrackListSidebarVisibility: () => useTrackListSidebarVisibility,
|
|
161
|
+
useTrackNoun: () => useTrackNoun,
|
|
162
|
+
useTrackUpload: () => useTrackUpload,
|
|
163
|
+
useUpdateGenre: () => useUpdateGenre,
|
|
164
|
+
useValidatedMutation: () => useValidatedMutation,
|
|
165
|
+
useVisibleGenrePlaylists: () => useVisibleGenrePlaylists
|
|
166
|
+
});
|
|
167
|
+
module.exports = __toCommonJS(src_exports);
|
|
168
|
+
|
|
169
|
+
// src/transport/app-errors/app-error-codes.ts
|
|
170
|
+
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
171
|
+
ErrorCode2["NETWORK_OFFLINE"] = "NET1000";
|
|
172
|
+
ErrorCode2["NETWORK_TIMEOUT"] = "NET1001";
|
|
173
|
+
ErrorCode2["NETWORK_CONNECTION_REFUSED"] = "NET1002";
|
|
174
|
+
ErrorCode2["NETWORK_NOT_FOUND"] = "NET1003";
|
|
175
|
+
ErrorCode2["NETWORK_ERROR"] = "NET1004";
|
|
176
|
+
ErrorCode2["NETWORK_FETCH_ERROR"] = "NET1005";
|
|
177
|
+
ErrorCode2["NETWORK_ABORT_ERROR"] = "NET1006";
|
|
178
|
+
ErrorCode2["NETWORK_FAILED_TO_FETCH"] = "NET1007";
|
|
179
|
+
ErrorCode2["NETWORK_UNKNOWN"] = "NET1008";
|
|
180
|
+
ErrorCode2["BACKEND_UNAVAILABLE"] = "BAC2000";
|
|
181
|
+
ErrorCode2["BACKEND_RATE_LIMIT"] = "BAC2001";
|
|
182
|
+
ErrorCode2["BACKEND_AUTH_ERROR"] = "BAC2002";
|
|
183
|
+
ErrorCode2["BACKEND_INVALID_RESPONSE"] = "BAC2003";
|
|
184
|
+
ErrorCode2["BACKEND_INTERNAL_ERROR"] = "BAC5000";
|
|
185
|
+
ErrorCode2["BACKEND_BAD_REQUEST"] = "BAC4000";
|
|
186
|
+
ErrorCode2["BACKEND_UNAUTHORIZED"] = "BAC4010";
|
|
187
|
+
ErrorCode2["BACKEND_FORBIDDEN"] = "BAC4030";
|
|
188
|
+
ErrorCode2["BACKEND_SPOTIFY_AUTHORIZATION_REQUIRED"] = "BAC4031";
|
|
189
|
+
ErrorCode2["BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED"] = "BAC4011";
|
|
190
|
+
ErrorCode2["BACKEND_SPOTIFY_OAUTH_CODE_INVALID_OR_EXPIRED"] = "BAC4017";
|
|
191
|
+
ErrorCode2["BACKEND_SPOTIFY_OAUTH_INVALID_CLIENT"] = "BAC4018";
|
|
192
|
+
ErrorCode2["BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST"] = "BAC4012";
|
|
193
|
+
ErrorCode2["BACKEND_SPOTIFY_AUTHENTICATION_ERROR"] = "BAC4013";
|
|
194
|
+
ErrorCode2["BACKEND_GOOGLE_AUTHENTICATION_ERROR"] = "BAC4014";
|
|
195
|
+
ErrorCode2["BACKEND_GOOGLE_OAUTH_MISCONFIGURED"] = "BAC4015";
|
|
196
|
+
ErrorCode2["BACKEND_GOOGLE_OAUTH_UNAUTHORIZED_CLIENT"] = "BAC4016";
|
|
197
|
+
ErrorCode2["BACKEND_NOT_FOUND"] = "BAC4040";
|
|
198
|
+
ErrorCode2["BACKEND_METHOD_NOT_ALLOWED"] = "BAC4050";
|
|
199
|
+
ErrorCode2["BACKEND_REQUEST_TIMEOUT"] = "BAC4080";
|
|
200
|
+
ErrorCode2["SESSION_EXPIRED"] = "SES4011";
|
|
201
|
+
ErrorCode2["SESSION_REQUIRED"] = "SES4012";
|
|
202
|
+
ErrorCode2["CLIENT_FORBIDDEN"] = "CLI4030";
|
|
203
|
+
ErrorCode2["CLIENT_NOT_FOUND"] = "CLI4040";
|
|
204
|
+
ErrorCode2["CLIENT_UNAUTHORIZED"] = "CLI4010";
|
|
205
|
+
ErrorCode2["CLIENT_INTERNAL_ERROR"] = "CLI5000";
|
|
206
|
+
ErrorCode2["CLIENT_UNKNOWN"] = "CLI5001";
|
|
207
|
+
ErrorCode2["SERVICE_BAD_REQUEST"] = "SER4000";
|
|
208
|
+
ErrorCode2["SERVICE_UNAUTHORIZED"] = "SER4010";
|
|
209
|
+
ErrorCode2["SERVICE_FORBIDDEN"] = "SER4030";
|
|
210
|
+
ErrorCode2["SERVICE_NOT_FOUND"] = "SER4040";
|
|
211
|
+
ErrorCode2["SERVICE_INTERNAL_ERROR"] = "SER5000";
|
|
212
|
+
ErrorCode2["SERVICE_UNKNOWN"] = "SER5001";
|
|
213
|
+
ErrorCode2["SERVICE_METHOD_NOT_ALLOWED"] = "SER4050";
|
|
214
|
+
ErrorCode2["SERVICE_REQUEST_TIMEOUT"] = "SER4080";
|
|
215
|
+
ErrorCode2["BACKEND_INVALID_INPUT"] = "INP4220";
|
|
216
|
+
return ErrorCode2;
|
|
217
|
+
})(ErrorCode || {});
|
|
218
|
+
|
|
219
|
+
// src/transport/app-errors/app-error-messages.ts
|
|
220
|
+
var SPOTIFY_ACCESS_REQUEST_SUBJECT = "Spotify access request";
|
|
221
|
+
var SPOTIFY_ACCESS_REQUEST_BODY = `I would like to request access to the app.
|
|
222
|
+
|
|
223
|
+
Spotify full name:
|
|
224
|
+
Spotify email address:`;
|
|
225
|
+
function getSpotifyAllowlistMessage() {
|
|
226
|
+
return "Your Spotify account is not yet authorized for this app.";
|
|
227
|
+
}
|
|
228
|
+
function getSpotifyAllowlistMailtoHref(contactEmail) {
|
|
229
|
+
if (!contactEmail) return null;
|
|
230
|
+
const params = new URLSearchParams({
|
|
231
|
+
subject: SPOTIFY_ACCESS_REQUEST_SUBJECT,
|
|
232
|
+
body: SPOTIFY_ACCESS_REQUEST_BODY
|
|
233
|
+
});
|
|
234
|
+
return `mailto:${contactEmail}?${params.toString()}`;
|
|
235
|
+
}
|
|
236
|
+
var ErrorMessages = {
|
|
237
|
+
// Network Errors
|
|
238
|
+
["NET1000" /* NETWORK_OFFLINE */]: "Network connection unavailable",
|
|
239
|
+
["NET1001" /* NETWORK_TIMEOUT */]: "Request timed out",
|
|
240
|
+
["NET1002" /* NETWORK_CONNECTION_REFUSED */]: "Connection refused",
|
|
241
|
+
["NET1003" /* NETWORK_NOT_FOUND */]: "Network not found",
|
|
242
|
+
["NET1004" /* NETWORK_ERROR */]: "Network error occurred",
|
|
243
|
+
["NET1005" /* NETWORK_FETCH_ERROR */]: "Failed to fetch data",
|
|
244
|
+
["NET1006" /* NETWORK_ABORT_ERROR */]: "Request aborted",
|
|
245
|
+
["NET1007" /* NETWORK_FAILED_TO_FETCH */]: "Failed to fetch",
|
|
246
|
+
["NET1008" /* NETWORK_UNKNOWN */]: "Unknown network error",
|
|
247
|
+
// Backend Errors
|
|
248
|
+
["BAC2000" /* BACKEND_UNAVAILABLE */]: "Service temporarily unavailable",
|
|
249
|
+
["BAC2001" /* BACKEND_RATE_LIMIT */]: "Too many requests, please try again later",
|
|
250
|
+
["BAC2002" /* BACKEND_AUTH_ERROR */]: "Authentication failed",
|
|
251
|
+
["BAC5000" /* BACKEND_INTERNAL_ERROR */]: "Internal server error",
|
|
252
|
+
["BAC2003" /* BACKEND_INVALID_RESPONSE */]: "Invalid response from server",
|
|
253
|
+
["BAC4000" /* BACKEND_BAD_REQUEST */]: "Bad request",
|
|
254
|
+
["BAC4010" /* BACKEND_UNAUTHORIZED */]: "Unauthorized",
|
|
255
|
+
["BAC4030" /* BACKEND_FORBIDDEN */]: "Forbidden",
|
|
256
|
+
["BAC4031" /* BACKEND_SPOTIFY_AUTHORIZATION_REQUIRED */]: "Connect Spotify to continue",
|
|
257
|
+
["BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */]: "Authorization code already used, expired, or invalid. Please try signing in again from the login page.",
|
|
258
|
+
["BAC4017" /* BACKEND_SPOTIFY_OAUTH_CODE_INVALID_OR_EXPIRED */]: "Authorization code already used, expired, or invalid. Please try signing in again from the login page.",
|
|
259
|
+
["BAC4018" /* BACKEND_SPOTIFY_OAUTH_INVALID_CLIENT */]: "Spotify sign-in is temporarily misconfigured. Please try again later or contact support.",
|
|
260
|
+
["BAC4012" /* BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST */]: getSpotifyAllowlistMessage(),
|
|
261
|
+
["BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */]: "Spotify authentication failed",
|
|
262
|
+
["BAC4014" /* BACKEND_GOOGLE_AUTHENTICATION_ERROR */]: "Google authentication failed",
|
|
263
|
+
["BAC4015" /* BACKEND_GOOGLE_OAUTH_MISCONFIGURED */]: "Sign-in is temporarily misconfigured. Please try again later or contact support.",
|
|
264
|
+
["BAC4016" /* BACKEND_GOOGLE_OAUTH_UNAUTHORIZED_CLIENT */]: "Google sign-in is temporarily unavailable. Please try again later or contact support.",
|
|
265
|
+
["BAC4040" /* BACKEND_NOT_FOUND */]: "Not found",
|
|
266
|
+
["BAC4050" /* BACKEND_METHOD_NOT_ALLOWED */]: "Method not allowed",
|
|
267
|
+
["BAC4080" /* BACKEND_REQUEST_TIMEOUT */]: "Request timeout",
|
|
268
|
+
["INP4220" /* BACKEND_INVALID_INPUT */]: "Invalid input",
|
|
269
|
+
// Session Errors
|
|
270
|
+
["SES4011" /* SESSION_EXPIRED */]: "Session expired",
|
|
271
|
+
["SES4012" /* SESSION_REQUIRED */]: "Session required",
|
|
272
|
+
// Client Errors
|
|
273
|
+
["CLI5001" /* CLIENT_UNKNOWN */]: "Unknown error",
|
|
274
|
+
["CLI4030" /* CLIENT_FORBIDDEN */]: "Forbidden",
|
|
275
|
+
["CLI4040" /* CLIENT_NOT_FOUND */]: "Not found",
|
|
276
|
+
["CLI4010" /* CLIENT_UNAUTHORIZED */]: "Unauthorized",
|
|
277
|
+
["CLI5000" /* CLIENT_INTERNAL_ERROR */]: "Internal client error",
|
|
278
|
+
// Service Errors
|
|
279
|
+
["SER4000" /* SERVICE_BAD_REQUEST */]: "Bad request",
|
|
280
|
+
["SER4010" /* SERVICE_UNAUTHORIZED */]: "Unauthorized",
|
|
281
|
+
["SER4030" /* SERVICE_FORBIDDEN */]: "Forbidden",
|
|
282
|
+
["SER4040" /* SERVICE_NOT_FOUND */]: "Not found",
|
|
283
|
+
["SER5000" /* SERVICE_INTERNAL_ERROR */]: "Internal server error",
|
|
284
|
+
["SER5001" /* SERVICE_UNKNOWN */]: "Unknown service error",
|
|
285
|
+
["SER4050" /* SERVICE_METHOD_NOT_ALLOWED */]: "Method not allowed",
|
|
286
|
+
["SER4080" /* SERVICE_REQUEST_TIMEOUT */]: "Request timeout"
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// src/transport/app-errors/app-error.ts
|
|
290
|
+
var AppError = class extends Error {
|
|
291
|
+
constructor(code) {
|
|
292
|
+
super(ErrorMessages[code]);
|
|
293
|
+
this.code = code;
|
|
294
|
+
this.name = "AppError";
|
|
295
|
+
}
|
|
296
|
+
code;
|
|
297
|
+
};
|
|
298
|
+
var ClientError = class extends AppError {
|
|
299
|
+
constructor(code) {
|
|
300
|
+
super(code);
|
|
301
|
+
this.name = "ClientError";
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
var InvalidInputError = class extends ClientError {
|
|
305
|
+
constructor(code, json) {
|
|
306
|
+
super(code);
|
|
307
|
+
this.json = json;
|
|
308
|
+
this.name = "InvalidInputError";
|
|
309
|
+
}
|
|
310
|
+
json;
|
|
311
|
+
toString() {
|
|
312
|
+
return `${super.toString()}
|
|
313
|
+
JSON: ${JSON.stringify(this.json, null, 2)}`;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
var ConnectivityError = class extends AppError {
|
|
317
|
+
constructor(code) {
|
|
318
|
+
super(code);
|
|
319
|
+
this.name = "ConnectivityError";
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
var BadRequestError = class extends ConnectivityError {
|
|
323
|
+
constructor(code) {
|
|
324
|
+
super(code);
|
|
325
|
+
this.name = "BadRequestError";
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
var NetworkError = class extends ConnectivityError {
|
|
329
|
+
constructor(code) {
|
|
330
|
+
super(code);
|
|
331
|
+
this.name = "NetworkError";
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
var BackendError = class extends ConnectivityError {
|
|
335
|
+
constructor(code, backendMessage) {
|
|
336
|
+
super(code);
|
|
337
|
+
this.backendMessage = backendMessage;
|
|
338
|
+
this.name = "BackendError";
|
|
339
|
+
if (backendMessage) {
|
|
340
|
+
this.message = backendMessage;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
backendMessage;
|
|
344
|
+
};
|
|
345
|
+
var BackendSpotifyUserNotAllowlistedError = class extends BackendError {
|
|
346
|
+
constructor(code, detailsMessage) {
|
|
347
|
+
super(code);
|
|
348
|
+
this.detailsMessage = detailsMessage;
|
|
349
|
+
this.name = "BackendSpotifyUserNotAllowlistedError";
|
|
350
|
+
}
|
|
351
|
+
detailsMessage;
|
|
352
|
+
};
|
|
353
|
+
var AuthRequired = class extends ConnectivityError {
|
|
354
|
+
constructor(code) {
|
|
355
|
+
super(code);
|
|
356
|
+
this.name = "AuthRequired";
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
var ServiceError = class extends ConnectivityError {
|
|
360
|
+
constructor(code) {
|
|
361
|
+
super(code);
|
|
362
|
+
this.name = "ServiceError";
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
// src/transport/app-errors/app-error-factory.ts
|
|
367
|
+
function createAppErrorFromErrorCode(code, json) {
|
|
368
|
+
if (["BAC4010" /* BACKEND_UNAUTHORIZED */, "SES4011" /* SESSION_EXPIRED */, "SES4012" /* SESSION_REQUIRED */].includes(code)) {
|
|
369
|
+
return new AuthRequired(code);
|
|
370
|
+
} else if (code.startsWith("NET")) {
|
|
371
|
+
return new NetworkError(code);
|
|
372
|
+
} else if (code.startsWith("BAC")) {
|
|
373
|
+
return new BackendError(code);
|
|
374
|
+
} else if (code.startsWith("CLI")) {
|
|
375
|
+
return new ClientError(code);
|
|
376
|
+
} else if (code.startsWith("SER")) {
|
|
377
|
+
return new ServiceError(code);
|
|
378
|
+
} else if (code.startsWith("INP")) {
|
|
379
|
+
return new InvalidInputError(code, json || {});
|
|
380
|
+
}
|
|
381
|
+
return new AppError(code);
|
|
382
|
+
}
|
|
383
|
+
async function createAppErrorFromResult(result, backendBaseUrl) {
|
|
384
|
+
const isBackendError = !!backendBaseUrl && result.url.includes(backendBaseUrl);
|
|
385
|
+
if (result.status === 400) {
|
|
386
|
+
if (isBackendError) {
|
|
387
|
+
try {
|
|
388
|
+
const json = await result.json();
|
|
389
|
+
return createAppErrorFromErrorCode("INP4220" /* BACKEND_INVALID_INPUT */, json);
|
|
390
|
+
} catch {
|
|
391
|
+
return createAppErrorFromErrorCode("INP4220" /* BACKEND_INVALID_INPUT */);
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
394
|
+
return createAppErrorFromErrorCode("SER4000" /* SERVICE_BAD_REQUEST */);
|
|
395
|
+
}
|
|
396
|
+
} else if (result.status === 401) {
|
|
397
|
+
if (isBackendError) {
|
|
398
|
+
try {
|
|
399
|
+
const body = await result.json();
|
|
400
|
+
const apiCode = body?.code;
|
|
401
|
+
const detailsCode = body?.details?.code;
|
|
402
|
+
if (detailsCode === "google_oauth_code_invalid_or_expired") {
|
|
403
|
+
return new BackendError(
|
|
404
|
+
"BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */,
|
|
405
|
+
body.details?.message
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
if (detailsCode === "spotify_oauth_code_invalid_or_expired") {
|
|
409
|
+
return new BackendError(
|
|
410
|
+
"BAC4017" /* BACKEND_SPOTIFY_OAUTH_CODE_INVALID_OR_EXPIRED */,
|
|
411
|
+
body.details?.message
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
if (detailsCode === "spotify_user_not_in_allowlist") {
|
|
415
|
+
return new BackendError(
|
|
416
|
+
"BAC4012" /* BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST */,
|
|
417
|
+
getSpotifyAllowlistMessage()
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
if (detailsCode === "spotify_authentication_error") {
|
|
421
|
+
return new BackendError(
|
|
422
|
+
"BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */,
|
|
423
|
+
body.details?.message
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
if (detailsCode === "google_authentication_error") {
|
|
427
|
+
return new BackendError(
|
|
428
|
+
"BAC4014" /* BACKEND_GOOGLE_AUTHENTICATION_ERROR */,
|
|
429
|
+
body.details?.message
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
if (detailsCode === "google_oauth_redirect_uri_mismatch" || detailsCode === "google_oauth_invalid_client") {
|
|
433
|
+
return new BackendError(
|
|
434
|
+
"BAC4015" /* BACKEND_GOOGLE_OAUTH_MISCONFIGURED */,
|
|
435
|
+
body.details?.message
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
if (detailsCode === "google_oauth_unauthorized_client") {
|
|
439
|
+
return new BackendError(
|
|
440
|
+
"BAC4016" /* BACKEND_GOOGLE_OAUTH_UNAUTHORIZED_CLIENT */,
|
|
441
|
+
body.details?.message
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
if (apiCode === 1006 || detailsCode === "authentication_required" || apiCode === 1001) {
|
|
445
|
+
return createAppErrorFromErrorCode("BAC4010" /* BACKEND_UNAUTHORIZED */);
|
|
446
|
+
}
|
|
447
|
+
} catch {
|
|
448
|
+
}
|
|
449
|
+
return createAppErrorFromErrorCode("BAC4010" /* BACKEND_UNAUTHORIZED */);
|
|
450
|
+
} else {
|
|
451
|
+
return createAppErrorFromErrorCode("SER4010" /* SERVICE_UNAUTHORIZED */);
|
|
452
|
+
}
|
|
453
|
+
} else if (result.status === 403) {
|
|
454
|
+
if (isBackendError) {
|
|
455
|
+
try {
|
|
456
|
+
const body = await result.json();
|
|
457
|
+
const apiCode = body?.code;
|
|
458
|
+
const detailsCode = body?.details?.code;
|
|
459
|
+
if (apiCode === 1005 || detailsCode === "spotify_authorization_required") {
|
|
460
|
+
return createAppErrorFromErrorCode("BAC4031" /* BACKEND_SPOTIFY_AUTHORIZATION_REQUIRED */);
|
|
461
|
+
}
|
|
462
|
+
} catch {
|
|
463
|
+
}
|
|
464
|
+
return createAppErrorFromErrorCode("BAC4030" /* BACKEND_FORBIDDEN */);
|
|
465
|
+
} else {
|
|
466
|
+
return createAppErrorFromErrorCode("SER4030" /* SERVICE_FORBIDDEN */);
|
|
467
|
+
}
|
|
468
|
+
} else if (result.status === 404) {
|
|
469
|
+
if (isBackendError) {
|
|
470
|
+
return createAppErrorFromErrorCode("BAC4040" /* BACKEND_NOT_FOUND */);
|
|
471
|
+
} else {
|
|
472
|
+
return createAppErrorFromErrorCode("SER4040" /* SERVICE_NOT_FOUND */);
|
|
473
|
+
}
|
|
474
|
+
} else if (result.status === 405) {
|
|
475
|
+
if (isBackendError) {
|
|
476
|
+
return createAppErrorFromErrorCode("BAC4050" /* BACKEND_METHOD_NOT_ALLOWED */);
|
|
477
|
+
} else {
|
|
478
|
+
return createAppErrorFromErrorCode("SER4050" /* SERVICE_METHOD_NOT_ALLOWED */);
|
|
479
|
+
}
|
|
480
|
+
} else if (result.status === 408) {
|
|
481
|
+
if (isBackendError) {
|
|
482
|
+
return createAppErrorFromErrorCode("BAC4080" /* BACKEND_REQUEST_TIMEOUT */);
|
|
483
|
+
} else {
|
|
484
|
+
return createAppErrorFromErrorCode("SER4080" /* SERVICE_REQUEST_TIMEOUT */);
|
|
485
|
+
}
|
|
486
|
+
} else if (result.status === 500) {
|
|
487
|
+
if (isBackendError) {
|
|
488
|
+
try {
|
|
489
|
+
const body = await result.json();
|
|
490
|
+
const detailsCode = body?.details?.code;
|
|
491
|
+
if (detailsCode === "spotify_invalid_client") {
|
|
492
|
+
return new BackendError(
|
|
493
|
+
"BAC4018" /* BACKEND_SPOTIFY_OAUTH_INVALID_CLIENT */,
|
|
494
|
+
body.details?.message
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
} catch {
|
|
498
|
+
}
|
|
499
|
+
return createAppErrorFromErrorCode("BAC5000" /* BACKEND_INTERNAL_ERROR */);
|
|
500
|
+
} else {
|
|
501
|
+
return createAppErrorFromErrorCode("SER5000" /* SERVICE_INTERNAL_ERROR */);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return createAppErrorFromErrorCode("CLI5001" /* CLIENT_UNKNOWN */);
|
|
505
|
+
}
|
|
506
|
+
function createNetworkOrBackendError(error, url, backendBaseUrl) {
|
|
507
|
+
const isBackendError = !!backendBaseUrl && url.includes(backendBaseUrl);
|
|
508
|
+
if (typeof navigator !== "undefined" && !navigator.onLine) {
|
|
509
|
+
return createAppErrorFromErrorCode("NET1000" /* NETWORK_OFFLINE */);
|
|
510
|
+
}
|
|
511
|
+
if (!(error instanceof Error)) {
|
|
512
|
+
if (typeof error === "string") {
|
|
513
|
+
return isBackendError ? createAppErrorFromErrorCode("BAC5000" /* BACKEND_INTERNAL_ERROR */) : createAppErrorFromErrorCode("NET1008" /* NETWORK_UNKNOWN */);
|
|
514
|
+
}
|
|
515
|
+
return createAppErrorFromErrorCode("NET1008" /* NETWORK_UNKNOWN */);
|
|
516
|
+
}
|
|
517
|
+
if (error instanceof TypeError) {
|
|
518
|
+
if (error.message.includes("timeout")) {
|
|
519
|
+
return isBackendError ? createAppErrorFromErrorCode("BAC4080" /* BACKEND_REQUEST_TIMEOUT */) : createAppErrorFromErrorCode("NET1001" /* NETWORK_TIMEOUT */);
|
|
520
|
+
}
|
|
521
|
+
return createAppErrorFromErrorCode("NET1007" /* NETWORK_FAILED_TO_FETCH */);
|
|
522
|
+
}
|
|
523
|
+
if (error.name === "AbortError") {
|
|
524
|
+
return createAppErrorFromErrorCode("NET1006" /* NETWORK_ABORT_ERROR */);
|
|
525
|
+
}
|
|
526
|
+
if (error.message?.includes("Failed to fetch")) {
|
|
527
|
+
return createAppErrorFromErrorCode("NET1007" /* NETWORK_FAILED_TO_FETCH */);
|
|
528
|
+
}
|
|
529
|
+
if (error.message?.includes("not found")) {
|
|
530
|
+
return isBackendError ? createAppErrorFromErrorCode("BAC4040" /* BACKEND_NOT_FOUND */) : createAppErrorFromErrorCode("NET1003" /* NETWORK_NOT_FOUND */);
|
|
531
|
+
}
|
|
532
|
+
return isBackendError ? createAppErrorFromErrorCode("BAC5000" /* BACKEND_INTERNAL_ERROR */) : createAppErrorFromErrorCode("NET1008" /* NETWORK_UNKNOWN */);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// src/transport/app-errors/app-error-types.ts
|
|
536
|
+
var ConnectivityErrorType = /* @__PURE__ */ ((ConnectivityErrorType2) => {
|
|
537
|
+
ConnectivityErrorType2["NETWORK"] = "NETWORK";
|
|
538
|
+
ConnectivityErrorType2["INTERNAL"] = "INTERNAL";
|
|
539
|
+
ConnectivityErrorType2["AUTH_REQUIRED"] = "AUTH_REQUIRED";
|
|
540
|
+
ConnectivityErrorType2["BAD_REQUEST"] = "BAD_REQUEST";
|
|
541
|
+
return ConnectivityErrorType2;
|
|
542
|
+
})(ConnectivityErrorType || {});
|
|
543
|
+
|
|
544
|
+
// src/transport/fetch-wrapper.ts
|
|
545
|
+
var NETWORK_RETRY_DELAYS_MS = [300, 900];
|
|
546
|
+
var fetchWithNetworkRetry = async (url, options) => {
|
|
547
|
+
const method = (options.method ?? "GET").toUpperCase();
|
|
548
|
+
const retryable = method === "GET" || method === "HEAD";
|
|
549
|
+
for (let attempt = 0; ; attempt++) {
|
|
550
|
+
try {
|
|
551
|
+
return await fetch(url, options);
|
|
552
|
+
} catch (error) {
|
|
553
|
+
if (!retryable || options.signal?.aborted || attempt >= NETWORK_RETRY_DELAYS_MS.length) throw error;
|
|
554
|
+
await new Promise((resolve) => setTimeout(resolve, NETWORK_RETRY_DELAYS_MS[attempt]));
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
var assertWellFormedRequest = (url, options) => {
|
|
559
|
+
if (typeof Request !== "function" || typeof URL !== "function") return;
|
|
560
|
+
try {
|
|
561
|
+
const base = globalThis.document?.baseURI ?? globalThis.location?.href;
|
|
562
|
+
const { method } = new Request(new URL(url, base), { ...options, body: void 0 });
|
|
563
|
+
if (options.body != null && (method === "GET" || method === "HEAD")) {
|
|
564
|
+
throw new TypeError(`${method} request cannot have a body`);
|
|
565
|
+
}
|
|
566
|
+
} catch (error) {
|
|
567
|
+
if (!(error instanceof TypeError)) throw error;
|
|
568
|
+
throw Object.assign(createAppErrorFromErrorCode("CLI5000" /* CLIENT_INTERNAL_ERROR */), { cause: error });
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
var fetchWrapper = async (url, requiresAuth, options = {}, accessToken, queryParams, handleMissingRequiredSession, handleError, expectBinary = false, backendBaseUrl) => {
|
|
572
|
+
const urlWithParams = queryParams ? `${url}${url.includes("?") ? "&" : "?"}${new URLSearchParams(
|
|
573
|
+
Object.entries(queryParams).map(([key, value]) => [key, String(value)])
|
|
574
|
+
).toString()}` : url;
|
|
575
|
+
const finalUrl = urlWithParams;
|
|
576
|
+
const isFormData = options.body instanceof FormData;
|
|
577
|
+
const finalOptions = {
|
|
578
|
+
...options,
|
|
579
|
+
headers: {
|
|
580
|
+
...isFormData ? {} : { "Content-Type": "application/json" },
|
|
581
|
+
...accessToken && { Authorization: `Bearer ${accessToken}` },
|
|
582
|
+
...options.headers || {}
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
if (requiresAuth && !accessToken) {
|
|
586
|
+
handleMissingRequiredSession?.();
|
|
587
|
+
return null;
|
|
588
|
+
}
|
|
589
|
+
try {
|
|
590
|
+
assertWellFormedRequest(finalUrl, finalOptions);
|
|
591
|
+
const result = await fetchWithNetworkRetry(finalUrl, finalOptions);
|
|
592
|
+
if (!result.ok) {
|
|
593
|
+
const appError = await createAppErrorFromResult(result, backendBaseUrl);
|
|
594
|
+
throw appError;
|
|
595
|
+
}
|
|
596
|
+
if (result.status === 204) {
|
|
597
|
+
return null;
|
|
598
|
+
}
|
|
599
|
+
if (expectBinary) {
|
|
600
|
+
return await result.arrayBuffer();
|
|
601
|
+
} else {
|
|
602
|
+
return result.json();
|
|
603
|
+
}
|
|
604
|
+
} catch (caughtError) {
|
|
605
|
+
let appError = null;
|
|
606
|
+
if (caughtError instanceof AppError) {
|
|
607
|
+
appError = caughtError;
|
|
608
|
+
} else {
|
|
609
|
+
appError = createNetworkOrBackendError(caughtError, finalUrl, backendBaseUrl);
|
|
610
|
+
}
|
|
611
|
+
if (!handleError) throw appError;
|
|
612
|
+
handleError(appError);
|
|
613
|
+
const method = (finalOptions.method ?? "GET").toUpperCase();
|
|
614
|
+
if (method !== "GET" && method !== "HEAD") throw appError;
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
// src/transport/useFetchWrapper.ts
|
|
620
|
+
var import_react3 = require("react");
|
|
621
|
+
|
|
622
|
+
// src/transport/connectivity-error-context.tsx
|
|
623
|
+
var import_react = require("react");
|
|
624
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
625
|
+
var ConnectivityErrorContext = (0, import_react.createContext)(void 0);
|
|
626
|
+
function ConnectivityErrorProvider({ children }) {
|
|
627
|
+
const [connectivityError, setConnectivityError] = (0, import_react.useState)(null);
|
|
628
|
+
const clearConnectivityError = (0, import_react.useCallback)(() => {
|
|
629
|
+
setConnectivityError(null);
|
|
630
|
+
}, []);
|
|
631
|
+
const handleSetConnectivityError = (0, import_react.useCallback)((error) => {
|
|
632
|
+
setConnectivityError(error);
|
|
633
|
+
}, []);
|
|
634
|
+
const value = (0, import_react.useMemo)(
|
|
635
|
+
() => ({
|
|
636
|
+
connectivityError,
|
|
637
|
+
setConnectivityError: handleSetConnectivityError,
|
|
638
|
+
clearConnectivityError
|
|
639
|
+
}),
|
|
640
|
+
[connectivityError, handleSetConnectivityError, clearConnectivityError]
|
|
641
|
+
);
|
|
642
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConnectivityErrorContext.Provider, { value, children });
|
|
643
|
+
}
|
|
644
|
+
function useConnectivityError() {
|
|
645
|
+
const context = (0, import_react.useContext)(ConnectivityErrorContext);
|
|
646
|
+
if (context === void 0) {
|
|
647
|
+
throw new Error("useConnectivityError must be used within a ConnectivityErrorProvider");
|
|
648
|
+
}
|
|
649
|
+
return context;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// src/auth/SessionContext.tsx
|
|
653
|
+
var import_react2 = require("react");
|
|
654
|
+
|
|
655
|
+
// src/transport/query-client.ts
|
|
656
|
+
var import_react_query = require("@tanstack/react-query");
|
|
657
|
+
var queryClient = new import_react_query.QueryClient({
|
|
658
|
+
defaultOptions: {
|
|
659
|
+
queries: {
|
|
660
|
+
staleTime: 60 * 1e3,
|
|
661
|
+
// 1 minute
|
|
662
|
+
retry: false
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
// src/auth/spotify-required-cache.ts
|
|
668
|
+
var SPOTIFY_REQUIRED_KEY = "spotify_required";
|
|
669
|
+
function getSpotifyRequiredCached() {
|
|
670
|
+
if (typeof window === "undefined") return false;
|
|
671
|
+
return sessionStorage.getItem(SPOTIFY_REQUIRED_KEY) === "1";
|
|
672
|
+
}
|
|
673
|
+
function setSpotifyRequiredCached() {
|
|
674
|
+
if (typeof window === "undefined") return;
|
|
675
|
+
sessionStorage.setItem(SPOTIFY_REQUIRED_KEY, "1");
|
|
676
|
+
}
|
|
677
|
+
function clearSpotifyRequiredCached() {
|
|
678
|
+
if (typeof window === "undefined") return;
|
|
679
|
+
sessionStorage.removeItem(SPOTIFY_REQUIRED_KEY);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// src/auth/SessionContext.tsx
|
|
683
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
684
|
+
var defaultSession = {
|
|
685
|
+
accessToken: null,
|
|
686
|
+
refreshToken: null,
|
|
687
|
+
expiresAt: null
|
|
688
|
+
};
|
|
689
|
+
var SESSION_STORAGE_KEY = "session";
|
|
690
|
+
var SessionContext = (0, import_react2.createContext)(void 0);
|
|
691
|
+
function SessionProvider({ children }) {
|
|
692
|
+
const [session, setSessionState] = (0, import_react2.useState)(defaultSession);
|
|
693
|
+
const [sessionRestored, setSessionRestored] = (0, import_react2.useState)(false);
|
|
694
|
+
(0, import_react2.useEffect)(() => {
|
|
695
|
+
const storedSession = localStorage.getItem(SESSION_STORAGE_KEY);
|
|
696
|
+
if (storedSession) {
|
|
697
|
+
try {
|
|
698
|
+
const parsed = JSON.parse(storedSession);
|
|
699
|
+
setSessionState(parsed);
|
|
700
|
+
if (parsed?.accessToken) {
|
|
701
|
+
queryClient.invalidateQueries();
|
|
702
|
+
}
|
|
703
|
+
} catch {
|
|
704
|
+
localStorage.removeItem(SESSION_STORAGE_KEY);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
setSessionRestored(true);
|
|
708
|
+
}, []);
|
|
709
|
+
const setSession = (0, import_react2.useCallback)((newSession) => {
|
|
710
|
+
setSessionState(newSession);
|
|
711
|
+
localStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(newSession));
|
|
712
|
+
}, []);
|
|
713
|
+
const clearSession = (0, import_react2.useCallback)(() => {
|
|
714
|
+
setSessionState(defaultSession);
|
|
715
|
+
localStorage.removeItem(SESSION_STORAGE_KEY);
|
|
716
|
+
clearSpotifyRequiredCached();
|
|
717
|
+
queryClient.clear();
|
|
718
|
+
}, []);
|
|
719
|
+
const value = (0, import_react2.useMemo)(
|
|
720
|
+
() => ({ session, setSession, clearSession, sessionRestored }),
|
|
721
|
+
[session, setSession, clearSession, sessionRestored]
|
|
722
|
+
);
|
|
723
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SessionContext.Provider, { value, children });
|
|
724
|
+
}
|
|
725
|
+
function useSession() {
|
|
726
|
+
const context = (0, import_react2.useContext)(SessionContext);
|
|
727
|
+
if (context === void 0) {
|
|
728
|
+
throw new Error("useSession must be used within a SessionProvider");
|
|
729
|
+
}
|
|
730
|
+
return context;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// src/transport/useFetchWrapper.ts
|
|
734
|
+
var useFetchWrapper = (getBackendBaseUrl) => {
|
|
735
|
+
const { setConnectivityError } = useConnectivityError();
|
|
736
|
+
const { clearSession, session, sessionRestored } = useSession();
|
|
737
|
+
const handleError = (0, import_react3.useCallback)((error) => {
|
|
738
|
+
if (error instanceof ConnectivityError) {
|
|
739
|
+
const authDetailErrors = [
|
|
740
|
+
"BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */,
|
|
741
|
+
"BAC4012" /* BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST */,
|
|
742
|
+
"BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */,
|
|
743
|
+
"BAC4014" /* BACKEND_GOOGLE_AUTHENTICATION_ERROR */,
|
|
744
|
+
"BAC4015" /* BACKEND_GOOGLE_OAUTH_MISCONFIGURED */
|
|
745
|
+
];
|
|
746
|
+
if (error instanceof BackendError && authDetailErrors.includes(error.code)) {
|
|
747
|
+
throw error;
|
|
748
|
+
}
|
|
749
|
+
if (error instanceof AuthRequired) {
|
|
750
|
+
clearSession();
|
|
751
|
+
}
|
|
752
|
+
setConnectivityError(error);
|
|
753
|
+
if (error instanceof BackendError && error.code === "BAC4031" /* BACKEND_SPOTIFY_AUTHORIZATION_REQUIRED */) {
|
|
754
|
+
throw error;
|
|
755
|
+
}
|
|
756
|
+
} else {
|
|
757
|
+
throw error;
|
|
758
|
+
}
|
|
759
|
+
}, [clearSession, setConnectivityError]);
|
|
760
|
+
const handleMissingRequiredSession = () => {
|
|
761
|
+
if (!sessionRestored) return;
|
|
762
|
+
setConnectivityError(createAppErrorFromErrorCode("SES4012" /* SESSION_REQUIRED */));
|
|
763
|
+
};
|
|
764
|
+
const fetch2 = (0, import_react3.useCallback)((backendEndpointOrUrl, fromBackend = true, requiresAuth = true, options = {}, queryParams, expectBinary = false, skipGlobalError = false) => {
|
|
765
|
+
const baseUrl = getBackendBaseUrl().replace(/\/+$/, "");
|
|
766
|
+
const endpointPath = String(backendEndpointOrUrl);
|
|
767
|
+
if (fromBackend && endpointPath.startsWith("/")) {
|
|
768
|
+
throw new Error(`Endpoint path must be relative (no leading slash). Got: "${endpointPath}".`);
|
|
769
|
+
}
|
|
770
|
+
const url = fromBackend ? endpointPath ? `${baseUrl}/${endpointPath}` : baseUrl : backendEndpointOrUrl;
|
|
771
|
+
return fetchWrapper(
|
|
772
|
+
url,
|
|
773
|
+
requiresAuth,
|
|
774
|
+
options,
|
|
775
|
+
session?.accessToken || void 0,
|
|
776
|
+
queryParams,
|
|
777
|
+
handleMissingRequiredSession,
|
|
778
|
+
skipGlobalError ? void 0 : handleError,
|
|
779
|
+
expectBinary,
|
|
780
|
+
baseUrl
|
|
781
|
+
);
|
|
782
|
+
}, [session?.accessToken, handleError, getBackendBaseUrl, sessionRestored, setConnectivityError]);
|
|
783
|
+
return { fetch: fetch2 };
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
// src/transport/site-urls.ts
|
|
787
|
+
function buildSubdomainBaseUrl({
|
|
788
|
+
subdomain,
|
|
789
|
+
orgDomain,
|
|
790
|
+
isProduction,
|
|
791
|
+
stagingSuffix = "-staging"
|
|
792
|
+
}) {
|
|
793
|
+
if (!subdomain) throw new Error("subdomain is required");
|
|
794
|
+
if (!orgDomain) throw new Error("orgDomain is required");
|
|
795
|
+
const host = isProduction ? subdomain : `${subdomain}${stagingSuffix}`;
|
|
796
|
+
return `https://${host}.${orgDomain}`;
|
|
797
|
+
}
|
|
798
|
+
function buildBackendBaseUrl(params) {
|
|
799
|
+
if (params.overrideUrl) return params.overrideUrl;
|
|
800
|
+
const { apiSubdomain, orgDomain, apiRootSegment, isProduction, stagingSuffix } = params;
|
|
801
|
+
if (!apiRootSegment) throw new Error("apiRootSegment is required");
|
|
802
|
+
const origin = buildSubdomainBaseUrl({ subdomain: apiSubdomain, orgDomain, isProduction, stagingSuffix });
|
|
803
|
+
return `${origin}/${apiRootSegment.replace(/^\/+|\/+$/g, "")}/`;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// src/transport/lib/parse-with-log.ts
|
|
807
|
+
var import_zod = require("zod");
|
|
808
|
+
function parseWithLog(schema, data, context) {
|
|
809
|
+
const result = schema.safeParse(data);
|
|
810
|
+
if (!result.success) {
|
|
811
|
+
const prefix = context ? `[${context}]` : "";
|
|
812
|
+
if (data == null) {
|
|
813
|
+
throw new Error(`${prefix} received null response before schema validation`);
|
|
814
|
+
}
|
|
815
|
+
console.error(`${prefix} schema validation failed`, import_zod.z.flattenError(result.error));
|
|
816
|
+
throw result.error;
|
|
817
|
+
}
|
|
818
|
+
return result.data;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
// src/transport/lib/paginated-response.ts
|
|
822
|
+
var import_zod2 = require("zod");
|
|
823
|
+
var PaginatedResponseSchema = (itemSchema) => import_zod2.z.object({
|
|
824
|
+
overallTotal: import_zod2.z.number(),
|
|
825
|
+
next: import_zod2.z.string().url().nullable(),
|
|
826
|
+
previous: import_zod2.z.string().url().nullable(),
|
|
827
|
+
results: import_zod2.z.array(itemSchema),
|
|
828
|
+
page: import_zod2.z.number(),
|
|
829
|
+
pageSize: import_zod2.z.number(),
|
|
830
|
+
totalPages: import_zod2.z.number()
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
// src/transport/lib/use-query-with-parse.ts
|
|
834
|
+
var import_react_query2 = require("@tanstack/react-query");
|
|
835
|
+
function useQueryWithParse({
|
|
836
|
+
queryFn,
|
|
837
|
+
schema,
|
|
838
|
+
context,
|
|
839
|
+
...options
|
|
840
|
+
}) {
|
|
841
|
+
return (0, import_react_query2.useQuery)({
|
|
842
|
+
...options,
|
|
843
|
+
queryFn: async () => {
|
|
844
|
+
const response = await queryFn();
|
|
845
|
+
return parseWithLog(schema, response, context);
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
// src/transport/lib/use-validated-mutation.ts
|
|
851
|
+
var import_react_query3 = require("@tanstack/react-query");
|
|
852
|
+
var import_react4 = require("react");
|
|
853
|
+
var import_zod3 = require("zod");
|
|
854
|
+
function useValidatedMutation({
|
|
855
|
+
inputSchema,
|
|
856
|
+
outputSchema,
|
|
857
|
+
mutationFn,
|
|
858
|
+
...options
|
|
859
|
+
}) {
|
|
860
|
+
const [formErrors, setFormErrors] = (0, import_react4.useState)([]);
|
|
861
|
+
const validatedMutation = (0, import_react_query3.useMutation)({
|
|
862
|
+
...options,
|
|
863
|
+
mutationFn: async (data) => {
|
|
864
|
+
setFormErrors([]);
|
|
865
|
+
const parsedInput = inputSchema.safeParse(data);
|
|
866
|
+
if (!parsedInput.success) {
|
|
867
|
+
const fieldErrors = parsedInput.error.issues.map((error) => ({
|
|
868
|
+
field: error.path.map(String).join("."),
|
|
869
|
+
message: error.message
|
|
870
|
+
}));
|
|
871
|
+
setFormErrors(fieldErrors);
|
|
872
|
+
throw new Error("Invalid input data");
|
|
873
|
+
}
|
|
874
|
+
try {
|
|
875
|
+
const response = await mutationFn(parsedInput.data);
|
|
876
|
+
const parsedOutput = outputSchema.safeParse(response);
|
|
877
|
+
if (!parsedOutput.success) {
|
|
878
|
+
console.error("Output validation failed:", parsedOutput.error);
|
|
879
|
+
setFormErrors([{ field: "form", message: "Invalid response from server" }]);
|
|
880
|
+
throw new Error("Invalid response from server");
|
|
881
|
+
}
|
|
882
|
+
return parsedOutput.data;
|
|
883
|
+
} catch (error) {
|
|
884
|
+
if (error instanceof Error && "json" in error) {
|
|
885
|
+
try {
|
|
886
|
+
const errorResponse = import_zod3.z.object({
|
|
887
|
+
details: import_zod3.z.object({
|
|
888
|
+
fieldErrors: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.array(import_zod3.z.object({ message: import_zod3.z.string() })))
|
|
889
|
+
})
|
|
890
|
+
}).parse(error.json);
|
|
891
|
+
setFormErrors(
|
|
892
|
+
Object.entries(errorResponse.details.fieldErrors || {}).flatMap(
|
|
893
|
+
([field, errors]) => errors.map((err) => ({
|
|
894
|
+
field,
|
|
895
|
+
message: err.message
|
|
896
|
+
}))
|
|
897
|
+
)
|
|
898
|
+
);
|
|
899
|
+
} catch (parseError) {
|
|
900
|
+
console.error("Failed to parse error response:", parseError);
|
|
901
|
+
setFormErrors([{ field: "form", message: "An error occurred" }]);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
throw error;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
});
|
|
908
|
+
return { ...validatedMutation, formErrors };
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
// src/auth/code-exchange.ts
|
|
912
|
+
var SPOTIFY_EXCHANGE_CONFIG = {
|
|
913
|
+
endpoint: "auth/spotify/",
|
|
914
|
+
redirectStorageKey: "spotifyAuthRedirect",
|
|
915
|
+
rethrowErrorCodes: [
|
|
916
|
+
"BAC4012" /* BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST */,
|
|
917
|
+
"BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */,
|
|
918
|
+
"BAC4018" /* BACKEND_SPOTIFY_OAUTH_INVALID_CLIENT */
|
|
919
|
+
]
|
|
920
|
+
};
|
|
921
|
+
var GOOGLE_EXCHANGE_CONFIG = {
|
|
922
|
+
endpoint: "auth/google/",
|
|
923
|
+
redirectStorageKey: "googleAuthRedirect",
|
|
924
|
+
rethrowErrorCodes: [
|
|
925
|
+
"BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */,
|
|
926
|
+
"BAC4016" /* BACKEND_GOOGLE_OAUTH_UNAUTHORIZED_CLIENT */,
|
|
927
|
+
"BAC4014" /* BACKEND_GOOGLE_AUTHENTICATION_ERROR */,
|
|
928
|
+
"BAC4015" /* BACKEND_GOOGLE_OAUTH_MISCONFIGURED */
|
|
929
|
+
]
|
|
930
|
+
};
|
|
931
|
+
async function exchangeCodeWithBackend(fetchAuth, setSession, setConnectivityError, config, code) {
|
|
932
|
+
const { endpoint, redirectStorageKey, rethrowErrorCodes } = config;
|
|
933
|
+
const setBackendAuthError = () => setConnectivityError(createAppErrorFromErrorCode("BAC2002" /* BACKEND_AUTH_ERROR */));
|
|
934
|
+
try {
|
|
935
|
+
const response = await fetchAuth(endpoint, true, false, {
|
|
936
|
+
method: "POST",
|
|
937
|
+
body: JSON.stringify({ code })
|
|
938
|
+
});
|
|
939
|
+
if (!response) {
|
|
940
|
+
setBackendAuthError();
|
|
941
|
+
return null;
|
|
942
|
+
}
|
|
943
|
+
setSession({
|
|
944
|
+
accessToken: response.accessToken,
|
|
945
|
+
refreshToken: response.refreshToken,
|
|
946
|
+
expiresAt: response.expiresAt
|
|
947
|
+
});
|
|
948
|
+
const stored = localStorage.getItem(redirectStorageKey);
|
|
949
|
+
if (stored) {
|
|
950
|
+
localStorage.removeItem(redirectStorageKey);
|
|
951
|
+
try {
|
|
952
|
+
const url = new URL(stored);
|
|
953
|
+
return url.pathname + url.search;
|
|
954
|
+
} catch {
|
|
955
|
+
return "/";
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
return "/";
|
|
959
|
+
} catch (e) {
|
|
960
|
+
if (e instanceof BackendError && rethrowErrorCodes.includes(e.code)) {
|
|
961
|
+
throw e;
|
|
962
|
+
}
|
|
963
|
+
console.error("[auth] exchangeCodeWithBackend error", e);
|
|
964
|
+
setBackendAuthError();
|
|
965
|
+
return null;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
function resolveRedirectUri(redirectUriEnv) {
|
|
969
|
+
return redirectUriEnv.startsWith("http") ? redirectUriEnv : `${window.location.origin}${redirectUriEnv.startsWith("/") ? "" : "/"}${redirectUriEnv}`;
|
|
970
|
+
}
|
|
971
|
+
function storeRedirectUrl(redirectStorageKey, redirectAfterAuthPath) {
|
|
972
|
+
const path = typeof redirectAfterAuthPath === "string" ? redirectAfterAuthPath : void 0;
|
|
973
|
+
const urlToStore = path ? `${window.location.origin}${path.startsWith("/") ? "" : "/"}${path}` : window.location.href;
|
|
974
|
+
localStorage.setItem(redirectStorageKey, urlToStore);
|
|
975
|
+
}
|
|
976
|
+
function clearStoredRedirectUrl(redirectStorageKey) {
|
|
977
|
+
localStorage.removeItem(redirectStorageKey);
|
|
978
|
+
}
|
|
979
|
+
function createLogout(clearConnectivityError, clearSession) {
|
|
980
|
+
return () => {
|
|
981
|
+
clearConnectivityError();
|
|
982
|
+
clearSession();
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
// src/auth/useLogout.ts
|
|
987
|
+
var import_react5 = require("react");
|
|
988
|
+
function useLogout() {
|
|
989
|
+
const { clearSession } = useSession();
|
|
990
|
+
const { clearConnectivityError } = useConnectivityError();
|
|
991
|
+
const logout = (0, import_react5.useCallback)(
|
|
992
|
+
createLogout(clearConnectivityError, clearSession),
|
|
993
|
+
[clearConnectivityError, clearSession]
|
|
994
|
+
);
|
|
995
|
+
return { logout };
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// src/auth/useAuthCallback.ts
|
|
999
|
+
var import_react6 = require("react");
|
|
1000
|
+
var import_navigation = require("next/navigation");
|
|
1001
|
+
function useAuthCallback({
|
|
1002
|
+
googleCallbackPathname = "/auth/google/callback",
|
|
1003
|
+
spotifyCallbackPathname = "/auth/spotify/callback",
|
|
1004
|
+
authToBackendFromGoogleCode,
|
|
1005
|
+
authToBackendFromSpotifyCode,
|
|
1006
|
+
onReauthRequired,
|
|
1007
|
+
onOAuthMisconfigured,
|
|
1008
|
+
onSpotifyAuthError
|
|
1009
|
+
}) {
|
|
1010
|
+
const router = (0, import_navigation.useRouter)();
|
|
1011
|
+
const [state, setState] = (0, import_react6.useState)("idle");
|
|
1012
|
+
const [errorMessage, setErrorMessage] = (0, import_react6.useState)(null);
|
|
1013
|
+
const handled = (0, import_react6.useRef)(false);
|
|
1014
|
+
(0, import_react6.useEffect)(() => {
|
|
1015
|
+
if (typeof window === "undefined" || handled.current) return;
|
|
1016
|
+
const pathname = window.location.pathname;
|
|
1017
|
+
const params = new URLSearchParams(window.location.search);
|
|
1018
|
+
const code = params.get("code");
|
|
1019
|
+
const errorParam = params.get("error");
|
|
1020
|
+
const isGoogleCallback = pathname === googleCallbackPathname;
|
|
1021
|
+
const isSpotifyCallback = pathname === spotifyCallbackPathname;
|
|
1022
|
+
if (!isGoogleCallback && !isSpotifyCallback) return;
|
|
1023
|
+
handled.current = true;
|
|
1024
|
+
setState("handling");
|
|
1025
|
+
const runGoogle = async () => {
|
|
1026
|
+
if (errorParam) {
|
|
1027
|
+
setErrorMessage(`Google authentication failed: ${errorParam}`);
|
|
1028
|
+
setState("error");
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
if (!code) {
|
|
1032
|
+
setErrorMessage("No authorization code received from Google");
|
|
1033
|
+
setState("error");
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
try {
|
|
1037
|
+
const redirectUrl = await authToBackendFromGoogleCode(code);
|
|
1038
|
+
setState("done");
|
|
1039
|
+
router.replace(redirectUrl || "/");
|
|
1040
|
+
} catch (err) {
|
|
1041
|
+
if (err instanceof BackendError && err.code === "BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */) {
|
|
1042
|
+
clearStoredRedirectUrl(GOOGLE_EXCHANGE_CONFIG.redirectStorageKey);
|
|
1043
|
+
onReauthRequired();
|
|
1044
|
+
router.replace("/");
|
|
1045
|
+
} else if (err instanceof BackendError && err.code === "BAC4016" /* BACKEND_GOOGLE_OAUTH_UNAUTHORIZED_CLIENT */) {
|
|
1046
|
+
onOAuthMisconfigured(err.code);
|
|
1047
|
+
router.replace("/");
|
|
1048
|
+
} else {
|
|
1049
|
+
setErrorMessage(err instanceof Error ? err.message : "Authentication failed");
|
|
1050
|
+
setState("error");
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
const runSpotify = async () => {
|
|
1055
|
+
if (errorParam) {
|
|
1056
|
+
onSpotifyAuthError(`Spotify authentication failed: ${errorParam}`, () => router.replace("/"));
|
|
1057
|
+
setState("done");
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
if (!code) {
|
|
1061
|
+
onSpotifyAuthError("No authorization code received from Spotify", () => router.replace("/"));
|
|
1062
|
+
setState("done");
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
try {
|
|
1066
|
+
const redirectUrl = await authToBackendFromSpotifyCode(code);
|
|
1067
|
+
setState("done");
|
|
1068
|
+
router.replace(redirectUrl || "/");
|
|
1069
|
+
} catch (err) {
|
|
1070
|
+
if (err instanceof BackendError && (err.code === "BAC4017" /* BACKEND_SPOTIFY_OAUTH_CODE_INVALID_OR_EXPIRED */ || err.code === "BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */)) {
|
|
1071
|
+
clearStoredRedirectUrl(SPOTIFY_EXCHANGE_CONFIG.redirectStorageKey);
|
|
1072
|
+
onReauthRequired();
|
|
1073
|
+
router.replace("/");
|
|
1074
|
+
} else if (err instanceof BackendError && err.code === "BAC4018" /* BACKEND_SPOTIFY_OAUTH_INVALID_CLIENT */) {
|
|
1075
|
+
onOAuthMisconfigured(err.code);
|
|
1076
|
+
router.replace("/");
|
|
1077
|
+
} else {
|
|
1078
|
+
const message = err instanceof BackendError ? err.code === "BAC2002" /* BACKEND_AUTH_ERROR */ ? "Failed to authenticate with the backend server." : err.message : "An unexpected error occurred.";
|
|
1079
|
+
onSpotifyAuthError(message, () => router.replace("/"));
|
|
1080
|
+
}
|
|
1081
|
+
setState("done");
|
|
1082
|
+
}
|
|
1083
|
+
};
|
|
1084
|
+
if (isGoogleCallback) runGoogle();
|
|
1085
|
+
else runSpotify();
|
|
1086
|
+
}, [
|
|
1087
|
+
googleCallbackPathname,
|
|
1088
|
+
spotifyCallbackPathname,
|
|
1089
|
+
authToBackendFromGoogleCode,
|
|
1090
|
+
authToBackendFromSpotifyCode,
|
|
1091
|
+
onReauthRequired,
|
|
1092
|
+
onOAuthMisconfigured,
|
|
1093
|
+
onSpotifyAuthError,
|
|
1094
|
+
router
|
|
1095
|
+
]);
|
|
1096
|
+
if (state === "handling") return { status: "pending" };
|
|
1097
|
+
if (state === "error") return { status: "error", message: errorMessage, goHome: () => router.replace("/") };
|
|
1098
|
+
return { status: null };
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
// src/popup/PopupContext.tsx
|
|
1102
|
+
var import_react7 = require("react");
|
|
1103
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1104
|
+
var AUTH_POPUP_TYPE = "auth";
|
|
1105
|
+
var PopupContext = (0, import_react7.createContext)(void 0);
|
|
1106
|
+
function PopupProvider({ children }) {
|
|
1107
|
+
const [state, setState] = (0, import_react7.useState)({ content: null, type: null });
|
|
1108
|
+
const activePopup = state.content;
|
|
1109
|
+
const showPopup = (0, import_react7.useCallback)((popup, type) => {
|
|
1110
|
+
setState({ content: popup, type: type ?? null });
|
|
1111
|
+
}, []);
|
|
1112
|
+
const hidePopup = (0, import_react7.useCallback)((options) => {
|
|
1113
|
+
if (options?.onlyIfType !== void 0) {
|
|
1114
|
+
setState((prev) => prev.type === options.onlyIfType ? { content: null, type: null } : prev);
|
|
1115
|
+
} else {
|
|
1116
|
+
setState({ content: null, type: null });
|
|
1117
|
+
}
|
|
1118
|
+
}, []);
|
|
1119
|
+
const value = (0, import_react7.useMemo)(() => ({ showPopup, hidePopup, activePopup }), [showPopup, hidePopup, activePopup]);
|
|
1120
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PopupContext.Provider, { value, children });
|
|
1121
|
+
}
|
|
1122
|
+
function usePopup() {
|
|
1123
|
+
const context = (0, import_react7.useContext)(PopupContext);
|
|
1124
|
+
if (context === void 0) {
|
|
1125
|
+
throw new Error("usePopup must be used within a PopupProvider");
|
|
1126
|
+
}
|
|
1127
|
+
return context;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
// src/popup/useConnectivityErrorPopup.ts
|
|
1131
|
+
var import_react8 = require("react");
|
|
1132
|
+
var ALWAYS_REDISPLAY_ON_REPEAT = [NetworkError, BackendError, ClientError, ServiceError, InvalidInputError];
|
|
1133
|
+
function useConnectivityErrorPopup({
|
|
1134
|
+
isAccountPage,
|
|
1135
|
+
routeRequiresAuth,
|
|
1136
|
+
routeRequiresSpotify,
|
|
1137
|
+
renderers
|
|
1138
|
+
}) {
|
|
1139
|
+
const { showPopup, hidePopup } = usePopup();
|
|
1140
|
+
const { connectivityError, clearConnectivityError } = useConnectivityError();
|
|
1141
|
+
const currentConnectivityErrorRef = (0, import_react8.useRef)(null);
|
|
1142
|
+
const renderersRef = (0, import_react8.useRef)(renderers);
|
|
1143
|
+
renderersRef.current = renderers;
|
|
1144
|
+
(0, import_react8.useEffect)(() => {
|
|
1145
|
+
if (connectivityError === null) {
|
|
1146
|
+
if (currentConnectivityErrorRef.current !== null) {
|
|
1147
|
+
currentConnectivityErrorRef.current = null;
|
|
1148
|
+
hidePopup();
|
|
1149
|
+
}
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
const error = connectivityError;
|
|
1153
|
+
const isSpotifyAllowlistOrAuthError = error instanceof BackendError && ["BAC4012" /* BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST */, "BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */].includes(
|
|
1154
|
+
error.code
|
|
1155
|
+
);
|
|
1156
|
+
if (isSpotifyAllowlistOrAuthError && !routeRequiresSpotify) {
|
|
1157
|
+
hidePopup();
|
|
1158
|
+
clearConnectivityError();
|
|
1159
|
+
currentConnectivityErrorRef.current = null;
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
if (currentConnectivityErrorRef.current == null || !ALWAYS_REDISPLAY_ON_REPEAT.includes(currentConnectivityErrorRef.current) && !(connectivityError instanceof currentConnectivityErrorRef.current)) {
|
|
1163
|
+
const renderer = renderersRef.current;
|
|
1164
|
+
let popup = null;
|
|
1165
|
+
let popupType = null;
|
|
1166
|
+
if (!isAccountPage && routeRequiresAuth && error instanceof AuthRequired) {
|
|
1167
|
+
popup = renderer.renderAuthPopup();
|
|
1168
|
+
popupType = AUTH_POPUP_TYPE;
|
|
1169
|
+
} else if (!isAccountPage && routeRequiresSpotify && error instanceof BackendError && error.code === "BAC4031" /* BACKEND_SPOTIFY_AUTHORIZATION_REQUIRED */) {
|
|
1170
|
+
popup = renderer.renderSpotifyOnlyAuthPopup();
|
|
1171
|
+
popupType = AUTH_POPUP_TYPE;
|
|
1172
|
+
} else if (error instanceof InvalidInputError) {
|
|
1173
|
+
console.error("[InvalidInputError]", error.code, error.json);
|
|
1174
|
+
popup = renderer.renderInternalErrorPopup(error.code);
|
|
1175
|
+
} else if (routeRequiresSpotify && error instanceof BackendError && ["BAC4012" /* BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST */, "BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */].includes(
|
|
1176
|
+
error.code
|
|
1177
|
+
)) {
|
|
1178
|
+
popup = renderer.renderSpotifyAuthErrorPopup({
|
|
1179
|
+
message: error.message,
|
|
1180
|
+
errorCode: error.code,
|
|
1181
|
+
onClose: () => hidePopup()
|
|
1182
|
+
});
|
|
1183
|
+
} else if (error instanceof BackendError && [
|
|
1184
|
+
"BAC4014" /* BACKEND_GOOGLE_AUTHENTICATION_ERROR */,
|
|
1185
|
+
"BAC4015" /* BACKEND_GOOGLE_OAUTH_MISCONFIGURED */,
|
|
1186
|
+
"BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */
|
|
1187
|
+
].includes(error.code)) {
|
|
1188
|
+
popup = renderer.renderGoogleAuthErrorPopup({ message: error.message, onClose: () => hidePopup() });
|
|
1189
|
+
} else if (error instanceof BadRequestError || error instanceof BackendError || error instanceof ServiceError || error instanceof AuthRequired) {
|
|
1190
|
+
popup = renderer.renderInternalErrorPopup(error.code);
|
|
1191
|
+
} else if (error instanceof NetworkError) {
|
|
1192
|
+
popup = renderer.renderNetworkErrorPopup();
|
|
1193
|
+
}
|
|
1194
|
+
if (popup) {
|
|
1195
|
+
showPopup(popup, popupType);
|
|
1196
|
+
}
|
|
1197
|
+
currentConnectivityErrorRef.current = error.constructor;
|
|
1198
|
+
}
|
|
1199
|
+
}, [
|
|
1200
|
+
connectivityError,
|
|
1201
|
+
showPopup,
|
|
1202
|
+
hidePopup,
|
|
1203
|
+
clearConnectivityError,
|
|
1204
|
+
isAccountPage,
|
|
1205
|
+
routeRequiresAuth,
|
|
1206
|
+
routeRequiresSpotify
|
|
1207
|
+
]);
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
// src/popup/useTrackUpload.ts
|
|
1211
|
+
var import_react9 = require("react");
|
|
1212
|
+
function useTrackUpload({
|
|
1213
|
+
files,
|
|
1214
|
+
genre,
|
|
1215
|
+
onProcessFile,
|
|
1216
|
+
onComplete,
|
|
1217
|
+
uploadTimeoutMs
|
|
1218
|
+
}) {
|
|
1219
|
+
const [items, setItems] = (0, import_react9.useState)([]);
|
|
1220
|
+
const [currentUploadIndex, setCurrentUploadIndex] = (0, import_react9.useState)(0);
|
|
1221
|
+
const [isUploading, setIsUploading] = (0, import_react9.useState)(false);
|
|
1222
|
+
const [allComplete, setAllComplete] = (0, import_react9.useState)(false);
|
|
1223
|
+
const lastFilesKeyRef = (0, import_react9.useRef)(null);
|
|
1224
|
+
const progressIntervalRef = (0, import_react9.useRef)(null);
|
|
1225
|
+
const runRef = (0, import_react9.useRef)(0);
|
|
1226
|
+
const completedRunRef = (0, import_react9.useRef)(null);
|
|
1227
|
+
(0, import_react9.useEffect)(() => {
|
|
1228
|
+
const filesKey = `${files.length}-${files.map((f) => `${f.name}:${f.size}`).join("|")}-${genre ?? ""}`;
|
|
1229
|
+
if (lastFilesKeyRef.current === filesKey) return;
|
|
1230
|
+
lastFilesKeyRef.current = filesKey;
|
|
1231
|
+
runRef.current += 1;
|
|
1232
|
+
if (progressIntervalRef.current) {
|
|
1233
|
+
clearInterval(progressIntervalRef.current);
|
|
1234
|
+
progressIntervalRef.current = null;
|
|
1235
|
+
}
|
|
1236
|
+
setItems(
|
|
1237
|
+
files.map((file, index) => ({
|
|
1238
|
+
id: `upload-${index}-${file.name}`,
|
|
1239
|
+
file,
|
|
1240
|
+
genre: genre ?? null,
|
|
1241
|
+
status: "pending",
|
|
1242
|
+
progress: 0
|
|
1243
|
+
}))
|
|
1244
|
+
);
|
|
1245
|
+
setCurrentUploadIndex(0);
|
|
1246
|
+
setIsUploading(false);
|
|
1247
|
+
setAllComplete(false);
|
|
1248
|
+
}, [files, genre]);
|
|
1249
|
+
const startNextUpload = (0, import_react9.useCallback)(() => {
|
|
1250
|
+
const currentItem = items[currentUploadIndex];
|
|
1251
|
+
setIsUploading(true);
|
|
1252
|
+
setItems(
|
|
1253
|
+
(prev) => prev.map((item, index) => index === currentUploadIndex ? { ...item, status: "uploading", progress: 0 } : item)
|
|
1254
|
+
);
|
|
1255
|
+
if (progressIntervalRef.current) clearInterval(progressIntervalRef.current);
|
|
1256
|
+
progressIntervalRef.current = setInterval(() => {
|
|
1257
|
+
setItems(
|
|
1258
|
+
(prev) => prev.map(
|
|
1259
|
+
(item, index) => index === currentUploadIndex && item.status === "uploading" ? { ...item, progress: Math.min(item.progress + Math.random() * 8, 99) } : item
|
|
1260
|
+
)
|
|
1261
|
+
);
|
|
1262
|
+
}, 800);
|
|
1263
|
+
const uploadingIndex = currentUploadIndex;
|
|
1264
|
+
const run = runRef.current;
|
|
1265
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
1266
|
+
setTimeout(() => reject(new Error("Upload timed out. The server took too long to respond.")), uploadTimeoutMs);
|
|
1267
|
+
});
|
|
1268
|
+
Promise.race([onProcessFile(currentItem.file, currentItem.genre), timeoutPromise]).then((data) => {
|
|
1269
|
+
if (run !== runRef.current) return;
|
|
1270
|
+
if (progressIntervalRef.current) {
|
|
1271
|
+
clearInterval(progressIntervalRef.current);
|
|
1272
|
+
progressIntervalRef.current = null;
|
|
1273
|
+
}
|
|
1274
|
+
setItems(
|
|
1275
|
+
(prev) => prev.map(
|
|
1276
|
+
(item, index) => index === uploadingIndex ? { ...item, status: "success", progress: 100, uploadedTrack: data } : item
|
|
1277
|
+
)
|
|
1278
|
+
);
|
|
1279
|
+
setIsUploading(false);
|
|
1280
|
+
setCurrentUploadIndex((prev) => prev + 1);
|
|
1281
|
+
}).catch((error) => {
|
|
1282
|
+
if (run !== runRef.current) return;
|
|
1283
|
+
if (progressIntervalRef.current) {
|
|
1284
|
+
clearInterval(progressIntervalRef.current);
|
|
1285
|
+
progressIntervalRef.current = null;
|
|
1286
|
+
}
|
|
1287
|
+
setItems(
|
|
1288
|
+
(prev) => prev.map((item, index) => index === uploadingIndex ? { ...item, status: "error", error } : item)
|
|
1289
|
+
);
|
|
1290
|
+
setIsUploading(false);
|
|
1291
|
+
setCurrentUploadIndex((prev) => prev + 1);
|
|
1292
|
+
});
|
|
1293
|
+
}, [items, currentUploadIndex, onProcessFile, uploadTimeoutMs]);
|
|
1294
|
+
(0, import_react9.useEffect)(() => {
|
|
1295
|
+
return () => {
|
|
1296
|
+
if (progressIntervalRef.current) {
|
|
1297
|
+
clearInterval(progressIntervalRef.current);
|
|
1298
|
+
progressIntervalRef.current = null;
|
|
1299
|
+
}
|
|
1300
|
+
};
|
|
1301
|
+
}, []);
|
|
1302
|
+
(0, import_react9.useEffect)(() => {
|
|
1303
|
+
const shouldStart = items.length > 0 && !isUploading && currentUploadIndex < items.length;
|
|
1304
|
+
if (shouldStart) {
|
|
1305
|
+
startNextUpload();
|
|
1306
|
+
}
|
|
1307
|
+
}, [items, currentUploadIndex, isUploading, startNextUpload]);
|
|
1308
|
+
(0, import_react9.useEffect)(() => {
|
|
1309
|
+
if (items.length > 0 && currentUploadIndex >= items.length && !isUploading) {
|
|
1310
|
+
if (completedRunRef.current === runRef.current) return;
|
|
1311
|
+
completedRunRef.current = runRef.current;
|
|
1312
|
+
setAllComplete(true);
|
|
1313
|
+
const successfulTracks = items.filter((item) => item.status === "success" && item.uploadedTrack).map((item) => item.uploadedTrack);
|
|
1314
|
+
onComplete?.(successfulTracks);
|
|
1315
|
+
}
|
|
1316
|
+
}, [items, currentUploadIndex, isUploading, onComplete]);
|
|
1317
|
+
return {
|
|
1318
|
+
items,
|
|
1319
|
+
isUploading,
|
|
1320
|
+
allComplete,
|
|
1321
|
+
successfulCount: items.filter((item) => item.status === "success").length,
|
|
1322
|
+
errorCount: items.filter((item) => item.status === "error").length
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
// src/track-noun/TrackNounContext.tsx
|
|
1327
|
+
var import_react10 = require("react");
|
|
1328
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1329
|
+
var TrackNounContext = (0, import_react10.createContext)(void 0);
|
|
1330
|
+
function TrackNounProvider({ singular, plural, children }) {
|
|
1331
|
+
const value = (0, import_react10.useMemo)(() => ({ singular, plural }), [singular, plural]);
|
|
1332
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TrackNounContext.Provider, { value, children });
|
|
1333
|
+
}
|
|
1334
|
+
function useTrackNoun() {
|
|
1335
|
+
const context = (0, import_react10.useContext)(TrackNounContext);
|
|
1336
|
+
if (context === void 0) {
|
|
1337
|
+
throw new Error("useTrackNoun must be used within a TrackNounProvider");
|
|
1338
|
+
}
|
|
1339
|
+
return context;
|
|
1340
|
+
}
|
|
1341
|
+
function capitalize(word) {
|
|
1342
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
// src/player/PlayStates.ts
|
|
1346
|
+
var PlayStates = /* @__PURE__ */ ((PlayStates2) => {
|
|
1347
|
+
PlayStates2["PLAYING"] = "PLAYING";
|
|
1348
|
+
PlayStates2["PAUSED"] = "PAUSED";
|
|
1349
|
+
PlayStates2["STOPPED"] = "STOPPED";
|
|
1350
|
+
PlayStates2["LOADING"] = "LOADING";
|
|
1351
|
+
return PlayStates2;
|
|
1352
|
+
})(PlayStates || {});
|
|
1353
|
+
|
|
1354
|
+
// src/player/PlayerContext.tsx
|
|
1355
|
+
var import_react11 = require("react");
|
|
1356
|
+
|
|
1357
|
+
// src/player/MediaController.ts
|
|
1358
|
+
var AudioMediaController = class {
|
|
1359
|
+
constructor(audio) {
|
|
1360
|
+
this.audio = audio;
|
|
1361
|
+
}
|
|
1362
|
+
audio;
|
|
1363
|
+
getCurrentTime() {
|
|
1364
|
+
return this.audio.currentTime;
|
|
1365
|
+
}
|
|
1366
|
+
setCurrentTime(time) {
|
|
1367
|
+
this.audio.currentTime = time;
|
|
1368
|
+
}
|
|
1369
|
+
getVolume() {
|
|
1370
|
+
return this.audio.volume * 100;
|
|
1371
|
+
}
|
|
1372
|
+
setVolume(volume) {
|
|
1373
|
+
this.audio.volume = volume / 100;
|
|
1374
|
+
}
|
|
1375
|
+
play() {
|
|
1376
|
+
this.audio.play().catch((error) => {
|
|
1377
|
+
console.error("Error playing audio:", error);
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
pause() {
|
|
1381
|
+
this.audio.pause();
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
var YoutubeMediaController = class {
|
|
1385
|
+
constructor(player) {
|
|
1386
|
+
this.player = player;
|
|
1387
|
+
}
|
|
1388
|
+
player;
|
|
1389
|
+
getCurrentTime() {
|
|
1390
|
+
return this.player.getCurrentTime();
|
|
1391
|
+
}
|
|
1392
|
+
setCurrentTime(time) {
|
|
1393
|
+
this.player.seekTo(time, true);
|
|
1394
|
+
}
|
|
1395
|
+
getVolume() {
|
|
1396
|
+
return this.player.getVolume();
|
|
1397
|
+
}
|
|
1398
|
+
setVolume(volume) {
|
|
1399
|
+
this.player.setVolume(volume);
|
|
1400
|
+
}
|
|
1401
|
+
play() {
|
|
1402
|
+
this.player.playVideo();
|
|
1403
|
+
}
|
|
1404
|
+
pause() {
|
|
1405
|
+
this.player.pauseVideo();
|
|
1406
|
+
}
|
|
1407
|
+
};
|
|
1408
|
+
|
|
1409
|
+
// src/player/youtubeIframeApi.ts
|
|
1410
|
+
var apiPromise = null;
|
|
1411
|
+
function loadYoutubeIframeApi() {
|
|
1412
|
+
if (typeof window === "undefined") {
|
|
1413
|
+
return Promise.reject(new Error("YouTube IFrame API can only be loaded in the browser"));
|
|
1414
|
+
}
|
|
1415
|
+
if (window.YT?.Player) {
|
|
1416
|
+
return Promise.resolve(window.YT);
|
|
1417
|
+
}
|
|
1418
|
+
if (apiPromise) {
|
|
1419
|
+
return apiPromise;
|
|
1420
|
+
}
|
|
1421
|
+
apiPromise = new Promise((resolve) => {
|
|
1422
|
+
const previousCallback = window.onYouTubeIframeAPIReady;
|
|
1423
|
+
window.onYouTubeIframeAPIReady = () => {
|
|
1424
|
+
previousCallback?.();
|
|
1425
|
+
resolve(window.YT);
|
|
1426
|
+
};
|
|
1427
|
+
const script = document.createElement("script");
|
|
1428
|
+
script.src = "https://www.youtube.com/iframe_api";
|
|
1429
|
+
document.head.appendChild(script);
|
|
1430
|
+
});
|
|
1431
|
+
return apiPromise;
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
// src/player/PlayerContext.tsx
|
|
1435
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1436
|
+
var isPlayable = (track) => track.kind !== "youtube" || !track.unplayableReason;
|
|
1437
|
+
function youtubeErrorMessage(code) {
|
|
1438
|
+
if (code === 100) return "Video not found";
|
|
1439
|
+
if (code === 101 || code === 150) return "Embedding disabled by the video owner";
|
|
1440
|
+
return `YouTube playback error (code ${code})`;
|
|
1441
|
+
}
|
|
1442
|
+
var PlayerContext = (0, import_react11.createContext)(void 0);
|
|
1443
|
+
function PlayerProvider({ children, loadTrack }) {
|
|
1444
|
+
const [playerTrackObject, setPlayerTrackObject] = (0, import_react11.useState)(null);
|
|
1445
|
+
const [isPlaying, setIsPlaying] = (0, import_react11.useState)(false);
|
|
1446
|
+
const [duration, setDuration] = (0, import_react11.useState)(0);
|
|
1447
|
+
const [volume, setVolume] = (0, import_react11.useState)(50);
|
|
1448
|
+
const [playState, setPlayState] = (0, import_react11.useState)("STOPPED" /* STOPPED */);
|
|
1449
|
+
const [isLoading, setIsLoading] = (0, import_react11.useState)(false);
|
|
1450
|
+
const [onTrackEnd, setOnTrackEnd] = (0, import_react11.useState)(null);
|
|
1451
|
+
const audioElementRef = (0, import_react11.useRef)(null);
|
|
1452
|
+
const youtubePlayerRef = (0, import_react11.useRef)(null);
|
|
1453
|
+
const videoContainerRef = (0, import_react11.useRef)(null);
|
|
1454
|
+
const currentTimeRef = (0, import_react11.useRef)(0);
|
|
1455
|
+
const onTrackEndRef = (0, import_react11.useRef)(onTrackEnd);
|
|
1456
|
+
(0, import_react11.useEffect)(() => {
|
|
1457
|
+
onTrackEndRef.current = onTrackEnd;
|
|
1458
|
+
}, [onTrackEnd]);
|
|
1459
|
+
(0, import_react11.useEffect)(() => {
|
|
1460
|
+
loadYoutubeIframeApi().catch(() => {
|
|
1461
|
+
});
|
|
1462
|
+
}, []);
|
|
1463
|
+
(0, import_react11.useEffect)(() => {
|
|
1464
|
+
const interval = setInterval(() => {
|
|
1465
|
+
const player = youtubePlayerRef.current;
|
|
1466
|
+
if (player) {
|
|
1467
|
+
currentTimeRef.current = player.getCurrentTime();
|
|
1468
|
+
setDuration(player.getDuration());
|
|
1469
|
+
}
|
|
1470
|
+
}, 250);
|
|
1471
|
+
return () => clearInterval(interval);
|
|
1472
|
+
}, []);
|
|
1473
|
+
const handleYoutubeStateChange = (0, import_react11.useCallback)((event) => {
|
|
1474
|
+
if (event.data === window.YT.PlayerState.ENDED) {
|
|
1475
|
+
setPlayState("STOPPED" /* STOPPED */);
|
|
1476
|
+
setIsPlaying(false);
|
|
1477
|
+
onTrackEndRef.current?.();
|
|
1478
|
+
}
|
|
1479
|
+
}, []);
|
|
1480
|
+
const loadAudioTrack = (0, import_react11.useCallback)(
|
|
1481
|
+
(track) => {
|
|
1482
|
+
const audio = new Audio(track.streamUrl);
|
|
1483
|
+
audio.volume = volume / 100;
|
|
1484
|
+
audioElementRef.current = audio;
|
|
1485
|
+
audio.addEventListener("loadedmetadata", () => {
|
|
1486
|
+
setDuration(audio.duration);
|
|
1487
|
+
});
|
|
1488
|
+
audio.addEventListener("timeupdate", () => {
|
|
1489
|
+
currentTimeRef.current = audio.currentTime;
|
|
1490
|
+
});
|
|
1491
|
+
audio.addEventListener("ended", () => {
|
|
1492
|
+
setPlayState("STOPPED" /* STOPPED */);
|
|
1493
|
+
setIsPlaying(false);
|
|
1494
|
+
onTrackEndRef.current?.();
|
|
1495
|
+
});
|
|
1496
|
+
audio.addEventListener("error", (e) => {
|
|
1497
|
+
console.error("Audio error event fired:", e);
|
|
1498
|
+
});
|
|
1499
|
+
setPlayerTrackObject({ track, mediaController: new AudioMediaController(audio), isReady: true, loadError: void 0 });
|
|
1500
|
+
setPlayState("PLAYING" /* PLAYING */);
|
|
1501
|
+
setIsPlaying(true);
|
|
1502
|
+
audio.play().catch((error) => {
|
|
1503
|
+
console.error("Error auto-playing audio:", error);
|
|
1504
|
+
});
|
|
1505
|
+
},
|
|
1506
|
+
[volume]
|
|
1507
|
+
);
|
|
1508
|
+
const loadYoutubeTrack = (0, import_react11.useCallback)(
|
|
1509
|
+
async (track) => {
|
|
1510
|
+
if (youtubePlayerRef.current) {
|
|
1511
|
+
const player = youtubePlayerRef.current;
|
|
1512
|
+
player.loadVideoById(track.youtubeVideoId);
|
|
1513
|
+
setPlayerTrackObject({ track, mediaController: new YoutubeMediaController(player), isReady: true, loadError: void 0 });
|
|
1514
|
+
setPlayState("PLAYING" /* PLAYING */);
|
|
1515
|
+
setIsPlaying(true);
|
|
1516
|
+
player.playVideo();
|
|
1517
|
+
return;
|
|
1518
|
+
}
|
|
1519
|
+
const container = videoContainerRef.current;
|
|
1520
|
+
if (!container) {
|
|
1521
|
+
throw new Error("PlayerVideoSurface must be rendered before a YouTube track can be loaded");
|
|
1522
|
+
}
|
|
1523
|
+
const YT = await loadYoutubeIframeApi();
|
|
1524
|
+
await new Promise((resolve) => {
|
|
1525
|
+
const player = new YT.Player(container, {
|
|
1526
|
+
videoId: track.youtubeVideoId,
|
|
1527
|
+
playerVars: { autoplay: 1 },
|
|
1528
|
+
events: {
|
|
1529
|
+
onReady: () => {
|
|
1530
|
+
youtubePlayerRef.current = player;
|
|
1531
|
+
setPlayerTrackObject({ track, mediaController: new YoutubeMediaController(player), isReady: true, loadError: void 0 });
|
|
1532
|
+
setPlayState("PLAYING" /* PLAYING */);
|
|
1533
|
+
setIsPlaying(true);
|
|
1534
|
+
player.playVideo();
|
|
1535
|
+
resolve();
|
|
1536
|
+
},
|
|
1537
|
+
onStateChange: handleYoutubeStateChange,
|
|
1538
|
+
onError: (event) => {
|
|
1539
|
+
const loadError = youtubeErrorMessage(event.data);
|
|
1540
|
+
setPlayerTrackObject((prev) => prev ? { ...prev, loadError } : prev);
|
|
1541
|
+
setPlayState("STOPPED" /* STOPPED */);
|
|
1542
|
+
setIsPlaying(false);
|
|
1543
|
+
onTrackEndRef.current?.();
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
});
|
|
1547
|
+
});
|
|
1548
|
+
},
|
|
1549
|
+
[handleYoutubeStateChange]
|
|
1550
|
+
);
|
|
1551
|
+
const loadTrackForPlayer = (0, import_react11.useCallback)(
|
|
1552
|
+
(trackId) => {
|
|
1553
|
+
if (audioElementRef.current) {
|
|
1554
|
+
audioElementRef.current.pause();
|
|
1555
|
+
audioElementRef.current.currentTime = 0;
|
|
1556
|
+
audioElementRef.current = null;
|
|
1557
|
+
}
|
|
1558
|
+
if (youtubePlayerRef.current) {
|
|
1559
|
+
youtubePlayerRef.current.pauseVideo();
|
|
1560
|
+
}
|
|
1561
|
+
setPlayerTrackObject(null);
|
|
1562
|
+
setIsLoading(true);
|
|
1563
|
+
setPlayState("LOADING" /* LOADING */);
|
|
1564
|
+
loadTrack(trackId).then((track) => track.kind === "youtube" ? loadYoutubeTrack(track) : loadAudioTrack(track)).catch((error) => {
|
|
1565
|
+
console.error("Error loading track:", error);
|
|
1566
|
+
setPlayState("STOPPED" /* STOPPED */);
|
|
1567
|
+
setPlayerTrackObject({
|
|
1568
|
+
track: { id: trackId, kind: "audio", streamUrl: "", title: "" },
|
|
1569
|
+
isReady: false,
|
|
1570
|
+
loadError: error?.message ?? "Failed to load track"
|
|
1571
|
+
});
|
|
1572
|
+
}).finally(() => {
|
|
1573
|
+
setIsLoading(false);
|
|
1574
|
+
});
|
|
1575
|
+
},
|
|
1576
|
+
[loadTrack, loadAudioTrack, loadYoutubeTrack]
|
|
1577
|
+
);
|
|
1578
|
+
const handleNextTrack = (0, import_react11.useCallback)(
|
|
1579
|
+
(trackList, currentTrack, onTrackChange) => {
|
|
1580
|
+
if (!trackList || !currentTrack) return;
|
|
1581
|
+
const currentIndex = trackList.findIndex((track) => track.id === currentTrack.id);
|
|
1582
|
+
if (currentIndex === -1) return;
|
|
1583
|
+
const nextTrack = trackList.slice(currentIndex + 1).find(isPlayable);
|
|
1584
|
+
if (nextTrack) {
|
|
1585
|
+
onTrackChange(nextTrack);
|
|
1586
|
+
loadTrackForPlayer(nextTrack.id);
|
|
1587
|
+
}
|
|
1588
|
+
},
|
|
1589
|
+
[loadTrackForPlayer]
|
|
1590
|
+
);
|
|
1591
|
+
const handlePreviousTrack = (0, import_react11.useCallback)(
|
|
1592
|
+
(trackList, currentTrack, onTrackChange) => {
|
|
1593
|
+
if (!trackList || !currentTrack) return;
|
|
1594
|
+
const currentIndex = trackList.findIndex((track) => track.id === currentTrack.id);
|
|
1595
|
+
if (currentIndex === -1) return;
|
|
1596
|
+
const previousTrack = trackList.slice(0, currentIndex).reverse().find(isPlayable);
|
|
1597
|
+
if (previousTrack) {
|
|
1598
|
+
onTrackChange(previousTrack);
|
|
1599
|
+
loadTrackForPlayer(previousTrack.id);
|
|
1600
|
+
}
|
|
1601
|
+
},
|
|
1602
|
+
[loadTrackForPlayer]
|
|
1603
|
+
);
|
|
1604
|
+
(0, import_react11.useEffect)(() => {
|
|
1605
|
+
return () => {
|
|
1606
|
+
if (audioElementRef.current) {
|
|
1607
|
+
audioElementRef.current.pause();
|
|
1608
|
+
audioElementRef.current = null;
|
|
1609
|
+
}
|
|
1610
|
+
if (youtubePlayerRef.current) {
|
|
1611
|
+
youtubePlayerRef.current.destroy();
|
|
1612
|
+
youtubePlayerRef.current = null;
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
}, []);
|
|
1616
|
+
const handlePlayPauseAction = (0, import_react11.useCallback)(() => {
|
|
1617
|
+
if (playState === "LOADING" /* LOADING */) return;
|
|
1618
|
+
if (!playerTrackObject?.isReady) return;
|
|
1619
|
+
const mediaController = playerTrackObject.mediaController;
|
|
1620
|
+
if (!mediaController) return;
|
|
1621
|
+
if (playState === "PLAYING" /* PLAYING */) {
|
|
1622
|
+
mediaController.pause();
|
|
1623
|
+
setPlayState("PAUSED" /* PAUSED */);
|
|
1624
|
+
setIsPlaying(false);
|
|
1625
|
+
} else {
|
|
1626
|
+
mediaController.play();
|
|
1627
|
+
setPlayState("PLAYING" /* PLAYING */);
|
|
1628
|
+
setIsPlaying(true);
|
|
1629
|
+
}
|
|
1630
|
+
}, [playerTrackObject?.isReady, playerTrackObject?.mediaController, playState]);
|
|
1631
|
+
const contextValue = (0, import_react11.useMemo)(
|
|
1632
|
+
() => ({
|
|
1633
|
+
playerTrackObject,
|
|
1634
|
+
isPlaying,
|
|
1635
|
+
setIsPlaying,
|
|
1636
|
+
currentTimeRef,
|
|
1637
|
+
duration,
|
|
1638
|
+
setDuration,
|
|
1639
|
+
volume,
|
|
1640
|
+
setVolume,
|
|
1641
|
+
playState,
|
|
1642
|
+
setPlayState,
|
|
1643
|
+
handlePlayPauseAction,
|
|
1644
|
+
loadTrackForPlayer,
|
|
1645
|
+
isLoading,
|
|
1646
|
+
handleNextTrack,
|
|
1647
|
+
handlePreviousTrack,
|
|
1648
|
+
onTrackEnd,
|
|
1649
|
+
setOnTrackEnd,
|
|
1650
|
+
videoContainerRef
|
|
1651
|
+
}),
|
|
1652
|
+
[
|
|
1653
|
+
playerTrackObject,
|
|
1654
|
+
isPlaying,
|
|
1655
|
+
duration,
|
|
1656
|
+
volume,
|
|
1657
|
+
playState,
|
|
1658
|
+
isLoading,
|
|
1659
|
+
handlePlayPauseAction,
|
|
1660
|
+
loadTrackForPlayer,
|
|
1661
|
+
handleNextTrack,
|
|
1662
|
+
handlePreviousTrack,
|
|
1663
|
+
onTrackEnd
|
|
1664
|
+
]
|
|
1665
|
+
);
|
|
1666
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PlayerContext.Provider, { value: contextValue, children });
|
|
1667
|
+
}
|
|
1668
|
+
function usePlayer() {
|
|
1669
|
+
const context = (0, import_react11.useContext)(PlayerContext);
|
|
1670
|
+
if (context === void 0) {
|
|
1671
|
+
throw new Error("usePlayer must be used within a PlayerProvider");
|
|
1672
|
+
}
|
|
1673
|
+
return context;
|
|
1674
|
+
}
|
|
1675
|
+
function PlayerVideoSurface({ className }) {
|
|
1676
|
+
const { videoContainerRef } = usePlayer();
|
|
1677
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { ref: videoContainerRef, className });
|
|
1678
|
+
}
|
|
1679
|
+
function useCurrentTime() {
|
|
1680
|
+
const { currentTimeRef } = usePlayer();
|
|
1681
|
+
const [currentTime, setCurrentTime] = (0, import_react11.useState)(0);
|
|
1682
|
+
(0, import_react11.useEffect)(() => {
|
|
1683
|
+
const interval = setInterval(() => {
|
|
1684
|
+
setCurrentTime(currentTimeRef.current);
|
|
1685
|
+
}, 100);
|
|
1686
|
+
return () => clearInterval(interval);
|
|
1687
|
+
}, [currentTimeRef]);
|
|
1688
|
+
return currentTime;
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
// src/genre-tree/useGenre.ts
|
|
1692
|
+
var import_zod22 = require("zod");
|
|
1693
|
+
var import_react_query5 = require("@tanstack/react-query");
|
|
1694
|
+
var import_react12 = require("react");
|
|
1695
|
+
|
|
1696
|
+
// src/genre-tree/useGenrePlaylist.ts
|
|
1697
|
+
var import_zod9 = require("zod");
|
|
1698
|
+
var import_react_query4 = require("@tanstack/react-query");
|
|
1699
|
+
|
|
1700
|
+
// src/genre-tree/schemas/criteria-playlist/simple.ts
|
|
1701
|
+
var import_zod8 = require("zod");
|
|
1702
|
+
|
|
1703
|
+
// src/genre-tree/schemas/criteria-playlist/detailed.ts
|
|
1704
|
+
var import_zod7 = require("zod");
|
|
1705
|
+
|
|
1706
|
+
// src/genre-tree/schemas/ids.ts
|
|
1707
|
+
var import_zod4 = require("zod");
|
|
1708
|
+
var GenreUuidSchema = import_zod4.z.string().uuid().brand();
|
|
1709
|
+
var GenrePlaylistUuidSchema = import_zod4.z.string().uuid().brand();
|
|
1710
|
+
|
|
1711
|
+
// src/genre-tree/schemas/criteria/minimum.ts
|
|
1712
|
+
var import_zod5 = require("zod");
|
|
1713
|
+
var CriteriaMinimumSchema = import_zod5.z.object({
|
|
1714
|
+
uuid: GenreUuidSchema,
|
|
1715
|
+
name: import_zod5.z.string(),
|
|
1716
|
+
side: import_zod5.z.enum(["core", "pop"]).nullable().optional(),
|
|
1717
|
+
wikidataId: import_zod5.z.string().nullable().optional()
|
|
1718
|
+
});
|
|
1719
|
+
|
|
1720
|
+
// src/genre-tree/schemas/criteria-playlist/minimum.ts
|
|
1721
|
+
var import_zod6 = require("zod");
|
|
1722
|
+
var CriteriaPlaylistMinimumSchema = import_zod6.z.object({
|
|
1723
|
+
uuid: GenrePlaylistUuidSchema,
|
|
1724
|
+
name: import_zod6.z.string()
|
|
1725
|
+
});
|
|
1726
|
+
|
|
1727
|
+
// src/genre-tree/schemas/criteria-playlist/detailed.ts
|
|
1728
|
+
var CriteriaPlaylistDetailedSchema = import_zod7.z.object({
|
|
1729
|
+
uuid: GenrePlaylistUuidSchema,
|
|
1730
|
+
name: import_zod7.z.string(),
|
|
1731
|
+
tracksCount: import_zod7.z.number(),
|
|
1732
|
+
// Summed YouTube views of the same songs as `tracksCount`.
|
|
1733
|
+
viewsCount: import_zod7.z.number(),
|
|
1734
|
+
durationInSec: import_zod7.z.number().min(0).nullable().optional(),
|
|
1735
|
+
durationStrInHourMinSec: import_zod7.z.string().nullable().optional(),
|
|
1736
|
+
// Nullable: the "Genreless" root playlist has no criteria attached and is never updated.
|
|
1737
|
+
criteria: CriteriaMinimumSchema.nullable(),
|
|
1738
|
+
parent: CriteriaPlaylistMinimumSchema.nullable(),
|
|
1739
|
+
root: CriteriaPlaylistMinimumSchema,
|
|
1740
|
+
createdOn: import_zod7.z.string(),
|
|
1741
|
+
updatedOn: import_zod7.z.string().nullable()
|
|
1742
|
+
});
|
|
1743
|
+
|
|
1744
|
+
// src/genre-tree/schemas/criteria-playlist/simple.ts
|
|
1745
|
+
var CriteriaPlaylistSimpleSchema = CriteriaPlaylistDetailedSchema.pick({
|
|
1746
|
+
uuid: true,
|
|
1747
|
+
name: true,
|
|
1748
|
+
criteria: true,
|
|
1749
|
+
parent: true,
|
|
1750
|
+
root: true,
|
|
1751
|
+
tracksCount: true,
|
|
1752
|
+
viewsCount: true,
|
|
1753
|
+
createdOn: true,
|
|
1754
|
+
updatedOn: true
|
|
1755
|
+
}).extend({
|
|
1756
|
+
// Only on the tree/list payloads, not the detail endpoint — hence not on the detailed schema.
|
|
1757
|
+
isUnacceptedRoot: import_zod8.z.boolean(),
|
|
1758
|
+
// Optional: a backend that does not curate umbrella genres omits it.
|
|
1759
|
+
isUmbrella: import_zod8.z.boolean().optional(),
|
|
1760
|
+
// Optional: only the grow tree payload carries it; null when the genre has no scene.
|
|
1761
|
+
scene: import_zod8.z.enum(["commercial", "underground"]).nullable().optional()
|
|
1762
|
+
});
|
|
1763
|
+
|
|
1764
|
+
// src/genre-tree/api/genre-playlists/queryKeys.ts
|
|
1765
|
+
var genrePlaylistQueryKeys = {
|
|
1766
|
+
me: {
|
|
1767
|
+
all: ["meGenrePlaylists"],
|
|
1768
|
+
list: (page) => ["meGenrePlaylists", "list", page],
|
|
1769
|
+
full: ["meGenrePlaylists", "full"],
|
|
1770
|
+
detail: (uuid) => ["meGenrePlaylists", uuid],
|
|
1771
|
+
tracks: (uuid) => ["meGenrePlaylists", uuid, "tracks"]
|
|
1772
|
+
},
|
|
1773
|
+
// "reference" scope is shared by any number of distinct backends (grow's own reference tree,
|
|
1774
|
+
// grow's read-only prototype/demo tree, etc.) that all use the same `scope: "reference"` value
|
|
1775
|
+
// but different `getBackendBaseUrl()` results — baseUrl is threaded into these keys so their
|
|
1776
|
+
// cache entries don't collide.
|
|
1777
|
+
reference: {
|
|
1778
|
+
all: ["referenceGenrePlaylists"],
|
|
1779
|
+
list: (baseUrl, page) => ["referenceGenrePlaylists", baseUrl, "list", page],
|
|
1780
|
+
full: (baseUrl) => ["referenceGenrePlaylists", baseUrl, "full"],
|
|
1781
|
+
detail: (baseUrl, uuid) => ["referenceGenrePlaylists", baseUrl, uuid]
|
|
1782
|
+
}
|
|
1783
|
+
};
|
|
1784
|
+
|
|
1785
|
+
// src/genre-tree/api/genre-playlists/endpoints.ts
|
|
1786
|
+
var makeGenrePlaylistEndpoints = (prefix) => ({
|
|
1787
|
+
list: () => `${prefix}genre-playlists/`,
|
|
1788
|
+
detail: (uuid) => `${prefix}genre-playlists/${uuid}/`,
|
|
1789
|
+
tracks: (uuid) => `${prefix}genre-playlists/${uuid}/tracks/`,
|
|
1790
|
+
create: () => `${prefix}genre-playlists/`,
|
|
1791
|
+
update: (uuid) => `${prefix}genre-playlists/${uuid}/`,
|
|
1792
|
+
delete: (uuid) => `${prefix}genre-playlists/${uuid}/`
|
|
1793
|
+
});
|
|
1794
|
+
var genrePlaylistEndpoints = {
|
|
1795
|
+
me: makeGenrePlaylistEndpoints("me/"),
|
|
1796
|
+
reference: { ...makeGenrePlaylistEndpoints(""), tree: () => "genre-playlists/tree/" }
|
|
1797
|
+
};
|
|
1798
|
+
|
|
1799
|
+
// src/genre-tree/api/library/songs/queryKeys.ts
|
|
1800
|
+
var makeSongQueryKeys = (prefix) => ({
|
|
1801
|
+
all: [`${prefix}Songs`],
|
|
1802
|
+
list: (page) => [`${prefix}Songs`, "list", page],
|
|
1803
|
+
detail: (uuid) => [`${prefix}Songs`, "detail", uuid],
|
|
1804
|
+
// baseUrl keeps distinct backends sharing a scope (e.g. grow and its prototype proxy) apart.
|
|
1805
|
+
byGenre: (baseUrl, genreUuid) => [`${prefix}Songs`, baseUrl, "genre", genreUuid]
|
|
1806
|
+
});
|
|
1807
|
+
|
|
1808
|
+
// src/genre-tree/api/library/songs/endpoints.ts
|
|
1809
|
+
var makeSongEndpoints = () => ({
|
|
1810
|
+
list: () => "library/songs/",
|
|
1811
|
+
detail: (uuid) => `library/songs/${uuid}/`,
|
|
1812
|
+
delete: (uuid) => `library/songs/${uuid}/`
|
|
1813
|
+
});
|
|
1814
|
+
|
|
1815
|
+
// src/genre-tree/api/library/index.ts
|
|
1816
|
+
var libraryQueryKeys = {
|
|
1817
|
+
reference: {
|
|
1818
|
+
songs: makeSongQueryKeys("reference")
|
|
1819
|
+
}
|
|
1820
|
+
};
|
|
1821
|
+
var libraryEndpoints = {
|
|
1822
|
+
reference: {
|
|
1823
|
+
songs: makeSongEndpoints()
|
|
1824
|
+
}
|
|
1825
|
+
};
|
|
1826
|
+
|
|
1827
|
+
// src/genre-tree/useGenrePlaylist.ts
|
|
1828
|
+
var FULL_LIST_PAGE_SIZE = 100;
|
|
1829
|
+
var FULL_LIST_CONCURRENCY = 4;
|
|
1830
|
+
var fetchAllPages = async (fetchPage) => {
|
|
1831
|
+
const fetchRequiredPage = async (page) => {
|
|
1832
|
+
const response = await fetchPage(page);
|
|
1833
|
+
if (response == null) throw new Error(`Paginated list page ${page} returned no body`);
|
|
1834
|
+
return response;
|
|
1835
|
+
};
|
|
1836
|
+
const first = await fetchRequiredPage(1);
|
|
1837
|
+
const remaining = Math.max(first.totalPages - 1, 0);
|
|
1838
|
+
const rest = new Array(remaining);
|
|
1839
|
+
let nextIndex = 0;
|
|
1840
|
+
await Promise.all(
|
|
1841
|
+
Array.from({ length: Math.min(FULL_LIST_CONCURRENCY, remaining) }, async () => {
|
|
1842
|
+
while (nextIndex < remaining) {
|
|
1843
|
+
const index = nextIndex++;
|
|
1844
|
+
rest[index] = await fetchRequiredPage(index + 2);
|
|
1845
|
+
}
|
|
1846
|
+
})
|
|
1847
|
+
);
|
|
1848
|
+
return [first, ...rest].flatMap((response) => response.results);
|
|
1849
|
+
};
|
|
1850
|
+
var useListGenrePlaylists = (page = 1, pageSize = 50, getBackendBaseUrl) => {
|
|
1851
|
+
const queryClient2 = (0, import_react_query4.useQueryClient)();
|
|
1852
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
1853
|
+
const { session, sessionRestored } = useSession();
|
|
1854
|
+
const query = useQueryWithParse({
|
|
1855
|
+
queryKey: genrePlaylistQueryKeys.me.list(page),
|
|
1856
|
+
queryFn: () => fetch2(genrePlaylistEndpoints.me.list(), true, true, {}, { page, pageSize }),
|
|
1857
|
+
schema: PaginatedResponseSchema(CriteriaPlaylistSimpleSchema),
|
|
1858
|
+
context: "useListGenrePlaylists",
|
|
1859
|
+
enabled: sessionRestored && !!session?.accessToken
|
|
1860
|
+
});
|
|
1861
|
+
const invalidateGenrePlaylists = () => {
|
|
1862
|
+
queryClient2.invalidateQueries({ queryKey: genrePlaylistQueryKeys.me.all });
|
|
1863
|
+
};
|
|
1864
|
+
return {
|
|
1865
|
+
...query,
|
|
1866
|
+
invalidateGenrePlaylists
|
|
1867
|
+
};
|
|
1868
|
+
};
|
|
1869
|
+
var useListFullGenrePlaylists = (scope, getBackendBaseUrl) => {
|
|
1870
|
+
const queryClient2 = (0, import_react_query4.useQueryClient)();
|
|
1871
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
1872
|
+
const { session, sessionRestored } = useSession();
|
|
1873
|
+
const queryKey = scope === "reference" ? genrePlaylistQueryKeys.reference.full(getBackendBaseUrl()) : genrePlaylistQueryKeys.me.full;
|
|
1874
|
+
const query = useQueryWithParse({
|
|
1875
|
+
queryKey,
|
|
1876
|
+
queryFn: () => scope === "reference" ? fetch2(genrePlaylistEndpoints.reference.tree(), true, false, {}, { treeName: "canonical" }) : fetchAllPages(
|
|
1877
|
+
(page) => fetch2(
|
|
1878
|
+
genrePlaylistEndpoints.me.list(),
|
|
1879
|
+
true,
|
|
1880
|
+
true,
|
|
1881
|
+
{},
|
|
1882
|
+
{ page, pageSize: FULL_LIST_PAGE_SIZE, treeName: "canonical" }
|
|
1883
|
+
)
|
|
1884
|
+
),
|
|
1885
|
+
schema: import_zod9.z.array(CriteriaPlaylistSimpleSchema),
|
|
1886
|
+
context: "useListFullGenrePlaylists",
|
|
1887
|
+
enabled: scope === "reference" || sessionRestored && !!session?.accessToken
|
|
1888
|
+
});
|
|
1889
|
+
const invalidateFullGenrePlaylists = () => {
|
|
1890
|
+
queryClient2.invalidateQueries({ queryKey });
|
|
1891
|
+
};
|
|
1892
|
+
return {
|
|
1893
|
+
...query,
|
|
1894
|
+
invalidateFullGenrePlaylists
|
|
1895
|
+
};
|
|
1896
|
+
};
|
|
1897
|
+
var useFetchGenrePlaylist = (uuid, getBackendBaseUrl, criteriaPlaylistDetailedSchema) => {
|
|
1898
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
1899
|
+
const { session, sessionRestored } = useSession();
|
|
1900
|
+
return useQueryWithParse({
|
|
1901
|
+
queryKey: genrePlaylistQueryKeys.me.detail(uuid),
|
|
1902
|
+
queryFn: () => fetch2(genrePlaylistEndpoints.me.detail(uuid)),
|
|
1903
|
+
schema: criteriaPlaylistDetailedSchema,
|
|
1904
|
+
context: "useFetchGenrePlaylist",
|
|
1905
|
+
enabled: !!uuid && sessionRestored && !!session?.accessToken
|
|
1906
|
+
});
|
|
1907
|
+
};
|
|
1908
|
+
var useInvalidateAllGenrePlaylistQueries = () => {
|
|
1909
|
+
const queryClient2 = (0, import_react_query4.useQueryClient)();
|
|
1910
|
+
return () => Promise.all([
|
|
1911
|
+
queryClient2.invalidateQueries({ queryKey: genrePlaylistQueryKeys.me.all }),
|
|
1912
|
+
queryClient2.invalidateQueries({ queryKey: genrePlaylistQueryKeys.me.full }),
|
|
1913
|
+
queryClient2.invalidateQueries({ queryKey: genrePlaylistQueryKeys.reference.all }),
|
|
1914
|
+
queryClient2.invalidateQueries({ queryKey: libraryQueryKeys.reference.songs.all })
|
|
1915
|
+
]);
|
|
1916
|
+
};
|
|
1917
|
+
|
|
1918
|
+
// src/genre-tree/schemas/criteria/detailed.ts
|
|
1919
|
+
var import_zod16 = require("zod");
|
|
1920
|
+
|
|
1921
|
+
// src/genre-tree/schemas/track/base.ts
|
|
1922
|
+
var import_zod13 = require("zod");
|
|
1923
|
+
|
|
1924
|
+
// src/genre-tree/schemas/artist-minimum.ts
|
|
1925
|
+
var import_zod10 = require("zod");
|
|
1926
|
+
var ArtistMinimumSchema = import_zod10.z.object({
|
|
1927
|
+
uuid: import_zod10.z.string().uuid(),
|
|
1928
|
+
name: import_zod10.z.string(),
|
|
1929
|
+
isSpecialPurpose: import_zod10.z.boolean().optional()
|
|
1930
|
+
});
|
|
1931
|
+
|
|
1932
|
+
// src/genre-tree/schemas/album-minimum.ts
|
|
1933
|
+
var import_zod11 = require("zod");
|
|
1934
|
+
var AlbumMinimumSchema = import_zod11.z.object({
|
|
1935
|
+
uuid: import_zod11.z.string().uuid(),
|
|
1936
|
+
name: import_zod11.z.string(),
|
|
1937
|
+
albumArtists: import_zod11.z.array(ArtistMinimumSchema).nullable().optional()
|
|
1938
|
+
});
|
|
1939
|
+
|
|
1940
|
+
// src/genre-tree/schemas/uuid-resource.ts
|
|
1941
|
+
var import_zod12 = require("zod");
|
|
1942
|
+
var UuidResourceSchema = import_zod12.z.object({
|
|
1943
|
+
uuid: import_zod12.z.string().uuid()
|
|
1944
|
+
});
|
|
1945
|
+
|
|
1946
|
+
// src/genre-tree/schemas/track/base.ts
|
|
1947
|
+
var TrackBaseSchema = UuidResourceSchema.extend({
|
|
1948
|
+
title: import_zod13.z.string(),
|
|
1949
|
+
artists: import_zod13.z.array(ArtistMinimumSchema).nullable().optional(),
|
|
1950
|
+
album: AlbumMinimumSchema.nullable().optional(),
|
|
1951
|
+
trackNumber: import_zod13.z.number().nullable().optional(),
|
|
1952
|
+
genre: CriteriaMinimumSchema,
|
|
1953
|
+
rating: import_zod13.z.number().min(0).max(10).nullable().optional(),
|
|
1954
|
+
language: import_zod13.z.string().nullable().optional(),
|
|
1955
|
+
playCount: import_zod13.z.number().min(0),
|
|
1956
|
+
createdOn: import_zod13.z.string().datetime(),
|
|
1957
|
+
updatedOn: import_zod13.z.string().datetime().nullable().optional()
|
|
1958
|
+
});
|
|
1959
|
+
|
|
1960
|
+
// src/genre-tree/schemas/track/minimum.ts
|
|
1961
|
+
var TrackMinimumSchema = TrackBaseSchema.pick({
|
|
1962
|
+
uuid: true,
|
|
1963
|
+
title: true,
|
|
1964
|
+
artists: true
|
|
1965
|
+
});
|
|
1966
|
+
|
|
1967
|
+
// src/genre-tree/schemas/criteria/lineage-rel/without-ascendant.ts
|
|
1968
|
+
var import_zod14 = require("zod");
|
|
1969
|
+
var CriteriaLineageRelWithoutAscendantSchema = import_zod14.z.object({
|
|
1970
|
+
descendant: CriteriaMinimumSchema,
|
|
1971
|
+
degree: import_zod14.z.number()
|
|
1972
|
+
});
|
|
1973
|
+
|
|
1974
|
+
// src/genre-tree/schemas/criteria/lineage-rel/without-descendant.ts
|
|
1975
|
+
var import_zod15 = require("zod");
|
|
1976
|
+
var CriteriaLineageRelWithoutDescendantSchema = import_zod15.z.object({
|
|
1977
|
+
ascendant: CriteriaMinimumSchema,
|
|
1978
|
+
degree: import_zod15.z.number()
|
|
1979
|
+
});
|
|
1980
|
+
|
|
1981
|
+
// src/genre-tree/schemas/criteria/detailed.ts
|
|
1982
|
+
var CriteriaDetailedSchema = import_zod16.z.object({
|
|
1983
|
+
uuid: GenreUuidSchema,
|
|
1984
|
+
name: import_zod16.z.string(),
|
|
1985
|
+
summary: import_zod16.z.string().nullable(),
|
|
1986
|
+
parent: CriteriaMinimumSchema.nullable(),
|
|
1987
|
+
ascendants: import_zod16.z.array(CriteriaLineageRelWithoutDescendantSchema),
|
|
1988
|
+
descendants: import_zod16.z.array(CriteriaLineageRelWithoutAscendantSchema),
|
|
1989
|
+
root: CriteriaMinimumSchema,
|
|
1990
|
+
children: import_zod16.z.array(CriteriaMinimumSchema),
|
|
1991
|
+
criteriaPlaylist: CriteriaPlaylistMinimumSchema,
|
|
1992
|
+
tracks: import_zod16.z.array(TrackMinimumSchema),
|
|
1993
|
+
essentialSongs: import_zod16.z.array(TrackMinimumSchema),
|
|
1994
|
+
tracksCount: import_zod16.z.number(),
|
|
1995
|
+
updatedOn: import_zod16.z.string().datetime().nullable()
|
|
1996
|
+
});
|
|
1997
|
+
|
|
1998
|
+
// src/genre-tree/schemas/criteria/overview.ts
|
|
1999
|
+
var import_zod18 = require("zod");
|
|
2000
|
+
|
|
2001
|
+
// src/genre-tree/schemas/http-url.ts
|
|
2002
|
+
var import_zod17 = require("zod");
|
|
2003
|
+
var HttpUrlSchema = import_zod17.z.url({ protocol: /^https?$/ });
|
|
2004
|
+
|
|
2005
|
+
// src/genre-tree/schemas/criteria/overview.ts
|
|
2006
|
+
var CriteriaOverviewSchema = import_zod18.z.object({
|
|
2007
|
+
uuid: GenreUuidSchema,
|
|
2008
|
+
name: import_zod18.z.string(),
|
|
2009
|
+
summary: import_zod18.z.string().nullable(),
|
|
2010
|
+
description: import_zod18.z.string().nullable(),
|
|
2011
|
+
summarySourceUrl: HttpUrlSchema.nullable(),
|
|
2012
|
+
essentialSongs: import_zod18.z.array(TrackMinimumSchema).optional()
|
|
2013
|
+
});
|
|
2014
|
+
|
|
2015
|
+
// src/genre-tree/schemas/criteria/simple.ts
|
|
2016
|
+
var import_zod19 = require("zod");
|
|
2017
|
+
var CriteriaSimpleSchema = import_zod19.z.object({
|
|
2018
|
+
uuid: GenreUuidSchema,
|
|
2019
|
+
name: import_zod19.z.string(),
|
|
2020
|
+
parent: CriteriaMinimumSchema.nullable(),
|
|
2021
|
+
createdOn: import_zod19.z.string().datetime(),
|
|
2022
|
+
summary: import_zod19.z.string().nullable()
|
|
2023
|
+
});
|
|
2024
|
+
|
|
2025
|
+
// src/genre-tree/schemas/criteria/creation.ts
|
|
2026
|
+
var import_zod20 = require("zod");
|
|
2027
|
+
var CriteriaCreationSchema = import_zod20.z.object({
|
|
2028
|
+
name: import_zod20.z.string().min(1, "Name is required"),
|
|
2029
|
+
parent: GenreUuidSchema.optional(),
|
|
2030
|
+
essentialSongs: import_zod20.z.array(import_zod20.z.string().uuid()).optional()
|
|
2031
|
+
});
|
|
2032
|
+
|
|
2033
|
+
// src/genre-tree/schemas/criteria/update.ts
|
|
2034
|
+
var import_zod21 = require("zod");
|
|
2035
|
+
var CriteriaUpdateSchema = import_zod21.z.object({
|
|
2036
|
+
name: import_zod21.z.string().optional(),
|
|
2037
|
+
parent: GenreUuidSchema.nullable().optional(),
|
|
2038
|
+
essentialSongs: import_zod21.z.array(import_zod21.z.string().uuid()).optional()
|
|
2039
|
+
});
|
|
2040
|
+
|
|
2041
|
+
// src/genre-tree/api/genres/queryKeys.ts
|
|
2042
|
+
var genreQueryKeys = {
|
|
2043
|
+
me: {
|
|
2044
|
+
all: ["genres"],
|
|
2045
|
+
list: (page) => ["genres", "list", page],
|
|
2046
|
+
detail: (id) => ["genres", "detail", id],
|
|
2047
|
+
overview: (id) => ["genres", "overview", id]
|
|
2048
|
+
},
|
|
2049
|
+
reference: {
|
|
2050
|
+
all: ["referenceGenres"],
|
|
2051
|
+
list: (page) => ["referenceGenres", "list", page],
|
|
2052
|
+
detail: (id) => ["referenceGenres", "detail", id],
|
|
2053
|
+
overview: (id) => ["referenceGenres", "overview", id]
|
|
2054
|
+
}
|
|
2055
|
+
};
|
|
2056
|
+
var genreUpdateMutationKey = ["genres", "update"];
|
|
2057
|
+
|
|
2058
|
+
// src/genre-tree/api/genres/endpoints.ts
|
|
2059
|
+
var makeGenreEndpoints = (prefix) => ({
|
|
2060
|
+
list: () => `${prefix}genres/`,
|
|
2061
|
+
detail: (id) => `${prefix}genres/${id}/`,
|
|
2062
|
+
overview: (id) => `${prefix}genres/${id}/overview/`,
|
|
2063
|
+
create: () => `${prefix}genres/`,
|
|
2064
|
+
update: (id) => `${prefix}genres/${id}/`,
|
|
2065
|
+
delete: (id) => `${prefix}genres/${id}/`
|
|
2066
|
+
});
|
|
2067
|
+
var genreEndpoints = {
|
|
2068
|
+
me: makeGenreEndpoints("me/"),
|
|
2069
|
+
reference: makeGenreEndpoints("")
|
|
2070
|
+
};
|
|
2071
|
+
|
|
2072
|
+
// src/genre-tree/useGenre.ts
|
|
2073
|
+
function useListGenres(page = 1, pageSize = 50, scope, getBackendBaseUrl) {
|
|
2074
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2075
|
+
const { session, sessionRestored } = useSession();
|
|
2076
|
+
const endpoint = scope === "reference" ? genreEndpoints.reference.list() : genreEndpoints.me.list();
|
|
2077
|
+
return useQueryWithParse({
|
|
2078
|
+
queryKey: scope === "reference" ? genreQueryKeys.reference.list(page) : genreQueryKeys.me.list(page),
|
|
2079
|
+
queryFn: () => fetch2(endpoint, true, scope === "me", {}, { page, pageSize }),
|
|
2080
|
+
schema: PaginatedResponseSchema(CriteriaSimpleSchema),
|
|
2081
|
+
context: "useListGenres",
|
|
2082
|
+
enabled: scope === "reference" || sessionRestored && !!session?.accessToken
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
function useFetchGenre(scope, getBackendBaseUrl) {
|
|
2086
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2087
|
+
return (0, import_react12.useCallback)(
|
|
2088
|
+
async (id) => {
|
|
2089
|
+
const endpoint = scope === "reference" ? genreEndpoints.reference.detail(id) : genreEndpoints.me.detail(id);
|
|
2090
|
+
const response = await fetch2(endpoint, true, scope === "me");
|
|
2091
|
+
return parseWithLog(CriteriaDetailedSchema, response, "useFetchGenre");
|
|
2092
|
+
},
|
|
2093
|
+
[fetch2, scope]
|
|
2094
|
+
);
|
|
2095
|
+
}
|
|
2096
|
+
function useFetchGenreDetail(id, scope, getBackendBaseUrl, schema = CriteriaDetailedSchema) {
|
|
2097
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2098
|
+
const queryKeys = scope === "reference" ? genreQueryKeys.reference : genreQueryKeys.me;
|
|
2099
|
+
const endpoints = scope === "reference" ? genreEndpoints.reference : genreEndpoints.me;
|
|
2100
|
+
const genreUuid = id ?? "";
|
|
2101
|
+
return useQueryWithParse({
|
|
2102
|
+
queryKey: queryKeys.detail(genreUuid),
|
|
2103
|
+
queryFn: () => fetch2(endpoints.detail(genreUuid), true, scope === "me"),
|
|
2104
|
+
schema,
|
|
2105
|
+
context: "useFetchGenreDetail",
|
|
2106
|
+
enabled: id !== null
|
|
2107
|
+
});
|
|
2108
|
+
}
|
|
2109
|
+
var GENRE_OVERVIEW_STALE_TIME_MS = 6e4;
|
|
2110
|
+
function useGenreOverviewQueryOptions(scope, getBackendBaseUrl, schema) {
|
|
2111
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2112
|
+
return (0, import_react12.useCallback)(
|
|
2113
|
+
(id) => {
|
|
2114
|
+
const queryKeys = scope === "reference" ? genreQueryKeys.reference : genreQueryKeys.me;
|
|
2115
|
+
const endpoints = scope === "reference" ? genreEndpoints.reference : genreEndpoints.me;
|
|
2116
|
+
return {
|
|
2117
|
+
queryKey: queryKeys.overview(id),
|
|
2118
|
+
queryFn: async () => parseWithLog(schema, await fetch2(endpoints.overview(id), true, scope === "me"), "useFetchGenreOverview"),
|
|
2119
|
+
staleTime: GENRE_OVERVIEW_STALE_TIME_MS
|
|
2120
|
+
};
|
|
2121
|
+
},
|
|
2122
|
+
[fetch2, scope, schema]
|
|
2123
|
+
);
|
|
2124
|
+
}
|
|
2125
|
+
function useFetchGenreOverview(id, scope, getBackendBaseUrl, schema = CriteriaOverviewSchema) {
|
|
2126
|
+
const queryOptions = useGenreOverviewQueryOptions(scope, getBackendBaseUrl, schema);
|
|
2127
|
+
return (0, import_react_query5.useQuery)({ ...queryOptions(id ?? ""), enabled: id !== null });
|
|
2128
|
+
}
|
|
2129
|
+
function usePrefetchGenreOverview(scope, getBackendBaseUrl, schema = CriteriaOverviewSchema) {
|
|
2130
|
+
const queryClient2 = (0, import_react_query5.useQueryClient)();
|
|
2131
|
+
const queryOptions = useGenreOverviewQueryOptions(scope, getBackendBaseUrl, schema);
|
|
2132
|
+
return (0, import_react12.useCallback)((id) => queryClient2.prefetchQuery(queryOptions(id)), [queryClient2, queryOptions]);
|
|
2133
|
+
}
|
|
2134
|
+
function useRefreshGenreTree(scope) {
|
|
2135
|
+
const queryClient2 = (0, import_react_query5.useQueryClient)();
|
|
2136
|
+
const invalidateAllGenrePlaylistQueries = useInvalidateAllGenrePlaylistQueries();
|
|
2137
|
+
return ({ changedUuid, deletedUuid } = {}) => {
|
|
2138
|
+
const queryKeys = scope === "reference" ? genreQueryKeys.reference : genreQueryKeys.me;
|
|
2139
|
+
if (deletedUuid) {
|
|
2140
|
+
queryClient2.removeQueries({ queryKey: queryKeys.detail(deletedUuid) });
|
|
2141
|
+
queryClient2.removeQueries({ queryKey: queryKeys.overview(deletedUuid) });
|
|
2142
|
+
}
|
|
2143
|
+
return Promise.all([
|
|
2144
|
+
queryClient2.invalidateQueries({ queryKey: queryKeys.all }),
|
|
2145
|
+
...changedUuid ? [queryClient2.invalidateQueries({ queryKey: queryKeys.detail(changedUuid) })] : [],
|
|
2146
|
+
invalidateAllGenrePlaylistQueries()
|
|
2147
|
+
]);
|
|
2148
|
+
};
|
|
2149
|
+
}
|
|
2150
|
+
function useCreateGenre(scope, getBackendBaseUrl) {
|
|
2151
|
+
const refreshGenreTree = useRefreshGenreTree(scope);
|
|
2152
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2153
|
+
return useValidatedMutation({
|
|
2154
|
+
inputSchema: CriteriaCreationSchema,
|
|
2155
|
+
outputSchema: CriteriaDetailedSchema,
|
|
2156
|
+
mutationFn: async (data) => {
|
|
2157
|
+
const endpoint = scope === "reference" ? genreEndpoints.reference.create() : genreEndpoints.me.create();
|
|
2158
|
+
const response = await fetch2(endpoint, true, scope === "me", {
|
|
2159
|
+
method: "POST",
|
|
2160
|
+
body: JSON.stringify(data)
|
|
2161
|
+
});
|
|
2162
|
+
return response;
|
|
2163
|
+
},
|
|
2164
|
+
onSuccess: () => refreshGenreTree()
|
|
2165
|
+
});
|
|
2166
|
+
}
|
|
2167
|
+
function useUpdateGenre(scope, getBackendBaseUrl) {
|
|
2168
|
+
const refreshGenreTree = useRefreshGenreTree(scope);
|
|
2169
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2170
|
+
const { mutate, mutateAsync, isPending, formErrors } = useValidatedMutation({
|
|
2171
|
+
inputSchema: import_zod22.z.object({
|
|
2172
|
+
uuid: GenreUuidSchema,
|
|
2173
|
+
data: CriteriaUpdateSchema
|
|
2174
|
+
}),
|
|
2175
|
+
outputSchema: CriteriaDetailedSchema,
|
|
2176
|
+
mutationFn: async ({ uuid, data }) => {
|
|
2177
|
+
const endpoint = scope === "reference" ? genreEndpoints.reference.update(uuid) : genreEndpoints.me.update(uuid);
|
|
2178
|
+
const response = await fetch2(endpoint, true, scope === "me", {
|
|
2179
|
+
method: "PUT",
|
|
2180
|
+
body: JSON.stringify(data)
|
|
2181
|
+
});
|
|
2182
|
+
return response;
|
|
2183
|
+
},
|
|
2184
|
+
mutationKey: genreUpdateMutationKey,
|
|
2185
|
+
onSuccess: (_, { uuid }) => {
|
|
2186
|
+
void refreshGenreTree({ changedUuid: uuid });
|
|
2187
|
+
}
|
|
2188
|
+
});
|
|
2189
|
+
const renameGenre = (uuid, name) => {
|
|
2190
|
+
mutate({ uuid, data: { name } });
|
|
2191
|
+
};
|
|
2192
|
+
const updateGenreParent = async (uuid, parentUuid) => {
|
|
2193
|
+
await mutateAsync({ uuid, data: { parent: parentUuid } });
|
|
2194
|
+
};
|
|
2195
|
+
return { mutate, renameGenre, updateGenreParent, isPending, formErrors };
|
|
2196
|
+
}
|
|
2197
|
+
function useDeleteGenre(scope, getBackendBaseUrl) {
|
|
2198
|
+
const refreshGenreTree = useRefreshGenreTree(scope);
|
|
2199
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2200
|
+
return useValidatedMutation({
|
|
2201
|
+
inputSchema: import_zod22.z.object({ uuid: GenreUuidSchema }),
|
|
2202
|
+
outputSchema: import_zod22.z.null(),
|
|
2203
|
+
mutationFn: async ({ uuid }) => {
|
|
2204
|
+
const endpoint = scope === "reference" ? genreEndpoints.reference.delete(uuid) : genreEndpoints.me.delete(uuid);
|
|
2205
|
+
return fetch2(endpoint, true, scope === "me", { method: "DELETE" }, void 0, false, true);
|
|
2206
|
+
},
|
|
2207
|
+
onSuccess: (_, { uuid }) => refreshGenreTree({ deletedUuid: uuid })
|
|
2208
|
+
});
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
// src/genre-tree/useArtist.ts
|
|
2212
|
+
var import_zod24 = require("zod");
|
|
2213
|
+
|
|
2214
|
+
// src/genre-tree/schemas/artist-detailed.ts
|
|
2215
|
+
var import_zod23 = require("zod");
|
|
2216
|
+
var ArtistMembershipSchema = import_zod23.z.object({
|
|
2217
|
+
artist: ArtistMinimumSchema,
|
|
2218
|
+
beginYear: import_zod23.z.number().int().nullable(),
|
|
2219
|
+
endYear: import_zod23.z.number().int().nullable(),
|
|
2220
|
+
ended: import_zod23.z.boolean(),
|
|
2221
|
+
roles: import_zod23.z.array(import_zod23.z.string())
|
|
2222
|
+
});
|
|
2223
|
+
var ARTIST_LINK_KINDS = [
|
|
2224
|
+
"official",
|
|
2225
|
+
"wikipedia",
|
|
2226
|
+
"wikidata",
|
|
2227
|
+
"spotify",
|
|
2228
|
+
"youtube",
|
|
2229
|
+
"bandcamp",
|
|
2230
|
+
"soundcloud",
|
|
2231
|
+
"discogs",
|
|
2232
|
+
"social"
|
|
2233
|
+
];
|
|
2234
|
+
var ArtistImageSchema = import_zod23.z.object({
|
|
2235
|
+
url: HttpUrlSchema,
|
|
2236
|
+
pageUrl: HttpUrlSchema,
|
|
2237
|
+
author: import_zod23.z.string().nullable(),
|
|
2238
|
+
license: import_zod23.z.string(),
|
|
2239
|
+
licenseUrl: HttpUrlSchema.nullable()
|
|
2240
|
+
});
|
|
2241
|
+
var ArtistDetailedSchema = import_zod23.z.object({
|
|
2242
|
+
uuid: import_zod23.z.string().uuid(),
|
|
2243
|
+
name: import_zod23.z.string(),
|
|
2244
|
+
musicbrainzArtistId: import_zod23.z.string().uuid().nullable(),
|
|
2245
|
+
type: import_zod23.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
|
|
2246
|
+
country: import_zod23.z.string().nullable(),
|
|
2247
|
+
beginYear: import_zod23.z.number().int().nullable(),
|
|
2248
|
+
endYear: import_zod23.z.number().int().nullable(),
|
|
2249
|
+
ended: import_zod23.z.boolean(),
|
|
2250
|
+
links: import_zod23.z.array(import_zod23.z.object({ kind: import_zod23.z.enum(ARTIST_LINK_KINDS), url: HttpUrlSchema })),
|
|
2251
|
+
members: import_zod23.z.array(ArtistMembershipSchema),
|
|
2252
|
+
memberOf: import_zod23.z.array(ArtistMembershipSchema),
|
|
2253
|
+
albums: import_zod23.z.array(
|
|
2254
|
+
import_zod23.z.object({
|
|
2255
|
+
uuid: import_zod23.z.string().uuid(),
|
|
2256
|
+
name: import_zod23.z.string(),
|
|
2257
|
+
year: import_zod23.z.string().nullable(),
|
|
2258
|
+
primaryType: import_zod23.z.string().nullable(),
|
|
2259
|
+
secondaryTypes: import_zod23.z.array(import_zod23.z.string())
|
|
2260
|
+
})
|
|
2261
|
+
),
|
|
2262
|
+
tracksCount: import_zod23.z.number().int(),
|
|
2263
|
+
image: ArtistImageSchema.nullable()
|
|
2264
|
+
});
|
|
2265
|
+
|
|
2266
|
+
// src/genre-tree/api/artists/queryKeys.ts
|
|
2267
|
+
var artistQueryKeys = {
|
|
2268
|
+
search: (query) => ["artistSearch", query],
|
|
2269
|
+
detail: (uuid) => ["artist", uuid],
|
|
2270
|
+
// baseUrl keeps distinct backends sharing a scope apart.
|
|
2271
|
+
genreCounts: (baseUrl, uuid) => ["artistGenreCounts", baseUrl, uuid]
|
|
2272
|
+
};
|
|
2273
|
+
|
|
2274
|
+
// src/genre-tree/api/artists/endpoints.ts
|
|
2275
|
+
var artistEndpoints = {
|
|
2276
|
+
search: () => "artists/search/",
|
|
2277
|
+
detail: (uuid) => `artists/${uuid}/`,
|
|
2278
|
+
genreCounts: (uuid) => `artists/${uuid}/genre-counts/`
|
|
2279
|
+
};
|
|
2280
|
+
|
|
2281
|
+
// src/genre-tree/useArtist.ts
|
|
2282
|
+
var isNotFound = (error) => error instanceof AppError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */;
|
|
2283
|
+
function useArtist(uuid, getBackendBaseUrl) {
|
|
2284
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2285
|
+
const isUuid = uuid !== null && import_zod24.z.string().uuid().safeParse(uuid).success;
|
|
2286
|
+
const { data, isPending, error } = useQueryWithParse({
|
|
2287
|
+
queryKey: artistQueryKeys.detail(uuid),
|
|
2288
|
+
// A missing artist is shown in the panel, not raised as an app-wide connectivity error.
|
|
2289
|
+
queryFn: () => fetch2(artistEndpoints.detail(uuid), true, false, void 0, void 0, false, true),
|
|
2290
|
+
schema: ArtistDetailedSchema,
|
|
2291
|
+
enabled: isUuid,
|
|
2292
|
+
retry: (failureCount, retryError) => !isNotFound(retryError) && failureCount < 3,
|
|
2293
|
+
context: "useArtist"
|
|
2294
|
+
});
|
|
2295
|
+
if (uuid === null) return { status: "idle" };
|
|
2296
|
+
if (!isUuid || isNotFound(error)) return { status: "not-found" };
|
|
2297
|
+
if (error) return { status: "error" };
|
|
2298
|
+
if (isPending) return { status: "loading" };
|
|
2299
|
+
return { status: "success", artist: data };
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2302
|
+
// src/genre-tree/useArtistSearch.ts
|
|
2303
|
+
var import_react_query6 = require("@tanstack/react-query");
|
|
2304
|
+
var import_react13 = require("react");
|
|
2305
|
+
|
|
2306
|
+
// src/genre-tree/schemas/artist-search.ts
|
|
2307
|
+
var import_zod25 = require("zod");
|
|
2308
|
+
var ArtistSearchResultSchema = import_zod25.z.object({
|
|
2309
|
+
uuid: import_zod25.z.string().uuid(),
|
|
2310
|
+
name: import_zod25.z.string(),
|
|
2311
|
+
disambiguation: import_zod25.z.string().nullable(),
|
|
2312
|
+
type: import_zod25.z.enum(["person", "group", "orchestra", "choir", "character", "other"]).nullable(),
|
|
2313
|
+
country: import_zod25.z.string().nullable(),
|
|
2314
|
+
beginYear: import_zod25.z.number().int().nullable(),
|
|
2315
|
+
endYear: import_zod25.z.number().int().nullable(),
|
|
2316
|
+
matchedAlias: import_zod25.z.string().nullable(),
|
|
2317
|
+
recordingCount: import_zod25.z.number().int()
|
|
2318
|
+
});
|
|
2319
|
+
var ArtistSearchResultsSchema = import_zod25.z.array(ArtistSearchResultSchema);
|
|
2320
|
+
|
|
2321
|
+
// src/genre-tree/useArtistSearch.ts
|
|
2322
|
+
var DEBOUNCE_MS = 250;
|
|
2323
|
+
var MIN_QUERY_LENGTH = 2;
|
|
2324
|
+
var RESULT_LIMIT = 8;
|
|
2325
|
+
function useArtistSearch(getBackendBaseUrl, text) {
|
|
2326
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2327
|
+
const trimmed = text.trim();
|
|
2328
|
+
const [query, setQuery] = (0, import_react13.useState)("");
|
|
2329
|
+
(0, import_react13.useEffect)(() => {
|
|
2330
|
+
const timer = setTimeout(() => setQuery(trimmed), DEBOUNCE_MS);
|
|
2331
|
+
return () => clearTimeout(timer);
|
|
2332
|
+
}, [trimmed]);
|
|
2333
|
+
const enabled = query.length >= MIN_QUERY_LENGTH;
|
|
2334
|
+
const { data, isFetching, isError } = useQueryWithParse({
|
|
2335
|
+
queryKey: artistQueryKeys.search(query),
|
|
2336
|
+
queryFn: () => fetch2(artistEndpoints.search(), true, false, {}, { q: query, limit: RESULT_LIMIT }),
|
|
2337
|
+
schema: ArtistSearchResultsSchema,
|
|
2338
|
+
context: "useArtistSearch",
|
|
2339
|
+
enabled,
|
|
2340
|
+
placeholderData: import_react_query6.keepPreviousData
|
|
2341
|
+
});
|
|
2342
|
+
const settled = enabled && !isFetching && query === trimmed;
|
|
2343
|
+
const failed = enabled && isError;
|
|
2344
|
+
return {
|
|
2345
|
+
artists: trimmed.length >= MIN_QUERY_LENGTH ? data ?? [] : [],
|
|
2346
|
+
isError: failed,
|
|
2347
|
+
settled,
|
|
2348
|
+
pending: trimmed.length >= MIN_QUERY_LENGTH && !settled && !failed
|
|
2349
|
+
};
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2352
|
+
// src/genre-tree/useArtistGenreCounts.ts
|
|
2353
|
+
var import_react_query7 = require("@tanstack/react-query");
|
|
2354
|
+
var import_zod27 = require("zod");
|
|
2355
|
+
|
|
2356
|
+
// src/genre-tree/schemas/artist-genre-count.ts
|
|
2357
|
+
var import_zod26 = require("zod");
|
|
2358
|
+
var ArtistGenreCountSchema = import_zod26.z.object({
|
|
2359
|
+
genrePlaylist: GenrePlaylistUuidSchema,
|
|
2360
|
+
/** All the artist's songs in the genre playlist's subtree; drives pruning. */
|
|
2361
|
+
songsCount: import_zod26.z.number().int().nonnegative(),
|
|
2362
|
+
/** The playable ones among them; drives node size and the play button. */
|
|
2363
|
+
tracksCount: import_zod26.z.number().int().nonnegative()
|
|
2364
|
+
});
|
|
2365
|
+
|
|
2366
|
+
// src/genre-tree/useArtistGenreCounts.ts
|
|
2367
|
+
var isNotFound2 = (error) => error instanceof AppError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */;
|
|
2368
|
+
function useArtistGenreCounts(artistUuid, getBackendBaseUrl) {
|
|
2369
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2370
|
+
return useQueryWithParse({
|
|
2371
|
+
queryKey: artistQueryKeys.genreCounts(getBackendBaseUrl(), artistUuid),
|
|
2372
|
+
// A missing artist is shown in the artist panel, not raised as an app-wide connectivity error.
|
|
2373
|
+
queryFn: () => fetch2(artistEndpoints.genreCounts(artistUuid), true, false, void 0, void 0, false, true),
|
|
2374
|
+
schema: import_zod27.z.array(ArtistGenreCountSchema),
|
|
2375
|
+
enabled: artistUuid !== null,
|
|
2376
|
+
placeholderData: import_react_query7.keepPreviousData,
|
|
2377
|
+
retry: (failureCount, error) => !isNotFound2(error) && failureCount < 3,
|
|
2378
|
+
context: "useArtistGenreCounts"
|
|
2379
|
+
});
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
// src/genre-tree/useGenreSearch.ts
|
|
2383
|
+
var import_react14 = require("react");
|
|
2384
|
+
|
|
2385
|
+
// src/genre-tree/lib/genre-search.ts
|
|
2386
|
+
var searchGenrePlaylistsByName = (genrePlaylists, query) => {
|
|
2387
|
+
const trimmedQuery = query.trim().toLowerCase();
|
|
2388
|
+
if (!trimmedQuery) return [];
|
|
2389
|
+
return genrePlaylists.filter(
|
|
2390
|
+
(genrePlaylist) => genrePlaylist.name.toLowerCase().includes(trimmedQuery)
|
|
2391
|
+
);
|
|
2392
|
+
};
|
|
2393
|
+
|
|
2394
|
+
// src/genre-tree/useGenreSearch.ts
|
|
2395
|
+
function useGenreSearch({
|
|
2396
|
+
genrePlaylists,
|
|
2397
|
+
onSelect,
|
|
2398
|
+
selectedName = null,
|
|
2399
|
+
onClear
|
|
2400
|
+
}) {
|
|
2401
|
+
const [query, setQuery] = (0, import_react14.useState)(selectedName ?? "");
|
|
2402
|
+
const [prevSelectedName, setPrevSelectedName] = (0, import_react14.useState)(selectedName);
|
|
2403
|
+
if (selectedName !== prevSelectedName) {
|
|
2404
|
+
setPrevSelectedName(selectedName);
|
|
2405
|
+
setQuery(selectedName ?? "");
|
|
2406
|
+
}
|
|
2407
|
+
const results = query !== "" && query !== selectedName ? searchGenrePlaylistsByName(genrePlaylists, query) : [];
|
|
2408
|
+
return {
|
|
2409
|
+
query,
|
|
2410
|
+
setQuery,
|
|
2411
|
+
results,
|
|
2412
|
+
canClear: query !== "" || selectedName !== null,
|
|
2413
|
+
clear: () => {
|
|
2414
|
+
setQuery("");
|
|
2415
|
+
onClear?.();
|
|
2416
|
+
},
|
|
2417
|
+
select: (genrePlaylist) => {
|
|
2418
|
+
setQuery(genrePlaylist.name === selectedName ? selectedName : "");
|
|
2419
|
+
onSelect(genrePlaylist);
|
|
2420
|
+
}
|
|
2421
|
+
};
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
// src/genre-tree/useGenreTreeViewState.ts
|
|
2425
|
+
var import_react16 = require("react");
|
|
2426
|
+
|
|
2427
|
+
// src/genre-tree/useVisibleGenrePlaylists.ts
|
|
2428
|
+
var import_react15 = require("react");
|
|
2429
|
+
|
|
2430
|
+
// src/genre-tree/lib/prune-genre-playlists-for-artist.ts
|
|
2431
|
+
var POP_ROOT_NAME = "Mainstream Pop";
|
|
2432
|
+
var CORE_ELECTRONIC_NAME = "Core electronic";
|
|
2433
|
+
var pruneGenrePlaylistsForArtist = (playlists, counts) => {
|
|
2434
|
+
const countByPlaylist = new Map(counts.map((count) => [count.genrePlaylist, count]));
|
|
2435
|
+
const kept = /* @__PURE__ */ new Set();
|
|
2436
|
+
for (const playlist of playlists) {
|
|
2437
|
+
const isPopRoot = playlist.parent === null && playlist.name === POP_ROOT_NAME;
|
|
2438
|
+
if (isPopRoot || (countByPlaylist.get(playlist.uuid)?.songsCount ?? 0) > 0) kept.add(playlist.uuid);
|
|
2439
|
+
}
|
|
2440
|
+
const coreElectronicUuids = new Set(
|
|
2441
|
+
playlists.filter((playlist) => playlist.name === CORE_ELECTRONIC_NAME && kept.has(playlist.uuid)).map((p) => p.uuid)
|
|
2442
|
+
);
|
|
2443
|
+
for (const playlist of playlists) {
|
|
2444
|
+
if (playlist.parent && coreElectronicUuids.has(playlist.parent.uuid)) kept.add(playlist.uuid);
|
|
2445
|
+
}
|
|
2446
|
+
return playlists.filter((playlist) => kept.has(playlist.uuid)).map((playlist) => ({
|
|
2447
|
+
...playlist,
|
|
2448
|
+
tracksCount: countByPlaylist.get(playlist.uuid)?.tracksCount ?? 0,
|
|
2449
|
+
// Per-artist view totals are not served, so the views metric is unavailable on a pruned tree.
|
|
2450
|
+
viewsCount: 0
|
|
2451
|
+
}));
|
|
2452
|
+
};
|
|
2453
|
+
|
|
2454
|
+
// src/genre-tree/useVisibleGenrePlaylists.ts
|
|
2455
|
+
function useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid = null }) {
|
|
2456
|
+
const { data: tree, isPending: isTreePending, isFetching: isTreeFetching } = useListFullGenrePlaylists(scope, getBackendBaseUrl);
|
|
2457
|
+
const counts = useArtistGenreCounts(artistUuid, getBackendBaseUrl);
|
|
2458
|
+
const artistCounts = artistUuid !== null ? counts.data : void 0;
|
|
2459
|
+
const isCountsLoading = artistUuid !== null && (counts.isPending || counts.isPlaceholderData);
|
|
2460
|
+
const genrePlaylists = (0, import_react15.useMemo)(() => {
|
|
2461
|
+
if (!tree) return [];
|
|
2462
|
+
return artistCounts ? pruneGenrePlaylistsForArtist(tree, artistCounts) : tree;
|
|
2463
|
+
}, [tree, artistCounts]);
|
|
2464
|
+
return { isLoading: isTreePending, isFetching: isCountsLoading || !isTreePending && isTreeFetching, genrePlaylists };
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
// src/genre-tree/lib/genre-playlist-helpers.ts
|
|
2468
|
+
var getGenrePlaylistsGroupedByRoot = (genrePlaylists) => genrePlaylists.reduce((acc, playlist) => {
|
|
2469
|
+
const rootUuid = playlist.root.uuid;
|
|
2470
|
+
if (!acc[rootUuid]) acc[rootUuid] = [];
|
|
2471
|
+
acc[rootUuid].push(playlist);
|
|
2472
|
+
return acc;
|
|
2473
|
+
}, {});
|
|
2474
|
+
var hasMainstreamPopRoot = (nodes) => nodes.some((node) => node.parentId === null && node.name === "Mainstream Pop");
|
|
2475
|
+
|
|
2476
|
+
// src/genre-tree/useGenreTreeViewState.ts
|
|
2477
|
+
var HOVER_PREFETCH_DELAY_MS = 100;
|
|
2478
|
+
var needsPopCore = (mode) => mode === "pop-core" || mode === "outline";
|
|
2479
|
+
function useGenreTreeViewState({
|
|
2480
|
+
scope,
|
|
2481
|
+
getBackendBaseUrl,
|
|
2482
|
+
viewMode: controlledViewMode,
|
|
2483
|
+
artistUuid,
|
|
2484
|
+
selectedNodeId: controlledSelectedNodeId,
|
|
2485
|
+
onSelectedNodeIdChange,
|
|
2486
|
+
criteriaOverviewSchema
|
|
2487
|
+
}) {
|
|
2488
|
+
const [internalViewMode, setInternalViewMode] = (0, import_react16.useState)("pop-core");
|
|
2489
|
+
const [allowWheelRotation, setAllowWheelRotation] = (0, import_react16.useState)(false);
|
|
2490
|
+
const [internalSelectedNodeId, setInternalSelectedNodeId] = (0, import_react16.useState)(null);
|
|
2491
|
+
const isSelectionControlled = controlledSelectedNodeId !== void 0;
|
|
2492
|
+
const selectedNodeId = isSelectionControlled ? controlledSelectedNodeId : internalSelectedNodeId;
|
|
2493
|
+
const setSelectedNodeId = (0, import_react16.useCallback)(
|
|
2494
|
+
(nodeId) => {
|
|
2495
|
+
if (!isSelectionControlled) setInternalSelectedNodeId(nodeId);
|
|
2496
|
+
onSelectedNodeIdChange?.(nodeId);
|
|
2497
|
+
},
|
|
2498
|
+
[isSelectionControlled, onSelectedNodeIdChange]
|
|
2499
|
+
);
|
|
2500
|
+
const { isLoading, isFetching, genrePlaylists } = useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid });
|
|
2501
|
+
const genrePlaylistByNodeId = (0, import_react16.useMemo)(() => new Map(genrePlaylists.map((gp) => [gp.uuid, gp])), [genrePlaylists]);
|
|
2502
|
+
const selectedGenrePlaylist = (0, import_react16.useMemo)(
|
|
2503
|
+
() => genrePlaylists.find((gp) => gp.uuid === selectedNodeId),
|
|
2504
|
+
[genrePlaylists, selectedNodeId]
|
|
2505
|
+
);
|
|
2506
|
+
const selectNode = (0, import_react16.useCallback)((node) => setSelectedNodeId(node?.id ?? null), [setSelectedNodeId]);
|
|
2507
|
+
const clearSelection = (0, import_react16.useCallback)(() => setSelectedNodeId(null), [setSelectedNodeId]);
|
|
2508
|
+
const selectGenrePlaylist = (0, import_react16.useCallback)(
|
|
2509
|
+
(genrePlaylist) => setSelectedNodeId(genrePlaylist.uuid),
|
|
2510
|
+
[setSelectedNodeId]
|
|
2511
|
+
);
|
|
2512
|
+
const prefetchGenreOverview = usePrefetchGenreOverview(scope, getBackendBaseUrl, criteriaOverviewSchema);
|
|
2513
|
+
const hoverPrefetchTimerRef = (0, import_react16.useRef)(null);
|
|
2514
|
+
(0, import_react16.useEffect)(
|
|
2515
|
+
() => () => {
|
|
2516
|
+
if (hoverPrefetchTimerRef.current) clearTimeout(hoverPrefetchTimerRef.current);
|
|
2517
|
+
},
|
|
2518
|
+
[]
|
|
2519
|
+
);
|
|
2520
|
+
const onNodeHover = (0, import_react16.useCallback)(
|
|
2521
|
+
(node) => {
|
|
2522
|
+
if (hoverPrefetchTimerRef.current) clearTimeout(hoverPrefetchTimerRef.current);
|
|
2523
|
+
const genreUuid = genrePlaylistByNodeId.get(node.id)?.criteria?.uuid;
|
|
2524
|
+
if (!genreUuid) return;
|
|
2525
|
+
hoverPrefetchTimerRef.current = setTimeout(() => {
|
|
2526
|
+
void prefetchGenreOverview(genreUuid);
|
|
2527
|
+
}, HOVER_PREFETCH_DELAY_MS);
|
|
2528
|
+
},
|
|
2529
|
+
[genrePlaylistByNodeId, prefetchGenreOverview]
|
|
2530
|
+
);
|
|
2531
|
+
const groupedGenrePlaylistsByRoot = (0, import_react16.useMemo)(() => getGenrePlaylistsGroupedByRoot(genrePlaylists), [genrePlaylists]);
|
|
2532
|
+
const canShowPopCore = (0, import_react16.useMemo)(
|
|
2533
|
+
() => hasMainstreamPopRoot(
|
|
2534
|
+
genrePlaylists.map((genrePlaylist) => ({
|
|
2535
|
+
parentId: genrePlaylist.parent?.uuid ?? null,
|
|
2536
|
+
name: genrePlaylist.name
|
|
2537
|
+
}))
|
|
2538
|
+
),
|
|
2539
|
+
[genrePlaylists]
|
|
2540
|
+
);
|
|
2541
|
+
(0, import_react16.useEffect)(() => {
|
|
2542
|
+
if (!isLoading && needsPopCore(internalViewMode) && !canShowPopCore) {
|
|
2543
|
+
setInternalViewMode("wheel");
|
|
2544
|
+
}
|
|
2545
|
+
}, [isLoading, canShowPopCore, internalViewMode]);
|
|
2546
|
+
const selectedViewMode = controlledViewMode ?? internalViewMode;
|
|
2547
|
+
const viewMode = needsPopCore(selectedViewMode) && !canShowPopCore ? "wheel" : selectedViewMode;
|
|
2548
|
+
const visibleGenrePlaylists = (0, import_react16.useMemo)(() => {
|
|
2549
|
+
if (viewMode === "stacked") return genrePlaylists;
|
|
2550
|
+
const unacceptedRootUuids = new Set(genrePlaylists.filter((gp) => gp.isUnacceptedRoot).map((gp) => gp.uuid));
|
|
2551
|
+
const accepted = genrePlaylists.filter((gp) => !gp.isUnacceptedRoot && !unacceptedRootUuids.has(gp.root.uuid));
|
|
2552
|
+
return viewMode === "outline" ? accepted : accepted.filter((gp) => gp.criteria);
|
|
2553
|
+
}, [genrePlaylists, viewMode]);
|
|
2554
|
+
return {
|
|
2555
|
+
isLoading,
|
|
2556
|
+
isFetching,
|
|
2557
|
+
genrePlaylists,
|
|
2558
|
+
genrePlaylistByNodeId,
|
|
2559
|
+
visibleGenrePlaylists,
|
|
2560
|
+
groupedGenrePlaylistsByRoot,
|
|
2561
|
+
selectedNodeId,
|
|
2562
|
+
selectedGenrePlaylist,
|
|
2563
|
+
selectNode,
|
|
2564
|
+
selectGenrePlaylist,
|
|
2565
|
+
clearSelection,
|
|
2566
|
+
viewMode,
|
|
2567
|
+
isViewModeControlled: controlledViewMode !== void 0,
|
|
2568
|
+
setViewMode: setInternalViewMode,
|
|
2569
|
+
canShowPopCore,
|
|
2570
|
+
allowWheelRotation,
|
|
2571
|
+
toggleWheelRotation: () => setAllowWheelRotation((prev) => !prev),
|
|
2572
|
+
onNodeHover
|
|
2573
|
+
};
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
// src/genre-tree/TrackListContext.tsx
|
|
2577
|
+
var import_react18 = require("react");
|
|
2578
|
+
|
|
2579
|
+
// src/genre-tree/schemas/track-playlist-rel/without-playlist.ts
|
|
2580
|
+
var import_zod28 = require("zod");
|
|
2581
|
+
var makeTrackPlaylistRelSchema = (trackSchema) => import_zod28.z.object({
|
|
2582
|
+
track: trackSchema,
|
|
2583
|
+
position: import_zod28.z.number().min(0)
|
|
2584
|
+
});
|
|
2585
|
+
var makeTrackPlaylistRelPageSchema = (trackSchema) => PaginatedResponseSchema(makeTrackPlaylistRelSchema(trackSchema));
|
|
2586
|
+
|
|
2587
|
+
// src/genre-tree/models/TrackList.ts
|
|
2588
|
+
var TrackList = class {
|
|
2589
|
+
constructor(tracks, origin, total = tracks.length, nextPage = null) {
|
|
2590
|
+
this.tracks = tracks;
|
|
2591
|
+
this.origin = origin;
|
|
2592
|
+
this.total = total;
|
|
2593
|
+
this.nextPage = nextPage;
|
|
2594
|
+
}
|
|
2595
|
+
tracks;
|
|
2596
|
+
origin;
|
|
2597
|
+
total;
|
|
2598
|
+
nextPage;
|
|
2599
|
+
};
|
|
2600
|
+
var TrackListFromTrack = class extends TrackList {
|
|
2601
|
+
constructor(tracks, origin) {
|
|
2602
|
+
super(tracks, origin);
|
|
2603
|
+
this.tracks = tracks;
|
|
2604
|
+
this.origin = origin;
|
|
2605
|
+
}
|
|
2606
|
+
tracks;
|
|
2607
|
+
origin;
|
|
2608
|
+
};
|
|
2609
|
+
var TrackListFromCriteriaPlaylist = class extends TrackList {
|
|
2610
|
+
constructor(tracks, origin, total, nextPage) {
|
|
2611
|
+
super(tracks, origin, total, nextPage);
|
|
2612
|
+
this.tracks = tracks;
|
|
2613
|
+
this.origin = origin;
|
|
2614
|
+
}
|
|
2615
|
+
tracks;
|
|
2616
|
+
origin;
|
|
2617
|
+
};
|
|
2618
|
+
var TrackListFromArtist = class extends TrackList {
|
|
2619
|
+
constructor(tracks, origin, total, nextPage) {
|
|
2620
|
+
super(tracks, origin, total, nextPage);
|
|
2621
|
+
this.tracks = tracks;
|
|
2622
|
+
this.origin = origin;
|
|
2623
|
+
}
|
|
2624
|
+
tracks;
|
|
2625
|
+
origin;
|
|
2626
|
+
};
|
|
2627
|
+
|
|
2628
|
+
// src/genre-tree/models/TrackListOriginType.ts
|
|
2629
|
+
var TrackListOriginType = /* @__PURE__ */ ((TrackListOriginType2) => {
|
|
2630
|
+
TrackListOriginType2["TRACK"] = "TRACK";
|
|
2631
|
+
TrackListOriginType2["GENRE_PLAYLIST"] = "GENRE_PLAYLIST";
|
|
2632
|
+
TrackListOriginType2["ARTIST"] = "ARTIST";
|
|
2633
|
+
return TrackListOriginType2;
|
|
2634
|
+
})(TrackListOriginType || {});
|
|
2635
|
+
|
|
2636
|
+
// src/genre-tree/models/TrackListOrigin.ts
|
|
2637
|
+
var TrackListOrigin = class {
|
|
2638
|
+
constructor(type, label, uuid, scope) {
|
|
2639
|
+
this.type = type;
|
|
2640
|
+
this.label = label;
|
|
2641
|
+
this.uuid = uuid;
|
|
2642
|
+
this.scope = scope;
|
|
2643
|
+
}
|
|
2644
|
+
type;
|
|
2645
|
+
label;
|
|
2646
|
+
uuid;
|
|
2647
|
+
scope;
|
|
2648
|
+
};
|
|
2649
|
+
var TrackListOriginFromTrack = class extends TrackListOrigin {
|
|
2650
|
+
constructor(track, scope) {
|
|
2651
|
+
super(
|
|
2652
|
+
"TRACK" /* TRACK */,
|
|
2653
|
+
`${track.title} by ${track.artists ? track.artists.map((artist) => artist.name).join(", ") : ""}`,
|
|
2654
|
+
track.uuid,
|
|
2655
|
+
scope
|
|
2656
|
+
);
|
|
2657
|
+
this.track = track;
|
|
2658
|
+
}
|
|
2659
|
+
track;
|
|
2660
|
+
};
|
|
2661
|
+
var TrackListOriginFromCriteriaPlaylist = class extends TrackListOrigin {
|
|
2662
|
+
/** `from`: the track the list starts at (server-side `?from=`), kept so later pages use it too. */
|
|
2663
|
+
constructor(criteriaPlaylist, scope, from) {
|
|
2664
|
+
super("GENRE_PLAYLIST" /* GENRE_PLAYLIST */, criteriaPlaylist.name, criteriaPlaylist.uuid, scope);
|
|
2665
|
+
this.criteriaPlaylist = criteriaPlaylist;
|
|
2666
|
+
this.from = from;
|
|
2667
|
+
}
|
|
2668
|
+
criteriaPlaylist;
|
|
2669
|
+
from;
|
|
2670
|
+
};
|
|
2671
|
+
var TrackListOriginFromArtist = class extends TrackListOrigin {
|
|
2672
|
+
/** `ordering`/`from`: kept so later pages use the same order and start track. */
|
|
2673
|
+
constructor(artist, scope, ordering, from, genreUuid) {
|
|
2674
|
+
super("ARTIST" /* ARTIST */, artist.name, artist.uuid, scope);
|
|
2675
|
+
this.artist = artist;
|
|
2676
|
+
this.ordering = ordering;
|
|
2677
|
+
this.from = from;
|
|
2678
|
+
this.genreUuid = genreUuid;
|
|
2679
|
+
}
|
|
2680
|
+
artist;
|
|
2681
|
+
ordering;
|
|
2682
|
+
from;
|
|
2683
|
+
genreUuid;
|
|
2684
|
+
};
|
|
2685
|
+
|
|
2686
|
+
// src/genre-tree/TrackListSidebarVisibilityContext.tsx
|
|
2687
|
+
var import_react17 = require("react");
|
|
2688
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
2689
|
+
var TrackListSidebarVisibilityContext = (0, import_react17.createContext)(void 0);
|
|
2690
|
+
function TrackListSidebarVisibilityProvider({ children }) {
|
|
2691
|
+
const [isTrackListSidebarVisible, setIsTrackListSidebarVisible] = (0, import_react17.useState)(false);
|
|
2692
|
+
const toggleTrackListSidebar = (0, import_react17.useCallback)(() => {
|
|
2693
|
+
setIsTrackListSidebarVisible((prev) => !prev);
|
|
2694
|
+
}, []);
|
|
2695
|
+
const showTrackListSidebar = (0, import_react17.useCallback)(() => {
|
|
2696
|
+
setIsTrackListSidebarVisible(true);
|
|
2697
|
+
}, []);
|
|
2698
|
+
const hideTrackListSidebar = (0, import_react17.useCallback)(() => {
|
|
2699
|
+
setIsTrackListSidebarVisible(false);
|
|
2700
|
+
}, []);
|
|
2701
|
+
const value = (0, import_react17.useMemo)(
|
|
2702
|
+
() => ({
|
|
2703
|
+
isTrackListSidebarVisible,
|
|
2704
|
+
toggleTrackListSidebar,
|
|
2705
|
+
showTrackListSidebar,
|
|
2706
|
+
hideTrackListSidebar
|
|
2707
|
+
}),
|
|
2708
|
+
[isTrackListSidebarVisible, toggleTrackListSidebar, showTrackListSidebar, hideTrackListSidebar]
|
|
2709
|
+
);
|
|
2710
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TrackListSidebarVisibilityContext.Provider, { value, children });
|
|
2711
|
+
}
|
|
2712
|
+
function useTrackListSidebarVisibility() {
|
|
2713
|
+
const context = (0, import_react17.useContext)(TrackListSidebarVisibilityContext);
|
|
2714
|
+
if (context === void 0) {
|
|
2715
|
+
throw new Error("useTrackListSidebarVisibility must be used within a TrackListSidebarVisibilityProvider");
|
|
2716
|
+
}
|
|
2717
|
+
return context;
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
// src/genre-tree/TrackListContext.tsx
|
|
2721
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
2722
|
+
var TRACKS_PAGE_SIZE = 100;
|
|
2723
|
+
var AUTO_LOAD_REMAINING_TRACKS = 10;
|
|
2724
|
+
function useListTracks(scope, getBackendBaseUrl, schema, listEndpoint, listQueryKey, page = 1, pageSize = 50) {
|
|
2725
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2726
|
+
const { session, sessionRestored } = useSession();
|
|
2727
|
+
return useQueryWithParse({
|
|
2728
|
+
queryKey: listQueryKey(page),
|
|
2729
|
+
queryFn: async () => {
|
|
2730
|
+
if (scope == null) return null;
|
|
2731
|
+
return fetch2(listEndpoint(page), true, scope === "me", {}, { page, pageSize });
|
|
2732
|
+
},
|
|
2733
|
+
schema: PaginatedResponseSchema(schema),
|
|
2734
|
+
context: "useListTracks",
|
|
2735
|
+
enabled: scope != null && (scope === "reference" || sessionRestored && !!session?.accessToken)
|
|
2736
|
+
});
|
|
2737
|
+
}
|
|
2738
|
+
var TrackListContext = (0, import_react18.createContext)(void 0);
|
|
2739
|
+
function TrackListProvider({
|
|
2740
|
+
children,
|
|
2741
|
+
getBackendBaseUrl,
|
|
2742
|
+
schema,
|
|
2743
|
+
listEndpoint,
|
|
2744
|
+
listQueryKey
|
|
2745
|
+
}) {
|
|
2746
|
+
const [trackList, setTrackList] = (0, import_react18.useState)(null);
|
|
2747
|
+
const [selectedTrack, setSelectedTrack] = (0, import_react18.useState)(null);
|
|
2748
|
+
const { loadTrackForPlayer } = usePlayer();
|
|
2749
|
+
const { showTrackListSidebar } = useTrackListSidebarVisibility();
|
|
2750
|
+
const scope = trackList?.origin?.scope ?? null;
|
|
2751
|
+
const { data: tracksResponse } = useListTracks(scope, getBackendBaseUrl, schema, listEndpoint, listQueryKey);
|
|
2752
|
+
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2753
|
+
const pageSchema = (0, import_react18.useMemo)(() => makeTrackPlaylistRelPageSchema(schema), [schema]);
|
|
2754
|
+
const latestPlayRequestRef = (0, import_react18.useRef)(0);
|
|
2755
|
+
const loadingOriginRef = (0, import_react18.useRef)(null);
|
|
2756
|
+
const fetchTracksPage = (0, import_react18.useCallback)(
|
|
2757
|
+
async (uuid, scope2, page, from) => {
|
|
2758
|
+
const endpoint = genrePlaylistEndpoints[scope2].tracks(uuid);
|
|
2759
|
+
const params = { page, pageSize: TRACKS_PAGE_SIZE, ...from && { from } };
|
|
2760
|
+
const response = await fetch2(endpoint, true, scope2 === "me", {}, params);
|
|
2761
|
+
const parsed = parseWithLog(pageSchema, response, "fetchGenrePlaylistTracksPage");
|
|
2762
|
+
return {
|
|
2763
|
+
tracks: parsed.results.map((rel) => rel.track),
|
|
2764
|
+
total: parsed.overallTotal,
|
|
2765
|
+
nextPage: parsed.next ? parsed.page + 1 : null
|
|
2766
|
+
};
|
|
2767
|
+
},
|
|
2768
|
+
[fetch2, pageSchema]
|
|
2769
|
+
);
|
|
2770
|
+
const artistPageSchema = (0, import_react18.useMemo)(() => PaginatedResponseSchema(schema), [schema]);
|
|
2771
|
+
const fetchArtistTracksPage = (0, import_react18.useCallback)(
|
|
2772
|
+
async (origin, page) => {
|
|
2773
|
+
const params = {
|
|
2774
|
+
artist: origin.uuid,
|
|
2775
|
+
playable: true,
|
|
2776
|
+
ordering: origin.ordering,
|
|
2777
|
+
page,
|
|
2778
|
+
pageSize: TRACKS_PAGE_SIZE,
|
|
2779
|
+
...origin.from && { from: origin.from },
|
|
2780
|
+
...origin.genreUuid && { genre: origin.genreUuid }
|
|
2781
|
+
};
|
|
2782
|
+
const response = await fetch2(
|
|
2783
|
+
libraryEndpoints.reference.songs.list(),
|
|
2784
|
+
true,
|
|
2785
|
+
false,
|
|
2786
|
+
{},
|
|
2787
|
+
params,
|
|
2788
|
+
false,
|
|
2789
|
+
// A start song that isn't playable 404s; surface it as a rejection, not the global error.
|
|
2790
|
+
page === 1 && !!origin.from
|
|
2791
|
+
);
|
|
2792
|
+
const parsed = parseWithLog(artistPageSchema, response, "fetchArtistTracksPage");
|
|
2793
|
+
return { tracks: parsed.results, total: parsed.overallTotal, nextPage: parsed.next ? parsed.page + 1 : null };
|
|
2794
|
+
},
|
|
2795
|
+
[fetch2, artistPageSchema]
|
|
2796
|
+
);
|
|
2797
|
+
const currentTrackList = (0, import_react18.useMemo)(() => {
|
|
2798
|
+
if (!trackList) return null;
|
|
2799
|
+
const freshTracks = new Map((tracksResponse?.results ?? []).map((track) => [track.uuid, track]));
|
|
2800
|
+
const tracks = trackList.tracks.map((track) => freshTracks.get(track.uuid) ?? track);
|
|
2801
|
+
if (tracks.every((track, index) => track === trackList.tracks[index])) return trackList;
|
|
2802
|
+
return new TrackList(tracks, trackList.origin, trackList.total, trackList.nextPage);
|
|
2803
|
+
}, [trackList, tracksResponse]);
|
|
2804
|
+
const toTrackAtPosition = (0, import_react18.useCallback)(
|
|
2805
|
+
(position) => {
|
|
2806
|
+
if (currentTrackList && position >= 0 && position < currentTrackList.tracks.length) {
|
|
2807
|
+
setSelectedTrack(currentTrackList.tracks[position]);
|
|
2808
|
+
}
|
|
2809
|
+
},
|
|
2810
|
+
[currentTrackList]
|
|
2811
|
+
);
|
|
2812
|
+
const playNewTrackListFromTrackUuid = (0, import_react18.useCallback)(
|
|
2813
|
+
(track, scope2) => {
|
|
2814
|
+
latestPlayRequestRef.current++;
|
|
2815
|
+
const origin = new TrackListOriginFromTrack(track, scope2);
|
|
2816
|
+
const newTrackList = new TrackListFromTrack([track], origin);
|
|
2817
|
+
setTrackList(newTrackList);
|
|
2818
|
+
setSelectedTrack(track);
|
|
2819
|
+
showTrackListSidebar();
|
|
2820
|
+
loadTrackForPlayer(track.uuid);
|
|
2821
|
+
},
|
|
2822
|
+
[showTrackListSidebar, loadTrackForPlayer]
|
|
2823
|
+
);
|
|
2824
|
+
const playNewTrackListFromGenrePlaylist = (0, import_react18.useCallback)(
|
|
2825
|
+
async (genrePlaylist, scope2, options) => {
|
|
2826
|
+
const request = ++latestPlayRequestRef.current;
|
|
2827
|
+
const from = options?.startSongUuid;
|
|
2828
|
+
let page;
|
|
2829
|
+
try {
|
|
2830
|
+
page = await fetchTracksPage(genrePlaylist.uuid, scope2, 1, from);
|
|
2831
|
+
} catch (error) {
|
|
2832
|
+
if (request !== latestPlayRequestRef.current) return;
|
|
2833
|
+
throw error;
|
|
2834
|
+
}
|
|
2835
|
+
if (request !== latestPlayRequestRef.current) return;
|
|
2836
|
+
const startTrack = page.tracks[0];
|
|
2837
|
+
if (from && startTrack?.uuid !== from) {
|
|
2838
|
+
throw new Error(`Genre playlist ${genrePlaylist.uuid} did not start at track ${from}`);
|
|
2839
|
+
}
|
|
2840
|
+
if (!startTrack) {
|
|
2841
|
+
console.warn("No playable tracks found in genre playlist");
|
|
2842
|
+
return;
|
|
2843
|
+
}
|
|
2844
|
+
const origin = new TrackListOriginFromCriteriaPlaylist(genrePlaylist, scope2, from);
|
|
2845
|
+
setTrackList(new TrackListFromCriteriaPlaylist(page.tracks, origin, page.total, page.nextPage));
|
|
2846
|
+
setSelectedTrack(startTrack);
|
|
2847
|
+
showTrackListSidebar();
|
|
2848
|
+
loadTrackForPlayer(startTrack.uuid);
|
|
2849
|
+
},
|
|
2850
|
+
[fetchTracksPage, showTrackListSidebar, loadTrackForPlayer]
|
|
2851
|
+
);
|
|
2852
|
+
const playNewTrackListFromArtist = (0, import_react18.useCallback)(
|
|
2853
|
+
async (artist, scope2, options) => {
|
|
2854
|
+
if (scope2 !== "reference") throw new Error("Artist track lists only support the reference scope");
|
|
2855
|
+
const request = ++latestPlayRequestRef.current;
|
|
2856
|
+
const from = options.startSongUuid;
|
|
2857
|
+
const origin = new TrackListOriginFromArtist(artist, scope2, options.ordering, from, options.genreUuid);
|
|
2858
|
+
let page;
|
|
2859
|
+
try {
|
|
2860
|
+
page = await fetchArtistTracksPage(origin, 1);
|
|
2861
|
+
} catch (error) {
|
|
2862
|
+
if (request !== latestPlayRequestRef.current) return;
|
|
2863
|
+
throw error;
|
|
2864
|
+
}
|
|
2865
|
+
if (request !== latestPlayRequestRef.current) return;
|
|
2866
|
+
const startTrack = page.tracks[0];
|
|
2867
|
+
if (from && startTrack?.uuid !== from) {
|
|
2868
|
+
throw new Error(`Artist ${artist.uuid} did not start at song ${from}`);
|
|
2869
|
+
}
|
|
2870
|
+
if (!startTrack) {
|
|
2871
|
+
console.warn("No playable songs found for artist");
|
|
2872
|
+
return;
|
|
2873
|
+
}
|
|
2874
|
+
setTrackList(new TrackListFromArtist(page.tracks, origin, page.total, page.nextPage));
|
|
2875
|
+
setSelectedTrack(startTrack);
|
|
2876
|
+
showTrackListSidebar();
|
|
2877
|
+
loadTrackForPlayer(startTrack.uuid);
|
|
2878
|
+
},
|
|
2879
|
+
[fetchArtistTracksPage, showTrackListSidebar, loadTrackForPlayer]
|
|
2880
|
+
);
|
|
2881
|
+
const loadMore = (0, import_react18.useCallback)(async () => {
|
|
2882
|
+
if (!trackList || trackList.nextPage === null) return;
|
|
2883
|
+
const origin = trackList.origin;
|
|
2884
|
+
if (!(origin instanceof TrackListOriginFromCriteriaPlaylist || origin instanceof TrackListOriginFromArtist)) return;
|
|
2885
|
+
if (loadingOriginRef.current === origin) return;
|
|
2886
|
+
const requestedPage = trackList.nextPage;
|
|
2887
|
+
loadingOriginRef.current = origin;
|
|
2888
|
+
try {
|
|
2889
|
+
const page = origin instanceof TrackListOriginFromArtist ? await fetchArtistTracksPage(origin, requestedPage) : await fetchTracksPage(origin.criteriaPlaylist.uuid, origin.scope, requestedPage, origin.from);
|
|
2890
|
+
setTrackList((prev) => {
|
|
2891
|
+
if (prev?.origin !== origin || prev.nextPage !== requestedPage) return prev;
|
|
2892
|
+
const loaded = new Set(prev.tracks.map((track) => track.uuid));
|
|
2893
|
+
const tracks = [...prev.tracks, ...page.tracks.filter((track) => !loaded.has(track.uuid))];
|
|
2894
|
+
return origin instanceof TrackListOriginFromArtist ? new TrackListFromArtist(tracks, origin, page.total, page.nextPage) : new TrackListFromCriteriaPlaylist(tracks, origin, page.total, page.nextPage);
|
|
2895
|
+
});
|
|
2896
|
+
} finally {
|
|
2897
|
+
if (loadingOriginRef.current === origin) loadingOriginRef.current = null;
|
|
2898
|
+
}
|
|
2899
|
+
}, [trackList, fetchTracksPage, fetchArtistTracksPage]);
|
|
2900
|
+
(0, import_react18.useEffect)(() => {
|
|
2901
|
+
if (!currentTrackList || currentTrackList.nextPage === null || !selectedTrack) return;
|
|
2902
|
+
const index = currentTrackList.tracks.findIndex((track) => track.uuid === selectedTrack.uuid);
|
|
2903
|
+
if (index !== -1 && currentTrackList.tracks.length - index <= AUTO_LOAD_REMAINING_TRACKS) {
|
|
2904
|
+
loadMore().catch((error) => console.error("Failed to load more tracks:", error));
|
|
2905
|
+
}
|
|
2906
|
+
}, [currentTrackList, selectedTrack, loadMore]);
|
|
2907
|
+
const value = (0, import_react18.useMemo)(
|
|
2908
|
+
() => ({
|
|
2909
|
+
trackList: currentTrackList,
|
|
2910
|
+
selectedTrack,
|
|
2911
|
+
setSelectedTrack,
|
|
2912
|
+
toTrackAtPosition,
|
|
2913
|
+
playNewTrackListFromTrackUuid,
|
|
2914
|
+
playNewTrackListFromGenrePlaylist,
|
|
2915
|
+
playNewTrackListFromArtist,
|
|
2916
|
+
fetchGenrePlaylistTracksPage: fetchTracksPage,
|
|
2917
|
+
loadMore
|
|
2918
|
+
}),
|
|
2919
|
+
[
|
|
2920
|
+
currentTrackList,
|
|
2921
|
+
selectedTrack,
|
|
2922
|
+
toTrackAtPosition,
|
|
2923
|
+
playNewTrackListFromTrackUuid,
|
|
2924
|
+
playNewTrackListFromGenrePlaylist,
|
|
2925
|
+
playNewTrackListFromArtist,
|
|
2926
|
+
fetchTracksPage,
|
|
2927
|
+
loadMore
|
|
2928
|
+
]
|
|
2929
|
+
);
|
|
2930
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TrackListContext.Provider, { value, children });
|
|
2931
|
+
}
|
|
2932
|
+
function useTrackList() {
|
|
2933
|
+
const context = (0, import_react18.useContext)(TrackListContext);
|
|
2934
|
+
if (!context) {
|
|
2935
|
+
throw new Error("useTrackList must be used within a TrackListProvider");
|
|
2936
|
+
}
|
|
2937
|
+
return context;
|
|
2938
|
+
}
|
|
2939
|
+
|
|
2940
|
+
// src/genre-tree/ArtistNames.tsx
|
|
2941
|
+
var import_react19 = require("react");
|
|
2942
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
2943
|
+
function ArtistNames({
|
|
2944
|
+
artists,
|
|
2945
|
+
renderArtistLink
|
|
2946
|
+
}) {
|
|
2947
|
+
if (!renderArtistLink) return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: artists.map((artist) => artist.name).join(", ") });
|
|
2948
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: artists.map((artist, index) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react19.Fragment, { children: [
|
|
2949
|
+
index > 0 && ", ",
|
|
2950
|
+
renderArtistLink(artist)
|
|
2951
|
+
] }, artist.uuid)) });
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
// src/genre-tree/schemas/mb-artist.ts
|
|
2955
|
+
var import_zod29 = require("zod");
|
|
2956
|
+
var MbArtistDetailedSchema = import_zod29.z.object({
|
|
2957
|
+
musicbrainzId: import_zod29.z.string().uuid(),
|
|
2958
|
+
name: import_zod29.z.string(),
|
|
2959
|
+
musicbrainzLink: HttpUrlSchema
|
|
2960
|
+
});
|
|
2961
|
+
|
|
2962
|
+
// src/genre-tree/schemas/mb-recording.ts
|
|
2963
|
+
var import_zod30 = require("zod");
|
|
2964
|
+
var MbRecordingDetailedSchema = import_zod30.z.object({
|
|
2965
|
+
musicbrainzId: import_zod30.z.string().uuid(),
|
|
2966
|
+
title: import_zod30.z.string(),
|
|
2967
|
+
score: import_zod30.z.number(),
|
|
2968
|
+
musicbrainzArtists: import_zod30.z.array(MbArtistDetailedSchema),
|
|
2969
|
+
musicbrainzLink: HttpUrlSchema,
|
|
2970
|
+
durationInSec: import_zod30.z.number().min(0).nullable().optional(),
|
|
2971
|
+
durationStrInHourMinSec: import_zod30.z.string().nullable().optional(),
|
|
2972
|
+
releaseDate: import_zod30.z.union([import_zod30.z.string().datetime(), import_zod30.z.string()]).transform((val) => {
|
|
2973
|
+
try {
|
|
2974
|
+
const date = new Date(val);
|
|
2975
|
+
if (isNaN(date.getTime())) {
|
|
2976
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
2977
|
+
}
|
|
2978
|
+
return date.toISOString();
|
|
2979
|
+
} catch {
|
|
2980
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
2981
|
+
}
|
|
2982
|
+
})
|
|
2983
|
+
});
|
|
2984
|
+
|
|
2985
|
+
// src/genre-tree/schemas/song/detailed.ts
|
|
2986
|
+
var import_zod31 = require("zod");
|
|
2987
|
+
var YOUTUBE_UNPLAYABLE_REASON_LABELS = {
|
|
2988
|
+
not_found: "Video unavailable",
|
|
2989
|
+
not_embeddable: "Embedding disabled",
|
|
2990
|
+
private: "Private video",
|
|
2991
|
+
not_processed: "Video still processing",
|
|
2992
|
+
region_whitelisted: "Region restricted"
|
|
2993
|
+
};
|
|
2994
|
+
var YOUTUBE_UNPLAYABLE_REASONS = Object.keys(YOUTUBE_UNPLAYABLE_REASON_LABELS);
|
|
2995
|
+
var SongDetailedSchema = TrackBaseSchema.extend({
|
|
2996
|
+
youtubeVideo: import_zod31.z.object({
|
|
2997
|
+
id: import_zod31.z.string(),
|
|
2998
|
+
// null = playable
|
|
2999
|
+
unplayableReason: import_zod31.z.enum(YOUTUBE_UNPLAYABLE_REASONS).nullable()
|
|
3000
|
+
}).nullable(),
|
|
3001
|
+
// null for hand-made/admin songs
|
|
3002
|
+
musicbrainzRecordingId: import_zod31.z.string().uuid().nullable()
|
|
3003
|
+
});
|
|
3004
|
+
var NO_VIDEO_LABEL = "No video available";
|
|
3005
|
+
function isSong(track) {
|
|
3006
|
+
return "youtubeVideo" in track;
|
|
3007
|
+
}
|
|
3008
|
+
function songUnplayableReason(song) {
|
|
3009
|
+
if (!song.youtubeVideo) return NO_VIDEO_LABEL;
|
|
3010
|
+
const reason = song.youtubeVideo.unplayableReason;
|
|
3011
|
+
return reason ? YOUTUBE_UNPLAYABLE_REASON_LABELS[reason] : null;
|
|
3012
|
+
}
|
|
3013
|
+
function musicBrainzRecordingUrl(song) {
|
|
3014
|
+
return song.musicbrainzRecordingId ? `https://musicbrainz.org/recording/${song.musicbrainzRecordingId}` : null;
|
|
3015
|
+
}
|
|
3016
|
+
|
|
3017
|
+
// src/genre-tree/lib/rating.ts
|
|
3018
|
+
var FORM_RATING_NULL_VALUE = -1;
|
|
3019
|
+
|
|
3020
|
+
// src/genre-tree/lib/formatting.ts
|
|
3021
|
+
var formatTime = (seconds) => {
|
|
3022
|
+
const minutes = Math.floor(seconds / 60);
|
|
3023
|
+
const secs = Math.floor(seconds % 60);
|
|
3024
|
+
let secsStr = secs.toString();
|
|
3025
|
+
if (secs < 10) {
|
|
3026
|
+
secsStr = "0" + secsStr;
|
|
3027
|
+
}
|
|
3028
|
+
return `${minutes}:${secsStr}`;
|
|
3029
|
+
};
|
|
3030
|
+
var capitalizeFirstLetter = (string) => {
|
|
3031
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
3032
|
+
};
|
|
3033
|
+
|
|
3034
|
+
// src/genre-tree/lib/reparent-candidates.ts
|
|
3035
|
+
var hasCriteria = (genrePlaylist) => genrePlaylist.criteria !== null;
|
|
3036
|
+
var getReparentCandidates = (genrePlaylists, genrePlaylistUuid) => {
|
|
3037
|
+
const parentUuidByUuid = new Map(genrePlaylists.map((genrePlaylist) => [genrePlaylist.uuid, genrePlaylist.parent?.uuid]));
|
|
3038
|
+
const currentParentUuid = parentUuidByUuid.get(genrePlaylistUuid);
|
|
3039
|
+
const isDescendant = (uuid) => {
|
|
3040
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3041
|
+
let ancestorUuid = parentUuidByUuid.get(uuid);
|
|
3042
|
+
while (ancestorUuid && !seen.has(ancestorUuid)) {
|
|
3043
|
+
if (ancestorUuid === genrePlaylistUuid) return true;
|
|
3044
|
+
seen.add(ancestorUuid);
|
|
3045
|
+
ancestorUuid = parentUuidByUuid.get(ancestorUuid);
|
|
3046
|
+
}
|
|
3047
|
+
return false;
|
|
3048
|
+
};
|
|
3049
|
+
return genrePlaylists.filter(hasCriteria).filter(
|
|
3050
|
+
(genrePlaylist) => genrePlaylist.uuid !== genrePlaylistUuid && genrePlaylist.uuid !== currentParentUuid && !isDescendant(genrePlaylist.uuid)
|
|
3051
|
+
);
|
|
3052
|
+
};
|
|
3053
|
+
|
|
3054
|
+
// src/genre-tree/lib/genre-songs-cache.ts
|
|
3055
|
+
function editGenreSongPages(data, edit) {
|
|
3056
|
+
if (!data) return data;
|
|
3057
|
+
const edited = data.pages.map((page) => edit(page.tracks));
|
|
3058
|
+
const delta = edited.reduce((sum, tracks, i) => sum + tracks.length - data.pages[i].tracks.length, 0);
|
|
3059
|
+
return {
|
|
3060
|
+
...data,
|
|
3061
|
+
pages: data.pages.map((page, i) => ({
|
|
3062
|
+
...page,
|
|
3063
|
+
tracks: edited[i],
|
|
3064
|
+
total: page.total === null ? null : page.total + delta
|
|
3065
|
+
}))
|
|
3066
|
+
};
|
|
3067
|
+
}
|
|
3068
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3069
|
+
0 && (module.exports = {
|
|
3070
|
+
ARTIST_LINK_KINDS,
|
|
3071
|
+
AUTH_POPUP_TYPE,
|
|
3072
|
+
AlbumMinimumSchema,
|
|
3073
|
+
AppError,
|
|
3074
|
+
ArtistDetailedSchema,
|
|
3075
|
+
ArtistGenreCountSchema,
|
|
3076
|
+
ArtistImageSchema,
|
|
3077
|
+
ArtistMinimumSchema,
|
|
3078
|
+
ArtistNames,
|
|
3079
|
+
ArtistSearchResultSchema,
|
|
3080
|
+
ArtistSearchResultsSchema,
|
|
3081
|
+
AudioMediaController,
|
|
3082
|
+
AuthRequired,
|
|
3083
|
+
BackendError,
|
|
3084
|
+
BackendSpotifyUserNotAllowlistedError,
|
|
3085
|
+
BadRequestError,
|
|
3086
|
+
ClientError,
|
|
3087
|
+
ConnectivityError,
|
|
3088
|
+
ConnectivityErrorProvider,
|
|
3089
|
+
ConnectivityErrorType,
|
|
3090
|
+
CriteriaCreationSchema,
|
|
3091
|
+
CriteriaDetailedSchema,
|
|
3092
|
+
CriteriaLineageRelWithoutAscendantSchema,
|
|
3093
|
+
CriteriaLineageRelWithoutDescendantSchema,
|
|
3094
|
+
CriteriaMinimumSchema,
|
|
3095
|
+
CriteriaOverviewSchema,
|
|
3096
|
+
CriteriaPlaylistDetailedSchema,
|
|
3097
|
+
CriteriaPlaylistMinimumSchema,
|
|
3098
|
+
CriteriaPlaylistSimpleSchema,
|
|
3099
|
+
CriteriaSimpleSchema,
|
|
3100
|
+
CriteriaUpdateSchema,
|
|
3101
|
+
ErrorCode,
|
|
3102
|
+
ErrorMessages,
|
|
3103
|
+
FORM_RATING_NULL_VALUE,
|
|
3104
|
+
GOOGLE_EXCHANGE_CONFIG,
|
|
3105
|
+
GenrePlaylistUuidSchema,
|
|
3106
|
+
GenreUuidSchema,
|
|
3107
|
+
InvalidInputError,
|
|
3108
|
+
MbArtistDetailedSchema,
|
|
3109
|
+
MbRecordingDetailedSchema,
|
|
3110
|
+
NO_VIDEO_LABEL,
|
|
3111
|
+
NetworkError,
|
|
3112
|
+
PaginatedResponseSchema,
|
|
3113
|
+
PlayStates,
|
|
3114
|
+
PlayerProvider,
|
|
3115
|
+
PlayerVideoSurface,
|
|
3116
|
+
PopupProvider,
|
|
3117
|
+
SPOTIFY_EXCHANGE_CONFIG,
|
|
3118
|
+
ServiceError,
|
|
3119
|
+
SessionProvider,
|
|
3120
|
+
SongDetailedSchema,
|
|
3121
|
+
TrackBaseSchema,
|
|
3122
|
+
TrackList,
|
|
3123
|
+
TrackListFromArtist,
|
|
3124
|
+
TrackListFromCriteriaPlaylist,
|
|
3125
|
+
TrackListFromTrack,
|
|
3126
|
+
TrackListOrigin,
|
|
3127
|
+
TrackListOriginFromArtist,
|
|
3128
|
+
TrackListOriginFromCriteriaPlaylist,
|
|
3129
|
+
TrackListOriginFromTrack,
|
|
3130
|
+
TrackListOriginType,
|
|
3131
|
+
TrackListProvider,
|
|
3132
|
+
TrackListSidebarVisibilityProvider,
|
|
3133
|
+
TrackMinimumSchema,
|
|
3134
|
+
TrackNounProvider,
|
|
3135
|
+
UuidResourceSchema,
|
|
3136
|
+
YOUTUBE_UNPLAYABLE_REASON_LABELS,
|
|
3137
|
+
YoutubeMediaController,
|
|
3138
|
+
artistEndpoints,
|
|
3139
|
+
artistQueryKeys,
|
|
3140
|
+
buildBackendBaseUrl,
|
|
3141
|
+
buildSubdomainBaseUrl,
|
|
3142
|
+
capitalize,
|
|
3143
|
+
capitalizeFirstLetter,
|
|
3144
|
+
clearSpotifyRequiredCached,
|
|
3145
|
+
clearStoredRedirectUrl,
|
|
3146
|
+
createAppErrorFromErrorCode,
|
|
3147
|
+
createAppErrorFromResult,
|
|
3148
|
+
createLogout,
|
|
3149
|
+
createNetworkOrBackendError,
|
|
3150
|
+
editGenreSongPages,
|
|
3151
|
+
exchangeCodeWithBackend,
|
|
3152
|
+
fetchWrapper,
|
|
3153
|
+
formatTime,
|
|
3154
|
+
genreEndpoints,
|
|
3155
|
+
genrePlaylistEndpoints,
|
|
3156
|
+
genrePlaylistQueryKeys,
|
|
3157
|
+
genreQueryKeys,
|
|
3158
|
+
genreUpdateMutationKey,
|
|
3159
|
+
getGenrePlaylistsGroupedByRoot,
|
|
3160
|
+
getReparentCandidates,
|
|
3161
|
+
getSpotifyAllowlistMailtoHref,
|
|
3162
|
+
getSpotifyAllowlistMessage,
|
|
3163
|
+
getSpotifyRequiredCached,
|
|
3164
|
+
hasMainstreamPopRoot,
|
|
3165
|
+
isSong,
|
|
3166
|
+
libraryEndpoints,
|
|
3167
|
+
libraryQueryKeys,
|
|
3168
|
+
makeTrackPlaylistRelPageSchema,
|
|
3169
|
+
makeTrackPlaylistRelSchema,
|
|
3170
|
+
musicBrainzRecordingUrl,
|
|
3171
|
+
parseWithLog,
|
|
3172
|
+
pruneGenrePlaylistsForArtist,
|
|
3173
|
+
queryClient,
|
|
3174
|
+
resolveRedirectUri,
|
|
3175
|
+
searchGenrePlaylistsByName,
|
|
3176
|
+
setSpotifyRequiredCached,
|
|
3177
|
+
songUnplayableReason,
|
|
3178
|
+
storeRedirectUrl,
|
|
3179
|
+
useArtist,
|
|
3180
|
+
useArtistGenreCounts,
|
|
3181
|
+
useArtistSearch,
|
|
3182
|
+
useAuthCallback,
|
|
3183
|
+
useConnectivityError,
|
|
3184
|
+
useConnectivityErrorPopup,
|
|
3185
|
+
useCreateGenre,
|
|
3186
|
+
useCurrentTime,
|
|
3187
|
+
useDeleteGenre,
|
|
3188
|
+
useFetchGenre,
|
|
3189
|
+
useFetchGenreDetail,
|
|
3190
|
+
useFetchGenreOverview,
|
|
3191
|
+
useFetchGenrePlaylist,
|
|
3192
|
+
useFetchWrapper,
|
|
3193
|
+
useGenreSearch,
|
|
3194
|
+
useGenreTreeViewState,
|
|
3195
|
+
useInvalidateAllGenrePlaylistQueries,
|
|
3196
|
+
useListFullGenrePlaylists,
|
|
3197
|
+
useListGenrePlaylists,
|
|
3198
|
+
useListGenres,
|
|
3199
|
+
useListTracks,
|
|
3200
|
+
useLogout,
|
|
3201
|
+
usePlayer,
|
|
3202
|
+
usePopup,
|
|
3203
|
+
usePrefetchGenreOverview,
|
|
3204
|
+
useQueryWithParse,
|
|
3205
|
+
useSession,
|
|
3206
|
+
useTrackList,
|
|
3207
|
+
useTrackListSidebarVisibility,
|
|
3208
|
+
useTrackNoun,
|
|
3209
|
+
useTrackUpload,
|
|
3210
|
+
useUpdateGenre,
|
|
3211
|
+
useValidatedMutation,
|
|
3212
|
+
useVisibleGenrePlaylists
|
|
3213
|
+
});
|
|
3214
|
+
//# sourceMappingURL=index.cjs.map
|