Skip to content

Commit 81a1325

Browse files
committed
Wrap remaining fetch in try catch
1 parent 8682b11 commit 81a1325

File tree

38 files changed

+889
-667
lines changed

38 files changed

+889
-667
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ platforms, and offers integration with various databases, now accessible with
2222
just a ENV Variable.
2323

2424
### 2025 Update
25-
The app has undergone a major refactor, bringing numerous improvements, including a fresh UI built with ShadCN and Svelte. The platform is now stable and mature enough to be considered a release candidate.
25+
The app has undergone a major refactor, bringing numerous improvements, including a fresh UI built with ShadCN and Svelte. The platform is now stable and mature enough to be considered a release candidate. This will need a new reinitiation of a plain database, so export your URL and be prepared to a new importer that should be able to guide you assign any kind of CSV to the platform.
2626

2727
## Features
2828

@@ -47,6 +47,7 @@ The app has undergone a major refactor, bringing numerous improvements, includin
4747

4848

4949
---
50+
## This is a major refactor, the database has been rewritten
5051
### Always backup before attempting any update
5152
---
5253

@@ -114,6 +115,7 @@ Some configuration moved from envs variable to settings page in-app, thou there
114115
are some ENV that could be set as default on first launch:
115116

116117
```
118+
APPNAME=Snapp # can be customized on startup before database initiation
117119
ADMIN_EMAIL=admin@example.org
118120
ADMIN_PASSWORD=password
119121
ADMIN_USERNAME=admin

src/lib/components/groups/manageGroup.svelte

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,24 @@
187187
const [u] = members.splice(idx, 1);
188188
if (u) users.push(u);
189189
const f = page.data.fetch as typeof fetch;
190-
191-
await (
192-
await f('/api/group/update', {
193-
body: JSON.stringify({
194-
data: {
195-
users: { disconnect: { id: u.id } }
196-
},
197-
where: { slug: groupId }
198-
}),
199-
credentials: 'include',
200-
method: 'PATCH'
201-
})
202-
).json();
203-
memberCount--;
204-
userCount = Math.max(0, userCount || 0 + 1);
190+
try {
191+
await (
192+
await f('/api/group/update', {
193+
body: JSON.stringify({
194+
data: {
195+
users: { disconnect: { id: u.id } }
196+
},
197+
where: { slug: groupId }
198+
}),
199+
credentials: 'include',
200+
method: 'PATCH'
201+
})
202+
).json();
203+
memberCount--;
204+
userCount = Math.max(0, userCount || 0 + 1);
205+
} catch (error) {
206+
console.error(error);
207+
}
205208
saved();
206209
}}
207210
>

src/lib/components/metrics/cityDistribution.svelte

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,29 @@
1212
1313
let data = $state<{ id: null | string; name: null | string; value: number }[]>([]);
1414
const loadData = async () => {
15-
const res = (await (
16-
await (page.data.fetch as typeof fetch)(
17-
`/api/usage/groupBy?q=${JSON.stringify({
18-
_count: { city: true },
19-
by: ['city'],
20-
orderBy: { _count: { city: 'desc' } },
21-
take: 10,
22-
where: {
23-
ownerId: page.data.user.role !== 'user' ? undefined : page.data.user.id,
24-
timestamp: {
25-
gte: mstore.start.toDate(getLocalTimeZone()).toISOString(),
26-
lte: mstore.end.toDate(getLocalTimeZone()).toISOString()
15+
try {
16+
const res = (await (
17+
await (page.data.fetch as typeof fetch)(
18+
`/api/usage/groupBy?q=${JSON.stringify({
19+
_count: { city: true },
20+
by: ['city'],
21+
orderBy: { _count: { city: 'desc' } },
22+
take: 10,
23+
where: {
24+
ownerId: page.data.user.role !== 'user' ? undefined : page.data.user.id,
25+
timestamp: {
26+
gte: mstore.start.toDate(getLocalTimeZone()).toISOString(),
27+
lte: mstore.end.toDate(getLocalTimeZone()).toISOString()
28+
}
2729
}
28-
}
29-
})}`
30-
)
31-
).json()) as { data: ({ _count: { city: number } } & Usage)[] };
32-
if (res && res?.data) {
33-
data = res.data.map((d) => ({ id: d.city, name: d.city, value: d._count.city }));
30+
})}`
31+
)
32+
).json()) as { data: ({ _count: { city: number } } & Usage)[] };
33+
if (res && res?.data) {
34+
data = res.data.map((d) => ({ id: d.city, name: d.city, value: d._count.city }));
35+
}
36+
} catch (error) {
37+
console.log(error);
3438
}
3539
};
3640

src/lib/components/metrics/countryDistribution.svelte

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,29 @@
1212
1313
let data = $state<{ id: null | string; name: null | string; value: number }[]>([]);
1414
const loadData = async () => {
15-
const res = (await (
16-
await (page.data.fetch as typeof fetch)(
17-
`/api/usage/groupBy?q=${JSON.stringify({
18-
_count: { country: true },
19-
by: ['country'],
20-
orderBy: { _count: { country: 'desc' } },
21-
take: 10,
22-
where: {
23-
ownerId: page.data.user.role !== 'user' ? undefined : page.data.user.id,
24-
timestamp: {
25-
gte: mstore.start.toDate(getLocalTimeZone()).toISOString(),
26-
lte: mstore.end.toDate(getLocalTimeZone()).toISOString()
15+
try {
16+
const res = (await (
17+
await (page.data.fetch as typeof fetch)(
18+
`/api/usage/groupBy?q=${JSON.stringify({
19+
_count: { country: true },
20+
by: ['country'],
21+
orderBy: { _count: { country: 'desc' } },
22+
take: 10,
23+
where: {
24+
ownerId: page.data.user.role !== 'user' ? undefined : page.data.user.id,
25+
timestamp: {
26+
gte: mstore.start.toDate(getLocalTimeZone()).toISOString(),
27+
lte: mstore.end.toDate(getLocalTimeZone()).toISOString()
28+
}
2729
}
28-
}
29-
})}`
30-
)
31-
).json()) as { data: ({ _count: { country: number } } & Usage)[] };
32-
if (res && res?.data) {
33-
data = res.data.map((d) => ({ id: d.country, name: d.country, value: d._count.country }));
30+
})}`
31+
)
32+
).json()) as { data: ({ _count: { country: number } } & Usage)[] };
33+
if (res && res?.data) {
34+
data = res.data.map((d) => ({ id: d.country, name: d.country, value: d._count.country }));
35+
}
36+
} catch (error) {
37+
console.log(error)
3438
}
3539
};
3640

src/lib/components/metrics/map.svelte

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,32 @@
1717
1818
const loadData = async () => {
1919
const alpha2 = (await import('iso-3166-1-alpha-2')).default;
20-
const res = (await (
21-
await (page.data.fetch as typeof fetch)(
22-
`/api/usage/groupBy?q=${JSON.stringify({
23-
_count: true,
24-
by: ['country'],
25-
where: {
26-
ownerId: page.data.user.role !== 'user' ? undefined : page.data.user.id,
27-
timestamp: {
28-
gte: mstore.start.toDate(getLocalTimeZone()).toISOString(),
29-
lte: mstore.end.toDate(getLocalTimeZone()).toISOString()
20+
try {
21+
const res = (await (
22+
await (page.data.fetch as typeof fetch)(
23+
`/api/usage/groupBy?q=${JSON.stringify({
24+
_count: true,
25+
by: ['country'],
26+
where: {
27+
ownerId: page.data.user.role !== 'user' ? undefined : page.data.user.id,
28+
timestamp: {
29+
gte: mstore.start.toDate(getLocalTimeZone()).toISOString(),
30+
lte: mstore.end.toDate(getLocalTimeZone()).toISOString()
31+
}
3032
}
31-
}
32-
})}`
33-
)
34-
).json()) as { data: ({ _count: number } & Usage)[] };
35-
if (res && res?.data)
36-
data = res.data.map((item) => ({
37-
id: item.country ? alpha2.getCode(item.country) : null,
38-
name: item.country,
39-
value: item._count
40-
}));
41-
await initMap();
33+
})}`
34+
)
35+
).json()) as { data: ({ _count: number } & Usage)[] };
36+
if (res && res?.data)
37+
data = res.data.map((item) => ({
38+
id: item.country ? alpha2.getCode(item.country) : null,
39+
name: item.country,
40+
value: item._count
41+
}));
42+
await initMap();
43+
} catch (error) {
44+
console.log(error);
45+
}
4246
};
4347
4448
const initMap = async () => {

src/lib/components/metrics/osDistribution.svelte

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,29 @@
1212
1313
let data = $state<{ id: null | string; name: null | string; value: number }[]>([]);
1414
const loadData = async () => {
15-
const res = (await (
16-
await (page.data.fetch as typeof fetch)(
17-
`/api/usage/groupBy?q=${JSON.stringify({
18-
_count: { os: true },
19-
by: ['os'],
20-
orderBy: { _count: { os: 'desc' } },
21-
take: 10,
22-
where: {
23-
ownerId: page.data.user.role !== 'user' ? undefined : page.data.user.id,
24-
timestamp: {
25-
gte: mstore.start.toDate(getLocalTimeZone()).toISOString(),
26-
lte: mstore.end.toDate(getLocalTimeZone()).toISOString()
15+
try {
16+
const res = (await (
17+
await (page.data.fetch as typeof fetch)(
18+
`/api/usage/groupBy?q=${JSON.stringify({
19+
_count: { os: true },
20+
by: ['os'],
21+
orderBy: { _count: { os: 'desc' } },
22+
take: 10,
23+
where: {
24+
ownerId: page.data.user.role !== 'user' ? undefined : page.data.user.id,
25+
timestamp: {
26+
gte: mstore.start.toDate(getLocalTimeZone()).toISOString(),
27+
lte: mstore.end.toDate(getLocalTimeZone()).toISOString()
28+
}
2729
}
28-
}
29-
})}`
30-
)
31-
).json()) as { data: ({ _count: { os: number } } & Usage)[] };
32-
if (res && res?.data) {
33-
data = res.data.map((d) => ({ id: d.os, name: d.os, value: d._count.os }));
30+
})}`
31+
)
32+
).json()) as { data: ({ _count: { os: number } } & Usage)[] };
33+
if (res && res?.data) {
34+
data = res.data.map((d) => ({ id: d.os, name: d.os, value: d._count.os }));
35+
}
36+
} catch (error) {
37+
console.log(error);
3438
}
3539
};
3640

src/lib/components/metrics/regionDistribution.svelte

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,29 @@
1212
1313
let data = $state<{ id: null | string; name: null | string; value: number }[]>([]);
1414
const loadData = async () => {
15-
const res = (await (
16-
await (page.data.fetch as typeof fetch)(
17-
`/api/usage/groupBy?q=${JSON.stringify({
18-
_count: { region: true },
19-
by: ['region'],
20-
orderBy: { _count: { region: 'desc' } },
21-
take: 10,
22-
where: {
23-
ownerId: page.data.user.role !== 'user' ? undefined : page.data.user.id,
24-
timestamp: {
25-
gte: mstore.start.toDate(getLocalTimeZone()).toISOString(),
26-
lte: mstore.end.toDate(getLocalTimeZone()).toISOString()
15+
try {
16+
const res = (await (
17+
await (page.data.fetch as typeof fetch)(
18+
`/api/usage/groupBy?q=${JSON.stringify({
19+
_count: { region: true },
20+
by: ['region'],
21+
orderBy: { _count: { region: 'desc' } },
22+
take: 10,
23+
where: {
24+
ownerId: page.data.user.role !== 'user' ? undefined : page.data.user.id,
25+
timestamp: {
26+
gte: mstore.start.toDate(getLocalTimeZone()).toISOString(),
27+
lte: mstore.end.toDate(getLocalTimeZone()).toISOString()
28+
}
2729
}
28-
}
29-
})}`
30-
)
31-
).json()) as { data: ({ _count: { region: number } } & Usage)[] };
32-
if (res && res?.data) {
33-
data = res.data.map((d) => ({ id: d.region, name: d.region, value: d._count.region }));
30+
})}`
31+
)
32+
).json()) as { data: ({ _count: { region: number } } & Usage)[] };
33+
if (res && res?.data) {
34+
data = res.data.map((d) => ({ id: d.region, name: d.region, value: d._count.region }));
35+
}
36+
} catch (error) {
37+
console.log(error);
3438
}
3539
};
3640

src/lib/components/metrics/topSnapps.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
[]
1515
);
1616
const loadData = async () => {
17+
try {
18+
1719
const res = (await (
1820
await (page.data.fetch as typeof fetch)(
1921
`/api/usage/groupBy?q=${JSON.stringify({
@@ -66,6 +68,10 @@
6668
);
6769
data = _data.filter((d) => d !== undefined);
6870
}
71+
72+
} catch (error) {
73+
console.log(error)
74+
}
6975
};
7076
7177
const i18n = getTranslations();
Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
12
export { default as AdminPanel } from './component.svelte';
23

34
export const checkVTApiKey = async (f: typeof fetch, key?: null | string) => {
4-
if (!key) return;
5+
if (!key||key?.trim()==='') return false;
56
const weekAgo = new Date();
67
weekAgo.setDate(weekAgo.getDate() - 7);
78

@@ -20,15 +21,22 @@ export const checkVTApiKey = async (f: typeof fetch, key?: null | string) => {
2021
};
2122
const res = await (await f(_url, { ..._options })).json();
2223
if (!res?.data?.links) return false;
23-
const analysis = await (
24-
await f(res.data.links.self, {
25-
headers: {
26-
'x-apikey': key
27-
}
28-
})
29-
).json();
3024

31-
if (typeof analysis === 'object') {
32-
return true;
33-
} else return false;
25+
try {
26+
27+
const analysis = await (
28+
await f(res.data.links.self, {
29+
headers: {
30+
'x-apikey': key
31+
}
32+
})
33+
).json();
34+
35+
if (typeof analysis === 'object') {
36+
return true;
37+
} else return false;
38+
} catch (error) {
39+
console.error(error)
40+
}
41+
return false
3442
};

src/lib/components/settings/adminPanel/vtapi.svelte

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
const { enhance: superEnhance, form: formData } = form;
2626
const i18n = getTranslations();
2727
28-
$effect(() => {
29-
untrack(() => {
30-
checkStatus();
31-
});
32-
});
28+
$effect(() => {untrack(() => checkStatus())});
3329
3430
let status = $state(false);
3531
const checkStatus = async () => {
36-
const res = await (await (page.data.fetch as typeof fetch)('/admin/check-vt-api')).json();
37-
if (res && res.status) status = true;
32+
try {
33+
const res = await (await (page.data.fetch as typeof fetch)('/admin/check-vt-api')).json();
34+
if (res && res.status) status = res.status;
35+
} catch (error) {
36+
console.error(error)
37+
}
3838
};
3939
</script>
4040

0 commit comments

Comments
 (0)