feat: trending hashtags

This commit is contained in:
2023-11-16 14:01:12 +00:00
parent ee0865d9af
commit 95b7cca4cb
5 changed files with 88 additions and 26 deletions

View File

@ -18,6 +18,10 @@ export interface TrendingNoteResponse {
notes: Array<TrendingNote>;
}
export interface TrendingHashtagsResponse {
hashtags: Array<string>
}
export interface SuggestedFollow {
pubkey: string;
}
@ -39,14 +43,13 @@ export class NostrBandError extends Error {
export default class NostrBandApi {
readonly #url = "https://api.nostr.band";
readonly #supportedLangs = ["en", "de", "ja", "zh", "th", "pt", "es", "fr"];
async trendingProfiles() {
return await this.#json<TrendingUserResponse>("GET", "/v0/trending/profiles");
}
async trendingNotes(lang?: string) {
const supportedLangs = ["en", "de", "ja", "zh", "th", "pt", "es", "fr"];
if (lang && supportedLangs.includes(lang)) {
if (lang && this.#supportedLangs.includes(lang)) {
return await this.#json<TrendingNoteResponse>("GET", `/v0/trending/notes?lang=${lang}`);
}
return await this.#json<TrendingNoteResponse>("GET", "/v0/trending/notes");
@ -56,6 +59,13 @@ export default class NostrBandApi {
return await this.#json<SuggestedFollowsResponse>("GET", `/v0/suggested/profiles/${pubkey}`);
}
async trendingHashtags(lang?: string) {
if (lang && this.#supportedLangs.includes(lang)) {
return await this.#json<TrendingHashtagsResponse>("GET", `/v0/trending/hashtags?lang=${lang}`);
}
return await this.#json<TrendingHashtagsResponse>("GET", "/v0/trending/hashtags");
}
async #json<T>(method: string, path: string) {
throwIfOffline();
const res = await fetch(`${this.#url}${path}`, {