-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Use pagination when fetching Mastodon blocks (#125)
- Loading branch information
1 parent
9472649
commit e7cced8
Showing
2 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {Injectable} from '@angular/core'; | ||
|
||
interface Links { | ||
next?: string; | ||
prev?: string; | ||
} | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class MastodonLinkParserService { | ||
public getLinks(rawHeader: string): Links { | ||
const result: Links = {}; | ||
|
||
const links = rawHeader.split(", "); | ||
for (const link of links) { | ||
const parts = link.split("; "); | ||
const url = parts[0].substring(1, parts[0].length - 1); | ||
const relation: 'next' | 'prev' = <'next' | 'prev'>parts[1].substring('rel="'.length, parts[1].length - 1); | ||
|
||
result[relation] = url; | ||
} | ||
|
||
return result; | ||
} | ||
} |