Skip to content

Commit fd41e26

Browse files
committed
feat: function fs_channels
1 parent 8d94ec2 commit fd41e26

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

app/Http/Function.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,40 @@ function fs_route(string $url = null, string|bool $locale = null): string
127127
}
128128
}
129129

130+
// fs_channels
131+
if (! function_exists('fs_channels')) {
132+
function fs_channels()
133+
{
134+
$langTag = current_lang_tag();
135+
136+
$uid = 'guest';
137+
if (fs_user()->check()) {
138+
$uid = fs_user('detail.uid');
139+
}
140+
141+
$cacheKey = "fresns_web_channels_{$uid}_{$langTag}";
142+
$cacheTag = 'fresnsWeb';
143+
144+
// is known to be empty
145+
$isKnownEmpty = CacheHelper::isKnownEmpty($cacheKey);
146+
if ($isKnownEmpty) {
147+
return [];
148+
}
149+
150+
$channels = CacheHelper::get($cacheKey, $cacheTag);
151+
152+
if (empty($channels)) {
153+
$result = ApiHelper::make()->get('/api/v2/global/channels');
154+
155+
$channels = data_get($result, 'data');
156+
157+
CacheHelper::put($channels, $cacheKey, $cacheTag, 5, now()->addMinutes(5));
158+
}
159+
160+
return $channels ?? [];
161+
}
162+
}
163+
130164
// fs_account
131165
if (! function_exists('fs_account')) {
132166
/**

0 commit comments

Comments
 (0)