itube-specs 0.0.311 → 0.0.312

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.
@@ -0,0 +1,24 @@
1
+ export function useApiFetcherNoCache<T>(
2
+ key: string | null,
3
+ apiMethod: (...args: any[]) => Promise<T>,
4
+ ...apiArgs: any[]
5
+ ) {
6
+ return async function fetchData() {
7
+ const hasKey = key?.trim();
8
+ const state = hasKey ? useState<T | null>(key!, () => null) : null;
9
+
10
+ try {
11
+ const result = await apiMethod(...apiArgs);
12
+
13
+ if (state) state.value = result;
14
+
15
+ return result;
16
+ } catch (err) {
17
+ throw createError({
18
+ statusCode: 500,
19
+ statusMessage: `Error fetching ${key}`,
20
+ message: err instanceof Error ? err.message : 'An unknown error occurred',
21
+ });
22
+ }
23
+ };
24
+ }
@@ -10,33 +10,21 @@ export const useFetchPlaylistsGetVideosById = (
10
10
  const route = useRoute();
11
11
  const id = computed(() => String(route.params[ 'id' ]));
12
12
  const key = EAsyncData.GetPlaylistsVideo;
13
- const stateKey = useState(`data-${key}-${id.value}`);
14
-
15
- async function fetchData() {
16
- try {
17
- const result = await apiMethod(
18
- id.value,
19
- isListPage ? {
20
- page: Number(route.query[ 'page' ]) || 1,
21
- [ 'per-page' ]: PER_PAGE,
22
- } : {
23
- page: 1,
24
- }
25
- );
26
- stateKey.value = result;
27
- return result;
28
- } catch (err) {
29
- throw createError({
30
- statusCode: 500,
31
- statusMessage: `Error fetching ${key}`,
32
- message: err instanceof Error ? err.message : 'An unknown error occurred',
33
- });
34
- }
35
- }
13
+ const stateKey = computed(() => `data-${key}-${id.value}`);
36
14
 
37
15
  const { data, status, error } = useAsyncData<PaginatedResponse<IVideoCard>>(
38
16
  key,
39
- fetchData,
17
+ () => useApiFetcherNoCache<PaginatedResponse<IVideoCard>>(
18
+ stateKey.value,
19
+ apiMethod,
20
+ id.value,
21
+ isListPage ? {
22
+ page: Number(route.query[ 'page' ]) || 1,
23
+ [ 'per-page' ]: PER_PAGE,
24
+ } : {
25
+ page: 1,
26
+ },
27
+ )(),
40
28
  );
41
29
 
42
30
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "itube-specs",
3
3
  "type": "module",
4
- "version": "0.0.311",
4
+ "version": "0.0.312",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "./types/index.d.ts",
7
7
  "scripts": {