Reduce controller logic scope
This commit is contained in:
28
app/Helpers/Sentry.ts
Normal file
28
app/Helpers/Sentry.ts
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
export interface SentryPagination {
|
||||
previous: string;
|
||||
hasPreviousResults: boolean;
|
||||
hasNextResults: boolean;
|
||||
next: string
|
||||
}
|
||||
export function parseSentryLinkHeader(header: string): SentryPagination {
|
||||
const links = header.split(',').map(part => part.trim())
|
||||
|
||||
let result = {} as SentryPagination
|
||||
for (const link of links) {
|
||||
const match = link.match(/<([^>]+)>;\s*rel="([^"]+)";\s*results="([^"]+)";\s*cursor="([^"]+)"/)
|
||||
if (!match) continue
|
||||
|
||||
const [, url, rel, results] = match
|
||||
|
||||
if (rel === 'previous') {
|
||||
result.previous = url
|
||||
result.hasPreviousResults = results === 'true'
|
||||
} else if (rel === 'next') {
|
||||
result.next = url
|
||||
result.hasNextResults = results === 'true'
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
Reference in New Issue
Block a user